I have a query where the input value is as: "Amar, Akbar, Anthony"
I want the query to treat input value as: 'Amar', 'Akbar', 'Anthony'. I have a regexp_substr which works in normal query and serves the purpose but when I put it with Case, it gives below error.
Single row query returns more than one row
The CASE is written so that if user doesn't enter anything in textbox, then query should return all rows, if user inputs something, result should show the matching values.
Select * from test_tbl a where
(
CASE
WHEN TRIM (:username) IS NULL
THEN NVL (a.user_name, 'NOTHING')
WHEN TRIM (UPPER (:username)) = 'NOTHING'
THEN NVL (a.user_name, :username)
ELSE UPPER (a.user_name)
END) LIKE (
CASE
WHEN TRIM (:username) IS NULL
THEN NVL (a.user_name, 'NOTHING')
WHEN TRIM (UPPER (:username)) = 'NOTHING'
THEN :username
ELSE ((select regexp_substr(:username,'[^,]+', 1, level) from dual connect by regexp_substr(:username, '[^,]+', 1, level) is not null))
END)
Is there a way to achieve required functionality? That is not change query much and include CASE with the regexp_substr.