0

Is it possible to define an inline array to use with the IN operator in Oracle SQL 12c? Pseudo code:

SELECT *
FROM T_AUDIO_PLAYERS
WHERE NAME IN {'foo', 'bar'};

Background: I have a Java tool, that's reading in valid .SQL files and replaces SQL-Variables like :NAME before execution.

6
  • 2
    Could you please elaborate what you mean by user defined array? You mean dynamic IN list? Also, {} is invalid syntax, you need to use (). Commented Nov 23, 2015 at 8:37
  • I just meant inline, without the need to declare the array elsewhere. Commented Nov 23, 2015 at 8:45
  • You can't declare the IN list to use it dynamically in SQL. You need to simply provide the static values at run time, WHERE NAME IN ('foo', 'bar'). Commented Nov 23, 2015 at 8:49
  • Oracle has no array data type for SQL (it has arrays in PL/SQL, but that is something different) Commented Nov 23, 2015 at 9:28
  • Were you required to get dynamic values for IN clause? Commented Nov 24, 2015 at 14:48

2 Answers 2

2

I am not sure if I understand your question correctly. However, if you change your {-brackets to (-brackets, this should already work:

SELECT *
FROM T_AUDIO_PLAYERS
WHERE NAME IN ('foo', 'bar');
Sign up to request clarification or add additional context in comments.

Comments

0

You can use LISTAGG function like

SELECT *
FROM T_AUDIO_PLAYERS
WHERE NAME IN (select LISTAGG() ...);

More detail here

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.