python oracle excute error(ORA-01036: illegal variable name/number)

135 Views Asked by At

hi i am korean so not native english speaker

anyway i have question

when i learning sql and python flask connect

this is my code

  sql='''select count(*) from member where id = :1 '''
    result=curs.execute(sql,(join_id))
    cnt=result.fetchone()

this code print (ORA-01036: illegal variable name/number) error message

ok i solved error

 sql='''select count(*) from member where id = :1 '''
    result=curs.execute(sql,(join_id,)
    cnt=result.fetchone()

like this( join_id (add),)

that is my question

why different result (,) or not

i think it just one binding variable so why need (,)??

1

There are 1 best solutions below

0
AKX On

Because the binding variables always need to be in a tuple, even if it's a 1-tuple. (This stands for all Python SQL libraries that adhere to the DB-API spec.)

Since in Python (foo) is just a parenthesized foo, to build an 1-tuple, you'll need the trailing comma (see e.g. How to create a tuple with only one element).