Calling PL/SQL functions with boolean output in cx_Oracle

PL/SQL functions with boolean output can't be called through the cursor.callfunc() method in cx_Oracle library. To overcome that, one needs to make use of a PL/SQL block.

Here the PL/SQL function that returns a boolean has the following function prototype.

FUNCTION is_correct RETURN BOOLEAN

The python script using cx_Oracle

sel = """
begin
  if (is_correct())
  then dbms_output.put_line('Yes');
  else dbms_output.put_line('No');
  end if;
end;

cursor.callproc("dbms_output.enable")
cursor.execute(sel)
statusVar = cursor.var(cx_Oracle.NUMBER)
lineVar = cursor.var(cx_Oracle.STRING)
cursor.callproc("dbms_output.get_line", (lineVar, statusVar))
if statusVar.getvalue() == 0:
  sr = lineVar.getvalue()
  print sr

Reference

Comments

Popular posts from this blog

Using PlayStation 1 Densha de Go controller on emulators

Using PS1/PC Densha de Go! controller SLPH-00051/TCPP-20001/DGOC-44U on PS4/Switch Densha de Go!!

Play octoshape stream on windows with VLC player