Skip to content
Advertisement

Pass subquery value to IN statement

In one table named prefs, I have a column named “Value” of type clob that holds this value: ‘T’, ‘L’

Screenshot showing prefs record which holds lookup values

I need to query table attendance_code to retrieve the records where column att_code values are either T or L. The att_code column is of type varchar2.

As a manual model query, this works fine:

Attempt 1

Attempt 2

This yields no error, but returns no rows.

Attempt 3 (Based on https://blogs.oracle.com/aramamoo/how-to-split-comma-separated-string-and-pass-to-in-clause-of-select-statement)

Attempt 4

I have also tried changing the value in the prefs table to just T,L (removing the single quotes) and running all of the above against that, to no avail.

What is the proper way to do this, please?

Advertisement

Answer

You can use hierarchical query with removed single quotes as follows:

or simplify the above query with the CTE as following:

Example with Dual as following:

Cheers!!

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement