I have a table with something like a dozen different columns. Is there a way to conditionally select columns based on a certain condition?
For example we’ll say this a user table with username, password, all that stuff, and a field that holds a count of how many times that user has failed a login. (Wrong password, right username). So instead of having a query that returns nothing when either username or password are wrong, or a query that returns everything when just the username is correct, I would like a query that returns a subset when the username is correct but the password is wrong.
Pseudo SQL:
SELECT column1,
column2,
column3,
column4,
column5,
column6,
--If this condition is not met the following columns are not selected
IF password = password
(
conditional_column1,
conditional_column2,
conditional_column3
)
FROM source_table
WHERE username = username
I have tried a CASE statement and DECODE but each of those only returns one value for each condition. I want to select several columns for a single condition.
I do not have access to PL/SQL and I am trying to keep this all in one query. Anyone know if this is possible?
EDIT:
Just to clarify, in my case I do not want to check if I’m asking for username, I want to check if there are any rows where username = x. If all I had to do was pass username to a function and build a query string this wouldn’t be a problem.
So the flow goes:
Get some columns where username is ‘x’ then, if password is ‘y’ get these other columns.
It sounds like you want to have a look at the virtual private database (VPD) feature of oracle