let’s say I have a database table “ACCOUNTS” where it only has 3 fields:
- ACCOUNT_NUMBER (BIGINT)
- CREDIT (BIGINT)
- DEBIT (BIGINT)
And I simply want to make a query that will show only two columns:
- ACCOUNT_NUMBER (BIGINT)
- “BALANCED” (A boolean value. True if Credit == Debit, false otherwise)
How do I make such a query?
I tried using the equal operator (=) but it doesn’t accept it
x
SELECT
ACCOUNT_NUMBER,
CREDIT = DEBIT as "BALANCED"
FROM ACCOUNTS;
Advertisement
Answer
There’s no Boolean datatype in Oracle’s SQL, so you’ll have to live with its string (or numeric) representation, such as
select account_number,
case when credit = debit then 'true'
else 'false'
end as balanced
from accounts