krishna bharat
krishna bharat

Reputation: 43

ORA-01036: illegal variable name/number (cx_Oracle)

When I am trying to insert data into DB and i can see the above error when i am using below code.

Could you please suggest what else can be done.

Code:

list_to_add=['Have you searched','similar question has already been posted']

dsn_tns = cx.makedsn(cred_test['HOST'], cred_test['PORT'], service_name=cred_test['SERVICE_NAME'])

conn = cx.connect(user=cred_test['USER'], password=cred_test['PASWRD'], dsn=dsn_tns)

cursor = conn.cursor()

cursor.prepare('INSERT INTO Table_name Col_name values (:0)')

cursor.executemany(None,list_to_add)

conn.commit()

Upvotes: 2

Views: 6131

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65408

You have minor issues :

  1. ORA-01036 raises due to list elements are not wrapped up with square brackets

  2. ORA-00947 will raise after fixing the first matter, since the Col_name is not wrapped up with parentheses within the Insert statement

    list_to_add=[['Have you searched'],['similar question has already been posted']]
    
    dsn_tns = cx.makedsn(cred_test['HOST'], cred_test['PORT'], service_name=cred_test['SERVICE_NAME'])
    
    conn = cx.connect(user=cred_test['USER'], password=cred_test['PASWRD'], dsn=dsn_tns)
    
    cursor = conn.cursor()
    
    cursor.prepare('INSERT INTO Table_name(Col_name) VALUES(:0)')
    
    cursor.executemany(None,list_to_add)
    
    conn.commit()
    

Upvotes: 3

Related Questions