Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to create a Boolean data type in ORACLE?

Posted on 2003-03-07
6
Medium Priority
?
9,540 Views
Last Modified: 2008-01-09
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.
                             
0
Comment
Question by:nages_21
5 Comments
 

Author Comment

by:nages_21
ID: 8087389
I am using oracle version 8.1.

bye

Nagesh.
0
 
LVL 15

Accepted Solution

by:
andrewst earned 100 total points
ID: 8087491
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
 

Assisted Solution

by:sonusao
sonusao earned 100 total points
ID: 8087497
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
 

Expert Comment

by:Ix
ID: 8087722
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
 
LVL 3

Expert Comment

by:patelgokul
ID: 9940309
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question