Oracle - Can A Bind Variable Be Put In In() Clause If The Variable Can Be Empty

风流意气都作罢 提交于 2019-12-02 10:21:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!