简体   繁体   中英

How do I call an Oracle API function in Python 3.4 using cx_Oracle?

New to both Oracle and Python. I have an API in an Oracle database that has a function Part_Exist, which checks if a part exists and returns 1 for true, 0 for false:

FUNCTION Part_Exist (
   contract_        IN  VARCHAR2,
   part_no_         IN  VARCHAR2 ) RETURN NUMBER
IS
BEGIN
   IF Check_Exist___(contract_, part_no_) THEN
      RETURN 1;
   ELSE
      RETURN 0;
   END IF;
END Part_Exist;

I then try to execute this function in Python using a cx_Oracle connection cursor:

cursor.execute('INVENTORY_PART_API.PART_EXIST', ['100', '05945'])

I had tried cursor.callproc earlier, but since this is a function rather than a procedure, I thought cursor.execute would be correct.

I keep getting this traceback:

cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number

I've tried formatting the inputs every which way with no luck. I used cursor.callproc earlier with good results. Input appreciated!

Found the answer here: http://dbaportal.eu/sidekicks/sidekick-cx_oracle-code-paterns/

Basically I had to use cursor.callfunc rather than .execute or .callproc ...

        return_no = cursor.var(cx_Oracle.NUMBER)
        cursor.callfunc('INVENTORY_PART_API.Part_Exist', return_no, ['100', '05945'])
        number = return_no.getvalue()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM