2

I tried to:

select 1>2 from dual; 

but got:

ORA-00923: FROM keyword not found where expected 

Is there boolean type for column expression in Oracle SQL?

I able to do:

select case when 1>2 then 'T' else 'F' end from dual; 

Originally I tried to compare date fields and the quickest way I found was getting difference and look to sign...

UPDATE I tried SIGN function, I don't know if it is vendor specific extension:

select SIGN(1-2) from dual; select SIGN(DATE '2017-01-02' - DATE '2017-02-12') from dual; 

but this trick doesn't work for strings...

4
  • 1
    No, there is not a boolean type. You can use a char() or small integer. Commented Dec 26, 2017 at 15:13
  • 1
    char(1) with 1 and 0 would be your best bet. Commented Dec 26, 2017 at 15:15
  • I am looking for a way to express result of comparing of two values. I am not interested in creating column with "boolean" type. Commented Dec 26, 2017 at 15:15
  • 1
    sign returns -1, 0 or 1 (or null) according to the sign of the operand. You could use case to test string values. Column datatypes are listed here. Avoid char at all costs. Commented Dec 26, 2017 at 16:47

2 Answers 2

4

No there is not, you can use 0 and 1 just as yes/no.

Sign up to request clarification or add additional context in comments.

Comments

4

If you need to get the result 1 if something is true and 0 if it is false, you can use a case expression:

select case when (any_logical_condition_here) then 1 else 0 end as my_col from .... where .... 

For example:

select case when 1 > 2 then 1 else 0 end as bool_result from dual; BOOL_RESULT --------------------------------------- 0 

NOTE though - "Boolean" refers strictly to the TRUE/FALSE logic, it has no place for UNKNOWN. When you deal with null, as you must in SQL, you need three-valued logic. The case expression as written above returns 1 when the logical condition is true and 0 otherwise. Try it with 1 > null - the truth value is UNKNOWN, the case expression will return 0.

1 Comment

As is well-established in lore, Boolean is indeed trivalent: True, False, FileNotFound (link)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.