Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

cx-oracle sql insert query raise error when : (semicolon) insert into query

AQHDec 29 2020 — edited Dec 29 2020
dsn_tns = cx_Oracle.makedsn('myip', '1521', service_name='myservicename')
connection = cx_Oracle.connect(user='username', password='passwd', dsn=dsn_tns) 
cursor = connection.cursor()
cursor.execute("INSERT INTO  tablename VALUES (7.4)")
    #above works ok
cursor.execute("INSERT INTO  tablename VALUES (7:4)")
    #above works with '7:4'
myvar='7:4'
cursor.execute('INSERT INTO  tablename(col1) VALUES ({myvar})')
    #cx_Oracle.DatabaseError: ORA-00936: missing expression
connection.commit()
connection.close()

My requirement to is to insert : to be insert in this tablename, column type of this tablename is varchar2. ( when i insert '0001' it also remove leading zeros and only insert '1' in tabename), above code connect oracle database table and create cursor to execute sql insert query. in insert query with values 7.4 if successfully update the table but in second insert it raise error with ORA-00917. i am using oracle version 11g and python 3.7.

This post has been answered by AQH on Dec 30 2020
Jump to Answer
Comments
Post Details
Added on Dec 29 2020
1 comment
728 views