Forum Stats

  • 3,757,191 Users
  • 2,251,209 Discussions
  • 7,869,756 Comments

Discussions

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

AQH
AQH Member Posts: 297 Blue Ribbon
edited Dec 29, 2020 12:08PM in Python
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.

Tagged:

Best Answer

Answers