Binding single variable and list of variables in the same statement #103
-
Hi, Is there a way to bind a single variable and also a list of variables to the same statement? desired sql statements: I tried the following: This returns ORA-01484: arrays can only be bound to PL/SQL statements BR, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Yes, you cannot bind an array with cursor.execute(query, ids) But better yet would be to do this: bind_names = ",".join(":" + str(i + 2) for i in range(len(ids)))
bind_values = [element] + ids
query= f"select * from table where element = :1 and id in ({bind_names})"
cursor.execute(query, bind_values) That way you are using bind variables for everything. |
Beta Was this translation helpful? Give feedback.
-
Also see the documentation Binding Multiple Values to a SQL WHERE IN Clause. |
Beta Was this translation helpful? Give feedback.
Yes, you cannot bind an array with
cursor.execute()
. You could simply do this:But better yet would be to do this:
That way you are using bind variables for everything.