How to create a Boolean data type in ORACLE?

HI all,

     Can u pls tell me HOw to create a BOOLEAN data type in ORACLE. Actually I am changing my database from Access to oracle. so I need to change this. I tried in oracle with following syntax:

                   CREATE TABLE EMPLOYEE(
                           EMP_NO    NUMBER,
                           EMP_NAME  VARCHAR(20),
                           SEX       BOOLEAN
                           SALARY    NUMBER(6,2));

  the error was            ERROR at line 1:
                           ORA-00902: invalid datatype
Please help and if u have any other solution let me know immediatly.

bye,
Nagesh.
                             
nages_21Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nages_21Author Commented:
I am using oracle version 8.1.

bye

Nagesh.
0
andrewstCommented:
Unfortunatley, Oracle doesn't support a BOOLEAN datatype for columns - I think it is a shame.  You have 2 choices:

1) col NUMBER(1,0) CHECK (col IN (1,0))

2) col VARCHAR2(1) CHECK (col IN ('T','F'))

(or 'Y','N' or whatever you like really)

Mind you, I wouldn't want to use a BOOLEAN value for a column called SEX (unless it means "does he/she like sex?" or something!)  What does SEX=TRUE mean - male or female?

For this, I would use:

sex VARCHAR2(1) CHECK (sex IN ('M','F'))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sonusaoCommented:
No Boolean data type present in Oracle.

You can user CHAR or NUMBER datatype for your requirement. Create filed with datatype CHAR(1), or a NUMBER(1) and allow values such as Y/N, or 0/1 respectively. You can use constraint also on the field so that you can have only the allowed values.

Sandy
0
IxCommented:
Dear all

Boolean type exists in Oracle, but not for DDL!
Your can use Boolean in PL/SQL procedures.

If you need to use booleans in table, just use:
NUMBER(1,0) CHECK (col IN (1,0))
like andrewst mentionned before.

For status, types and so on... (like sex: there are 2 main states: M and F (in this case, cannot be NULL)),use a varchar2(<length>) with CHECK option and the list of values.

Avoid using NULL value in such fields (status, types...), it is better to use default values like 'UNKNOWN' or '?'... Avoid full table scans and lack of performance when querying on NULL values ;oD

Regards,
Ix.
0
patelgokulCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: andrewst {http:#8087491} & sonusao {http:#8087497}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

patelgokul
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.