?
Solved

How to create a Boolean data type in ORACLE?

Posted on 2003-03-07
6
Medium Priority
?
9,267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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

800 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