问题
In Oracle
, can a bind variable be put in IN()
clause if it can be empty? Asking because in the SQL if Oracle see IN()
without any data in it, it shows error
ORA-00936: missing expression.
Edit: Failed to mention that no PL/SQL can be used...
Edit2: Also failed to mention that the variable is either in format 1,2,3 or empty string. The empty string cannot be replaced with NULL.
回答1:
Seems to be working:
declare
l_statement varchar2(32767);
begin
l_statement := 'select * from user_tables where table_name in (:a)';
execute immediate l_statement
using '';
end;
回答2:
You can do it, it will be syntactically correct. I hope you are aware that NULL is not equal to anything even to NULL (so NULL=NULL is not TRUE but NULL), it can cause unexpected results in your query, so consider using NVL function if it doesn't affect performance
来源:https://stackoverflow.com/questions/18764564/oracle-can-a-bind-variable-be-put-in-in-clause-if-the-variable-can-be-empty