Reputation: 24620
I am trying to select results from a table and the visible
column should be a boolean ('true' or 'false' strings). Here is the SQL:
SELECT fldid AS "id",
TRIM(fldlabel) AS "name",
DECODE((select 'T' from dual where fldid in (53,54,7)), 'T', 'true', 'false') AS "visible"
FROM fieldTable
WHERE fldActive = 1
The set of fldid
s that should be visible will be an input parameter, but for the sake of this query they are hard-coded.
Without using DECODE I would get nulls for the records that are not in the set. Is DECODE the best solution for Oracle or is there a better way?
Upvotes: 0
Views: 65
Reputation: 1269953
You can use decode
in Oracle. The SQL standard is the case
statement, and you do not need the subquery:
SELECT fldid AS "id",
TRIM(fldlabel) AS "name",
(case when fldid in (53, 54, 7) then 'true' else 'false' end) as visible
FROM fieldTable
WHERE fldActive = 1;
Upvotes: 3