0

python for oracle

i am making a normal inventory management system just for practicing. so i have created a table in oracle 11g xe through python for dbms and i have created it successfully and i have also inserted some records in it but when i am trying to find the record from the table i am getting an error every time. here is my python code syntax. import cx_Oracle conn=cx_Oracle.connect("sanjay/sanjay@localhost") cur=conn.cursor() id=int(input("enter the product id")) cur.execute("select * from inventory where pid=:id",(id)) re=cur.fetchall() for i in re: print(i) and here is the error which i am getting again and again Traceback (most recent call last): File "C:\Users\root\Desktop\demodb.py", line 5, in <module> cur.execute("select * from inventory where pid=:id",(id)) TypeError: expecting a dictionary, sequence or keyword args

5th Jan 2020, 6:32 AM
Sanjay Tiwari
Sanjay Tiwari - avatar
1 Odpowiedź
+ 1
Based on the documentation https://cx-oracle.readthedocs.io/en/latest/user_guide/sql_execution.html You are just using wrong syntax in the sql query. Anyway I would recommend to change your variable name "id" because it is a built in python function name. product_id = int(input("enter the product id")) cur.execute("SELECT * FROM inventory WHERE pid=:pid", pid=product_id)
22nd Jan 2020, 3:43 AM
Tibor Santa
Tibor Santa - avatar