user3749378 user3749378 - 1 year ago 58
SQL Question

How to get a calculated field in SELECT comparing with SYSDATE

How can I build this select in Oracle:

SELECT DATETYPE_FIELD, DATETYPE_FIELD < SYSDATE AS IS_ON_DATE FROM MYTABLE


DATETYPE_FIELD
is a
DATE
field.
I want to get something like
TRUE/FALSE
in calculated
IS_ON_DATE
field.
USING that select still get an error in ORACLE.

How can this be done?

Answer Source

There is no boolean type in Oracle. You can use 1 or 0 to denote true or false like this:

SELECT DATETYPE_FIELD,
 case when DATETYPE_FIELD < SYSDATE then 1 else 0 end AS IS_ON_DATE
FROM MYTABLE

or string "true" and "false"

SELECT DATETYPE_FIELD,
 case when DATETYPE_FIELD < SYSDATE then 'true' else 'false' end AS IS_ON_DATE
FROM MYTABLE
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download