0

I'm getting an error when inserting None values into oracle in the following way:

    host = ('value1', 'value2', None, None)
    sql_insert = "INSERT INTO sm9_data_hostname (field1, field2, field3, field4) VALUES ( :1, :2, :3, :4)"
    conn_link.execute(sql_insert, host)
    connection.commit()

The error is: cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number

The insert works if I use 'Null' instead of None. I can't see what's wrong with this query as the parameters should replace the none with a Null. Or is this the wrong assumption?

Thanks, Isaac

4
  • 1
    Have you attempted using named placeholders? e.g. :field1, and passing as a dictionary? Commented Oct 12, 2015 at 11:53
  • I haven't, but will try now and see if that works, thanks Commented Oct 12, 2015 at 11:56
  • That seems to have done the trick, thanks! Commented Oct 13, 2015 at 10:41
  • I've posted it up as an answer for prosperity then! Commented Oct 13, 2015 at 22:53

1 Answer 1

2

I have no experience at all with cx_Oracle but I would suggest you try using named placeholders as an alternative. Such as the following

conn_link.execute(
    "INSERT INTO sm9_data_hostname (field1, field2, field3, field4) "
    "VALUES (:field1, :field2, :field3, :field4)",
    dict(field1="value1", field2="value2", field3=None, field4=None)
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.