1

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.

6
  • 1
    Wouldn't it see IN(null)? Commented Sep 12, 2013 at 12:57
  • I don't think it's possible. Thanks anyway. Commented Sep 13, 2013 at 6:56
  • var can only be 1,2,3 for example or nothing (not null) select * from table where code in (nvl(,null)) would result in error Commented Sep 13, 2013 at 6:57
  • Define 'nothing' - why isn't that null? Empty string ('') and null are the same thing in Oracle. If you have a bind varible in the query then it won't disappear. Maybe you should show your code so we can see what you really mean, and any errors you've got so far. Commented Sep 13, 2013 at 7:07
  • There's a PHP code which replaces the variable with either 1,2,3 or empty string which is not surrounded by quotes (neither null, nor empty string surrounded by quotes ''). This makes it impossible I guess. Thanks for the efforts anyway and sorry for not explaining it good enough. Commented Sep 13, 2013 at 7:34

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

2 Comments

That's not an empty list, it's a list containing an empty string.
Empty string and null are the same thing in Oracle
1

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

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.