Posts

Showing posts with the label PL/SQL

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