A few reasons why...
November 3, 2002 - 2pm Central time zone
Reviewer: Jeremy Smith from Salt Lake City, UT
Clarity: if the value I'm trying to store really is a boolean, then when I'm glancing at my model,
it's clear that that's what the column is. Sure, if it's a char(1) that's a good indication, but
not a sure-fire one.
Compatibility: I know you're suspicious of products developed for multiple platforms, but there
are a lot of them out there. It would be nice to not have to make that conversion every time.
Consistency: Y/N values with a check constraint are one way to represent a boolean. When I needed
my first one, I used T and F. Another person I know used 0 and 1. Someone who spoke another
language might choose two different characters.
PL/SQL compatibility: It would be nice to be able to declare booleans using "var_name%TYPE".
and just to clarify on performance issues:
Speed: doesn't that check constraint take a tiny amount more time than validating against
conformance to a particular datatypes?
Space: if I'm using a fixed width multi-byte character set, doesn't a char(1) boolean take up more
space than a universal boolean would?
Sorry if this sounds whiney, but it's something I find myself explaining to nearly every new Oracle
developer, and I've never heard a really good reason for why not. Best I've been able to come up
with is "Because they don't _need_ it, and because they don't feel like having it." You have to
admit, that's a pretty rare answer to give w/r/t an Oracle feature.
Followup November 3, 2002 - 9pm Central time zone:
For clarity -- i would hope the name (which could even incorporate "boolean") or the check
constraint would tell you that.
For compatibility -- you better stick with SQL89 datatypes (basically strings and numbers) -- not
really appealing when you get down to it.
Consistency -- well, the same thing could be said about zip codes, addresses, storing names, (and
the list goes on). Sounds like an implementation detail
Speed -- no, there wouldn't be.
space -- use a number with 1 and 0 then. Or using utf-8 or any variable length encoding scheme....
It just isn't a type we have -- I can say no more and no less. ANSI doesn't have it -- many
databases don't have it (we are certainly not alone). In the grand scheme of things -- I would say
the priotization of this is pretty "low" (thats my opinion there)
PL/SQL functions
November 4, 2002 - 4am Central time zone
Reviewer: JBrain from England
Point taken, but I find the following annoying...
(a) Someone (or even me) writes a PL/SQL function returning a BOOLEAN.
(b) I later find a use for it in a SQL WHERE clause.
True I might be able to code the condition in SQL, but if I want to try to maintain some semblance
of code reuse I either have to provide a Y/N function wrapper or go back to the author...
Would be nice just to be able to slip the original function into the WHERE clause and forget about
it.
Are there people out there who have coding standards banning functions which return a BOOLEAN...?
Followup November 4, 2002 - 8am Central time zone:
Are there people out there banning functions such as those returning a boolean -- I can almost
assure you there are. I've seen EVERY construct "banned" out of FUD at one point or another.
Boolean
November 4, 2002 - 8am Central time zone
Reviewer: Tony Andrews from UK
Since ANSI don't specify a BOOLEAN datatype, I guess our issue is with ANSI rather than Oracle.
But I don't buy the argument that BOOLEANs are redundant because you can use CHAR(1) with 'Y' or
'N' (what I'd call a "work around"). In that case, why have a PL/SQL BOOLEAN type either? BOOLEAN
is a fundamental and natural datatype, and most databases I have known would use it liberally if it
existed.
What is the Boolean mapping in Java.
February 5, 2003 - 7am Central time zone
Reviewer: Chandra S.Reddy from Hyderabad India
Hi Tom,
I have a question regarding boolean datatype.
Below is the SP, written by our client and we need to integrate this with our application.
PROCEDURE sp_xxxx_map (
ic_opt_number IN VARCHAR2,
in_cast_number IN NUMBER,
in_tyre_amount IN NUMBER,
ob_is_valid OUT BOOLEAN,
ob_is_obgr_obgt_valid OUT BOOLEAN,
--------------- few more parameters....
While integrating the above, everything id fine except boolean OUT parameter.
I think(correct me if am wrong) there is no SQL datatype in java(JDBC classes) to catch the
"ob_is_valid", "ob_is_obgr_obgt_valid" parameters.
How do can go about this issue.
One idea is:
Can I write another SP(say SP1), which will call the above SP and will convert the boolean types to
CHARs like 'Y' for true and 'N' for false.
Finally I let the application to call the newly created SP1.
Followup February 5, 2003 - 9am Central time zone:
just prepare and execute:
declare
b1 boolean;
b2 boolean;
n1 number := 0;
n2 number := 0;
begin
sp_xxxx_map( ?, ?, ?, b1, b2 );
if (b1) then n1 := 1; end if;
if (b2) then n2 := 1; end if;
? := n1;
? := n2;
end;
from the jdbc app.
pseudo-boolean datatype best practices
June 13, 2003 - 11pm Central time zone
Reviewer: Kurt from Springfield, VA USA
Tom,
Hi. This is a follow-on to the current thread.
I'm involved in a large database development project and I'd like to find out your opinion on best
practices for what I'm referring to as "pseudo-boolean datatypes".
As mentioned in this thread, Oracle does not natively support an SQL boolean datatype, and you've
suggested an alternative implementation using a char(1) datatype with a check constraint. I think
that's a very good idea, and I've been using a similar approach for years. So, unless you've
revised your original suggestion, let's assume the datatype and length issues have been settled -
char(1).
You've also suggested that there should be a check constraint in place that ensures that the values
are members of an explicit domain - 'Y' or 'N'. This implies that the column can be defined as "Not
Null", and I think that's a good idea, too. Although I think ('Y','N') is the correct domain, I've
seen other implementations where ('T','F') are used, and that's fine - any 2 values are fine as
long as they're used consistently across the project.
Since joining my current project, I've heard of 2 more approaches from well-respected Oracle
developers. One developer suggests that one single value ('Y' for example) means True, and any
other value (including null) means False. For example...
Y = True
y = False
3 = False
null = False
F = False
etc.
The other developer suggests that null means False, and any non-null value means True (a C-like
paradigm). For example...
Y = True
y = True
3 = True
null = False
F = True
etc.
My implementations have always been more rigid - the column is defined as "Not Null", 'Y' means
True and 'N' means False. Anything else is an error. To help out a bit, I use a pre-insert/update
trigger which converts null values to 'N', and uppercases all values. Then the trigger raises an
exception if the value is not in ('Y','N'), although this functionality could be accomplished using
the check constraint that you mentioned.
I try to avoid the use of "null" to indicate an explicit value. To me, it's like making decisions
based upon the absence of a value rather than making decisions based upon the presence of a value,
and that seems counter-intuitive. I understand that there are other places where this approach is
used successfully - such as performing an outer join and using the null values in the "right-hand
side" of the join to detect missing records - but that seems more palatable to me. I consider a
"Not Null" column to be "stronger" than a nullable column, unless you're forced to pack in
arbitrary data simply to satisfy the constraint.
Also, I believe there are legitimate reasons within Oracle to favor "Not Null" columns. For
example, null values are not stored in an index, and this could impact the resources needed to
satisfy a query where that column appears in a predicate. And, the optimizer may choose a different
(possibly inferior) execution plan based upon whether the column is nullable or not, even if the
column does not appear in an index.
Can you provide a critique of the implementations mentioned here, and make a suggestion as to the
best approach in general? The target application is a web-based OLTP application (JSP, WebSphere),
with the usual data entry screens, searches, and reports.
Thanks, Kurt
Followup June 14, 2003 - 8am Central time zone:
if a column has a domain of three values
true
false
unknow
then a constant value for TRUE is called for, a constant value for FALSE and NULL for unknown.
If it has two -- then two constants are called for.
It seems to make more sense to me anyway to consistently code:
select * from t where ..... and shipment_has_shipped = 'Y';
.... and payment_made = 'N';
rather then,
.... and shipment_has_shipped is not null;
.... and payment_made is null;
the first two just seem to convery "more details" about what they are doing.
so, I've never used anything other then Y/N/null
representing tri-state in a 2-state client
June 14, 2003 - 10am Central time zone
Reviewer: Kurt from Springfield, VA USA
Tom,
Thanks for the response.
If the sole application sitting on top of the database only has 2 representations for the value of
a boolean field, then doesn't that imply that the database should support only 2 values? For
example, a checkbox control on an HTML form can only represent checked and unchecked, for True and
False. It's clear that when the HTML form displays a pre-populated record, it will take the field
value 'Y' and render the checkbox in a checked state, and will take the field value 'N' and render
the checkbox in an unchecked state. But what should it do with a null value? I'm sure the usual
approach is to render the checkbox unchecked. But since that's the same as 'N', then why allow null
values in the field at all?
In a similar way, what does it mean when the user submits the HTML form with an unchecked checkbox?
To the data handler (whether that's the client JSP or the database PL/SQL), that doesn't mean null,
it means 'N' even if the user is "unsure" of what the correct value should be. HTML forms simply
don't support tri-state boolean values.
Thanks, Kurt
Followup June 14, 2003 - 1pm Central time zone:
if it only has two values - Y or N, it should be defined:
flag char(1) NOT NULL check (flag in ('Y','N'))
there are no nulls to deal with then
Which would you rather see
July 2, 2003 - 8am Central time zone
Reviewer: DH from USA
Not sure about the purpose for this thread, because it seems to me that Oracle does have a boolean
datatype, but I'm curious at the present time, which you would rather see in an application that
uses these constructs a great deal:
if( flag != 1 ) then
or
if( <boolean variable> ) then
I gather from the thread that they're certainly functionally the same, but I've seen the latter
more often in your examples. Is either one more efficient than the other?
Followup July 2, 2003 - 8am Central time zone:
i disagree, I mostly use the first case in my stuff.
I would not:
bool_val := flag != 1;
if ( bool_val )
then
....
I would
if ( flag != 1 )
then
....
funny
July 2, 2003 - 9am Central time zone
Reviewer: DH from USA
how perception sometimes deviates from reality. Looking back, I do see the boolean construct in
your examples, but only when the reader provided such a construct in their question. Ironically, I
started using boolean variables only because it appeared to me that it was your preference.
Use of Boolean in Query
June 10, 2004 - 6am Central time zone
Reviewer: AS from INDIA
I wanted to use function in query which returns boolean. Kindly can you please demonstrate :
I tried : select IS_NUMBER ('AAA') from dual but it failed.
Regards,
AS
Followup June 10, 2004 - 8am Central time zone:
it returns boolean.
sql knows nothing about boolean.
you'll have to make it return something like "1" and "0" or "yes" and "no" - a number or string,
instead of a boolean.
Parameter boolean
September 17, 2004 - 4am Central time zone
Reviewer: Ditter from PHIL.
Hi Tom,
One of my colleague is suggesting to convert all the input/out parameters having a output field of
'Y/N' to boolean. According to him, "bugs caused by alpha-literals are avoided"
example :
PROCEDURE VALID_CR
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
P_PR VARCHAR2 IN
P_DR DATE IN
P_CHK VARCHAR2 IN/OUT
should be :
PROCEDURE VALID_CR
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
P_PR VARCHAR2 IN
P_DR DATE IN
P_CHK BOOLEAN IN/OUT
Is there any gain if we modify the existing codes. And I told him that it would be just a waste of
time converting this.... Any comments.
Followup September 17, 2004 - 9am Central time zone:
alpha-literals -- is that anything like "the typical alpha male"?
umm, no clue what he is talking about at all.
there is about 0% chance I would go back and change Y/N logic to True/False boolean's
utter waste of time.
Boolean Datatype
September 22, 2004 - 11am Central time zone
Reviewer: Kevin Ryan
I am an ASP.net developer and all I want is for a oracleadpter to populate a simple dataset to bind
to a datagrid.
I want the dataset to populate checkboxes and it cant because you guys dont want to use booleans.
Thanks a bunch.
Followup September 22, 2004 - 11am Central time zone:
your welcome?
Boolean Array in PLSQL?
November 8, 2004 - 4pm Central time zone
Reviewer: Andrew Cohen from Wellington, NZ
Hi, just curious if I declare an array of bools in PLSQL, will it be compressed into a bitarray,
i.e. one bit per bool, or 8 bools per byte? i.e.:
type bitarray is table of boolean index by binary_integer;
b bitarray;
for in in 1..8000 loop
b(i) := true;
end loop;
will this take up 8000 bytes or 1000 bytes, or possibly more for some PLSQL overhead? Would an
array of varchar2(1) or number(1) be smaller? how can i "trace" or "profile" the memory usage?
thanks!!!
Followup November 8, 2004 - 9pm Central time zone:
you can use v$sesstat to track your pga/uga memory usage.
ops$tkyte@ORA9IR2> create or replace procedure p( p_n in number )
2 as
3 type array is table of boolean index by binary_integer;
4 b array;
5 begin
6 for i in 1 .. p_n
7 loop
8 b(i) := true;
9 end loop;
10 end;
11 /
Procedure created.
ops$tkyte@ORA9IR2> set echo off
PL/SQL procedure successfully completed.
NAME VALUE
------------------------------ ----------
session pga memory max 630760
ops$tkyte@ORA9IR2> exec p(1);
PL/SQL procedure successfully completed.
ops$tkyte@ORA9IR2> @mystat2
ops$tkyte@ORA9IR2> set echo off
NAME V DIFF
------------------------------ ---------- ----------
session pga memory max 630760 0
ops$tkyte@ORA9IR2> @mystat "pga%max"
ops$tkyte@ORA9IR2> set echo off
NAME VALUE
------------------------------ ----------
session pga memory max 630760
ops$tkyte@ORA9IR2> exec p(100000);
PL/SQL procedure successfully completed.
ops$tkyte@ORA9IR2> @mystat2
ops$tkyte@ORA9IR2> set echo off
NAME V DIFF
------------------------------ ---------- ----------
session pga memory max 1855824 1225064
ops$tkyte@ORA9IR2> @mystat "pga%max"
ops$tkyte@ORA9IR2> set echo off
NAME VALUE
------------------------------ ----------
session pga memory max 1855824
ops$tkyte@ORA9IR2> exec p(200000);
PL/SQL procedure successfully completed.
ops$tkyte@ORA9IR2> @mystat2
ops$tkyte@ORA9IR2> set echo off
NAME V DIFF
------------------------------ ---------- ----------
session pga memory max 3400056 1544232
ops$tkyte@ORA9IR2> @mystat "pga%max"
ops$tkyte@ORA9IR2> set echo off
NAME VALUE
------------------------------ ----------
session pga memory max 3400056
ops$tkyte@ORA9IR2> exec p(500000);
PL/SQL procedure successfully completed.
ops$tkyte@ORA9IR2> @mystat2
ops$tkyte@ORA9IR2> set echo off
NAME V DIFF
------------------------------ ---------- ----------
session pga memory max 8032752 4632696
so, about a byte, plus a bit of "management overhead"
Re: Boolean Array in PLSQL?
November 8, 2004 - 10pm Central time zone
Reviewer: Andrew Cohen from Wellington, NZ
Wow, thanks for the quick response!!
Is it my math or does it seem like your results suggest about 10 bytes per item in the array. Ah,
because it is a sparse array it has to store the index, a binary integer, plus the boolean.
Also, any chance of seeing mystat2.sql?
Followup November 9, 2004 - 8am Central time zone:
mystat2.sql:
set echo off
set verify off
select a.name, b.value V, b.value-&V diff
from v$statname a, v$mystat b
where a.statistic# = b.statistic#
and lower(a.name) like '%' || lower('&S')||'%'
/
set echo on
mystat.sql:
set echo off
set verify off
column value new_val V
define S="&1"
set autotrace off
select a.name, b.value
from v$statname a, v$mystat b
where a.statistic# = b.statistic#
and lower(a.name) like '%' || lower('&S')||'%'
/
set echo on
PL/SQL vs SQL
November 9, 2004 - 12am Central time zone
Reviewer: Bob B from Albany, NY
Oracle decided that a boolean variable type would be a useful construct at some point. I'm very
glad they've done this as it allows complex logic to be precalculated and can thus increase
performance. Consider:
Case 1 with boolean:
my_boolean := <complex evaluation>;
WHILE loop_condition
LOOP
<common logic>
IF my_boolean THEN
do_action_1;
ELSE
do_action_2;
END IF;
<more common logic>
END LOOP;
Case 2 without boolean worst case:
WHILE loop_condidition
LOOP
<common logic>
IF <complex evaluation> THEN
do_action_1;
ELSE
do_action_2;
END IF;
<more common logic>
END LOOP;
Case 3 without boolean, better case:
IF <complex evaluation> THEN
WHILE loop_condition
LOOP
<common logic>
do_action_1;
<more common logic>
END LOOP;
ELSE
WHILE loop_condition
LOOP
<common logic>
do_action_2;
<more common logic>
END LOOP;
END IF;
I would argue that Case 1 is the most efficient, easiest to maintain, and easiest to understand.
Case 2 is equally as easy to maintain, might be a little more difficult to understand, but will
likely be less efficient. Case 3 is as efficient as Case 1, but can lose some maintainability
and/or readability (<common logic> and <more common logic> would be procedures/functions).
Oracle is pushing the forefront of SQL and will likely/hopefully add additional features to the
ANSI standard such as analytics and/or the modeling clause. A boolean datatype can offer several
optimization opportunities for Oracle.
I'm assuming a Boolean datatype would have to be tri-valued to fully support integration with
PL/SQL and to be consistent with ANSI SQL. This means each boolean column would require 3 bits.
Many of the tables I've seen will have several booleans to represent several T/F situations. These
currently take up a minimum of 1 byte. With one time coding, up to 2^8/3 = 85 boolean columns
could fit in 1 byte (though likely 2 bits per column for a total of 4 booleans would be closer to
reality or 8 1 bit columns if NOT NULL is enforced).
- my 2 cents
Followup November 9, 2004 - 8am Central time zone:
analytics are part of the SQL drafts already....
CASE (variable)
when value1
when value2
or
decode( variable, value1, <A>, value2, <B>, ... )
already do "boolean" work in SQL.
I'm not aware of any work on making a "bit field" like that in place.
boolean
May 10, 2006 - 6pm Central time zone
Reviewer: mal
1 CREATE TABLE posts (
2 id INTEGER,
3 hidden BOOLEAN,
4 subject VARCHAR(255) NOT NULL,
5* text VARCHAR(10) NOT NULL)
SQL> /
hidden BOOLEAN,
*
ERROR at line 3:
ORA-00902: invalid datatype
The underlying data type
July 18, 2006 - 1pm Central time zone
Reviewer: Marius
To be honest, a bool data type would be nice to have but not at all necessary. Actually I believe I
wouldn't even consider using it should it pop out the next version, there are just too many
projects already done the old/current way. Besides, I don't believe they could design it to be
faster or take less space(1 bit? forget it).
My question tho is: what would it be better to use, numeric(1) or char(1)?
Both take the same amount of space, 1 byte(ok, there might be exceptions with char(1), but that's
beyond the scope of this question).
From a performance point of view they are similar, the numeric approach being just slightly faster
in my insert tests, but being slightly slower in my select tests.
So what would you pick and why?
I'd rather choose the numeric approach, at least I'll get rid of '' in the ad-hoc queries.
Followup July 19, 2006 - 8am Central time zone:
i myself use varchar2(1) with Y/N in it.
Booleans.
August 29, 2006 - 12pm Central time zone
Reviewer: D from UK
i find the way that booleans are implemented in say mySQL to be..a bit odd.
look at this example:
mysql> create table test (a varchar(10));
Query OK, 0 rows affected (0.09 sec)
mysql> insert into test values ('abcd');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values ('Y');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values ('y');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values ('0');
Query OK, 1 row affected (0.01 sec)
mysql> select * from test where a = 0;
+------+
| a |
+------+
| abcd |
| Y |
| y |
| 0 |
+------+
4 rows in set (0.00 sec)
mysql>
assume that you had a code bug and that was an update on a big table..i meant to type '0' and not
0. (no rollback available in standard mysql "myisam" tables!).
:-s
numeric(1) or char(1)
October 6, 2006 - 8am Central time zone
Reviewer: awomynda from Belgium
We too have recently discussed whether our standard should be 0/1 or Y/N.
Working on DataWarehouse, I proposed 0/1 for easier-to-read queries.
Example:
total_sales * isDiscounted -- for discounted_sales
, total_sales * isHoliday -- for holiday_sales
rather than
decode(isDiscounted, 'Y', total_sales, 0) -- discounted
, decode(isHoliday, 'Y', total_sales, 0) -- holiday_sales
More on booleans
April 26, 2007 - 1pm Central time zone
Reviewer: Earl Lewis from Salt Lake City, UT, USA
Tom,
You said that you like to use a varchar2(1) for boolean datatypes. That's fine. I think that works for all the situations I would need.
But how about a PL/SQL function that returns a boolean and you then find at a later time that it would be very convenient to reuse this function, and all it's complex underlying logic, in your select statements? In other words, I want a true/false from my function so it fits nicely into my PL/SQL. Then I find that that same function (again, returning true/false boolean) would be really useful in my query output? But I can't use it because it returns an incompatible datatype.
And, I can't create another function with the same name/signature (except for the return value datatype). Well, actually, I can create it, but then when I try to use it SQL complains that it finds too many definitions of the function. Now I've got to go back and rework my original function and all the PL/SQL the uses it.
Obviously, some thorough forethought could eliminate this problem. But it's not always clear when/where you might want to use everything you write into an application.
Can you tell that I just ran into this problem? I know, I'm completely transparent. What can I do?
Either way, do you consider this a compelling argument for booleans in SQL?
Followup April 27, 2007 - 10am Central time zone:
so, you write a wrapper
create or replace function my_wrapper( .... ) return varchar2
as
begin
if (original_function(.....))
then
return 'y';
else
return 'n';
end if;
end;
/
PLSQL types are not SQL types - that is the mismatch here, you need to have a SQL type (sql being "lower" than plsql) for both to see.
Another winner!
April 27, 2007 - 5pm Central time zone
Reviewer: Earl Lewis from Salt Lake City
Of course! Sometimes you can't see the forest fo the trees.
Thanks for the reply and thanks for sharing your vast wealth of Oracle knowledge with us all.
Sincerely,
Earl
Please just add the boolean datatype
July 17, 2007 - 3pm Central time zone
Reviewer: Jd from Milwaukee, WI
Please accept a customer's request to add a boolean datatype; it is tiresome always having to "work around" the lack of a boolean datatype and it's something that's been frustrating for all developers with which I've worked.
I understand that a viable "solution" is to 1) create a field using currently supported types then 2) create a constraint restricting the vales on the new field and 3) create a wrapper for use in SQL or PL/SQL then 4) create a helper method or utility class to convert the type returned in the resultset.
As a customer, and also expressing the frustration of other customers and their developers, I am giving my feedback that, as I customer, I am frustrated with having to "work around" Oracle databases not having native boolean support.
question of bitmaps
September 18, 2007 - 6pm Central time zone
Reviewer: Dave from New York, NY
so while it is not necessary to have a "boolean" type (and i agree, i usually just use 0 and 1),
does oracle support bitmaps - ie an array of booleans? can you do bit tests like if you were to
use a raw data type? or generally do we use a 0/1 or Y/N column for each flag we're looking at
here? i know oracle can use bitmaps for indexes, can it use them for data types?
Lot's of Bool
April 15, 2008 - 1pm Central time zone
Reviewer: Ed Cortes from Puerto Rico
Definitely Oracle has a way of making everything more complex, this shown with this discussion on
Boolean data type. It's like the OraGuys are stuck in the 1973...
I'm also a .Net developer, and it's a pain in the *** to be converting everytime to 0/1...
you should consider your customers requests
April 30, 2008 - 2pm Central time zone
Reviewer: Samuel from Spain
hello, I'm a happy MySQL developer, in my new job they where tempted to use Oracle for their databases.
I evaluated your database solutions and seemed a good replacement, your RDBMS is robust, highly reliable, secure and easy to mantain, except for this, the boolean stuff, we got to use a lot of fields with true/false fields, to use in data mining and logistic regression, the programs we developed worked even three times slower because of the boolean parsing, since we are working with billions of records, speed is critcial, so we decided to stick with mysql.
The moral of this is that you LOST A CUSTOMER because of this. People are paying money (and a lot of money) for your solutions, don't you think you should give to your customers what they want....
Followup April 30, 2008 - 3pm Central time zone:
... the programs we developed worked even three times slower because of the boolean parsing, ..
umm, you did something seriously whacky then, please consider what you just said there.
given that boolean in mysql
http://dev.mysql.com/doc/refman/5.1/en/boolean-values.html
is just, well, 1 and 0 - a number - nothing special - I don't really see how you could get "three times slower"
please, elaborate on what you did exactly.
Is Oracle ever going to add a boolean datatype?
April 30, 2008 - 6pm Central time zone
Reviewer: G Siems from St Paul, MN
SQL2003 has a boolean datatype. Don't you think that maybe it's time for Oracle to finally add
support for it?
how can I know that?
April 30, 2008 - 8pm Central time zone
Reviewer: samuel from Spain
how can I know why the sollutions worked faster with mysql? they just did worked faster, with only
the same stuff, we where in a hurry since they were billions of records. and actually my strongest
point is:
People are paying money (AND A LOT OF MONEY) for your solutions, don't you think you should give to
your customers what they want....
Followup April 30, 2008 - 9pm Central time zone:
you said the way you implemented it in oracle was "three times slower"
so, tell us, how did you implement the concept of "0 and 1" in Oracle? I'm curious - because - well, 0 and 1 are just 0 and 1 (in mysql as well as oracle).
what was your implementation in Oracle - what did you do to mimic mysql having a #define of TRUE=1 and FALSE=0? (that is their boolean type, a number with 0 or 1 in it)
*chuckle*
May 1, 2008 - 2am Central time zone
Reviewer: Mike Hennessy from Brisbane, Australia
On a sidenote, "your welcome", tsk tsk, next thing it'll be "ur welcome". A slippery slope indeed !
:-)
response
May 2, 2008 - 12am Central time zone
Reviewer: Samuel
this part was is executed 15 times in billions (spanish billions, not english billions of
operations):
mysql:
boolean my_varb1, my_varb2;
//----retrieved somewhere from a control, checking file existances ()
//like a ficticious example
varb1 = file.exists(my_file.psp);
query = "SELECT * FROM some_table WHERE some_value=" + my_varb.toString();
//note mysql supports WHERE my_value = TRUE, my_value='TRUE'
result = db_exec(query);
with oracle:
boolean my_varb1, my_varb2;
varb1 = file.exists(my_file.psp);
string d2varb1;
if(varb1)
d2varb1 = "1";
else
d2varb1 = "0";
query = "SELECT * FROM some_table WHERE some_value=" + d2varb1;
result = db_exec(query);
it's worth to mention that boolean ands and ors are used as well. if you think there are better
ways, I'm open to use them, thanks (this is becoming a forum, sorry)
Followup May 2, 2008 - 7am Central time zone:
why would you use "spanish billion" instead of just trillion.
you executed that 15 trillion times - and lived to speak of it.
this has not a thing to do with numbers Samuel, everything to do with writing the most inefficient code humanly possible. Code that is horribly subject to SQL Injection and that has not a chance of scaling up in the real world. Why would you parse over and over and over and over again and again and again. You spent 90% or more of your runtime parsing sql in all probability.
NOTE: in mysql, where my_value = TRUE is precisely identical to where my_value = 1 - boolean my butt, it is a *number*
Antediluvian
May 6, 2008 - 5pm Central time zone
Reviewer: DK from UK
I think that for me there are two frustrating parts to not having booleans in SQL.
First, while it's possible to constrain the column to Y/N the same doesn't apply to queries.
i.e. WHERE Paid is fairly foolproof
while
WHERE Is_Paid = 'y'
WHERE Is_Paid = ' Y'
are typing mistakes that need tracking down
The second is in that it's not possible to use boolean logically.
For instance,
WHERE Invoiced AND NOT Paid
is unambiguous
whilst
WHERE Is_Invoiced = 'Y' AND Is_Paid = 'N'
is not always equivalent to
WHERE Is_Invoiced = 'Y AND Is_Paid <> 'Y'
Subsequent rationalisation of code often falls foul of these things.
There was a trend in the 70's to reduce silly coding errors. For that reason Oracle insists on
predeclaring variables.
Why not move with the times?
my two cents why Oracle not supports boolean
May 21, 2008 - 12pm Central time zone
Reviewer: Johnson from USA
my personel opinion why Oracle does not have Boolean support in Sql:
1. the oracle database designer is not a PL/SQL programmer, he is not using Toad to make lines of
lines of plsql code everyday and calls his BOOL2YN YN2BOOL wrapper functions all the time.
Obviously, Oracle's PL/SQL team definitely needs Boolean while its Database engine team is thinking
differently.
2. Supporting boolean in database level(SQL) is a loud voice from the user, however, taking actions
on this is not going to increase their revenue and only to increase your developing cost.
Sorry Tom, I can not accept your explanation.
Followup May 21, 2008 - 3pm Central time zone:
well, it could be that
it would really add nothing to the language.
where column = TRUE;
that is mysql. Wow, that is so much different from
where column = 'Y'
or
where column = 1
I'm sorry, but I don't see the issue.
issue for no boolean
May 21, 2008 - 3pm Central time zone
Reviewer: Johnson from USA
Tom:
the issue(inconvenient, to be exact) for not supporting boolean in DB level is , for database
centered application, when alot of logic is put inside PL/SQL , users have to use wrapper functions
like I do (BOOL2YN YN2BOOL) to remap the YN to boolean or vice versa.
Please do not tell me I can use "if OldEnough='Y' then ..." to do flow control, this is just not
the decent flow control way in any programming language. Google "oracle boolean" you will find tons
of sighs about this type of wrapper solution, Steven Feuerstein is also a strong supporter to use
boolean instead of YN inside PLSQL, and he also provides the similar wrapper functions.
To conclude: As a daily plsql programmer, I am not saying I can not live without boolean, but make
it available in database level will make my life way much easier. I bet most PL/SQL programmers (
if not all) will agree with me. And I will be much more looking forward to having this included in
Oracle Version XX than any other fancy features oracle has added to its new version .
Thanks
Followup May 21, 2008 - 3pm Central time zone:
..Please do not tell me I can use "if OldEnough='Y' then ..." to do flow control,
this is just not the decent flow control way in any programming language.
...
I won't tell you - but it should be obvious that not only can you - but it is done quite a bit. Don't look at my code, you might be disappointed that I've never felt the need to hide or 'wrap' this.
we'll just have to agree to disagree - I don't see it as a big deal at all - in 20 years, I've never "missed" a boolean - many of the languages I've used over the years never had the concept, it wasn't a big deal.
I can definitely say "if not all" is easily disproved. I am a plsql programmer.
and you know, the mysql boolean would not give you, does not give you (eg: the ansi implementation would not give you either) a boolean you would use like this:
if ( column )
then
it would give you
if ( column = TRUE )
then
which means, you'd be right back to where you are. If you want that right now, just create a package with constants true and false defaulted to Y and N and you'd be *done*

May 21, 2008 - 3pm Central time zone
Reviewer: Johnson from USA
well,
according to your logic, all computer languages should take out boolean as their data type, because
they can simply use Y and N to do it.
I am a lazy programmer, if I can use one line of code to do the job, I won't use two.
Some people can live without car for their life and have nothing to complain.
this is their life style.
Followup May 21, 2008 - 5pm Central time zone:
hate it when people put words in my mouth.
what flow of logic did you see that makes you say that.
if ( column )
versus
if ( column ='Y' )
lazy or no, there ain't much difference there.
and if you got a SQL boolean, you'd be typing
if ( column = TRUE )
which is one more character, so we are saving you a keystroke.
I never said "remove boolean from language X", I'm saying "I don't see the point in a SQL boolean, it doesn't do anything for us"
Language independance
May 21, 2008 - 6pm Central time zone
Reviewer: Nick Price from Coventry UK
I have inherited an application that was developed by a primarily French team, who obviously read your column - however, as "Y" and "N" mean nothing to them, they've chosen to use "O" and "N" (Oui and Non respectively)...
My Maltese colleague started developing a new module, so he chose to set up his boolean columns as "I" (Iva) and "L" (Le) - the module developed by my Swedish colleague used "J" (Ja) and "N" (Nej)...
Now, this is a somewhat exaggerated story - in truth, we only had hard-coded strings in English and French throughout the database.
However, I am very disappointed to discover that you recommend storing true/false flag values as CHAR(1), rather than a language independent solution such as NUMBER(1) - while I can appreciate that perhaps "1" and "0" aren't as intuitive, it certainly makes it easier for a multi-national development team to agree on a standard for the application!
Followup May 21, 2008 - 9pm Central time zone:
Ok, you have just convinced me with a compelling reason.
I now like 1 and 0 - I see your point here. It was like a light bulb going on - never hit that (the different languages).
And since 2002 when this was first asked - I've outlawed char(1), it would be varchar2(1) if it were a one character field today....
But 0 and 1 - you just convinced me, in a compelling way.

May 23, 2008 - 10am Central time zone
Reviewer: Joe Bloggs
I too am an Oracle expert of 20 years, and cannot for the life of me see what your objections to adding BOOLEAN datatypes in the DB are, Tom.
I have many a time desired it myself, only having to resort to the workaround of the VARCHAR2(1) option which confuses a lot of people. Adding a column constraint is mandatory, though I prefer to limit it to 'X' or NULL, and not 'Y' or 'N', or 0 or 1. That way, it is far more of a real representation of a flag, and as such a tad more self-commenting, as well as being language independent too. Also, if it becomes necessary to index the column, it will be done so efficiently since NULLs are never stored in non-unique indexes.
Further, your argument towards not implementing BOOLEAN natively and using VARCHAR2(1) as a workaround to store 'Y' and 'N' or 0 and 1 holds no water. Why not in that case only ever allow a character datatype natively and store all numbers and dates in that character form ?!?!? Not logical !!!
(PS. When is Oracle gonna let us use VARCHAR ? It must be the 15th anniversary of the VARCHAR2 datatype by now).
If it were possible to store Boolean types natively, Oracle could perhaps add some fancy indexing possibilities natively over the top too. Such as the ability to choose whether TRUE or whether FALSE could be represented in the index as NULL.
Example, CREATE TABLE PERSON (NAME VARCHAR2(30),
SEX VARCHAR2(1) CHECK (SEX IN ('M','F')),
CREDIT_WORTHY_FLAG BOOLEAN)
/
CREATE INDEX PERSON_CREDIT_WORTHY_FLAG_IDX ON PERSON (CREDIT_WORTHY_FLAG) REPRESENTING TRUE AS NULL
/
Now, to find all the uncredit-worthy people you would query where the credit-worthy flag is false, and harness the use of an index to do it (because only the FALSE values are stored in the index in this example).
Followup May 23, 2008 - 6pm Central time zone:
I don't have "objections", I don't see the incredible usefulness.
ANSI says:
boolean is a byte, it would actually be a number under the covers
you would use the words TRUE and FALSE and optionally UNKNOWN (in place of null)
You would insert:
insert into t (x,y) values (s.nextval,TRUE);
you would query
select * from t where y = TRUE;
I don't see *why this is so important*, what this does that is so much better, how this makes life wonderful. That is all.

May 27, 2008 - 4am Central time zone
Reviewer: Joe Bloggs
Followup May 23, 2008 - 6pm US/Eastern:
> I don't see *why this is so important*, what this does that is so much better, how this makes life wonderful. That is all.
Well, it would be more descriptive. Increasing readability of code. (Also personally, I would choose IS TRUE over = TRUE).
Bools and language
May 29, 2008 - 8am Central time zone
Reviewer: Per from Bremen, Germany
I for one think that a bool SQL Type would make table data more readable for the developer, and
reduce the amount of errors made while coding. In our project, we have -1 = True and 0 = False (or
was it the other way around).
Y/N is more descriptive, but it still has the problem of querying for T/F,y/n, j/n or other
variations of it. Best workaround I have found for now is to declare a constant in my code c_true
and c_false with the respective values. That way I can be sure, that any query comparing it to any
number/string is obviously wrong.... not pretty, but there is no better way atm.
Bool is not nessesary, bool is JUST beautifull. As a coder I perefer beautifull code, because I
think it is good code.
Readability in general
July 21, 2008 - 12pm Central time zone
Reviewer: Vincent Baier
I certainly have no problem using that implementation if there is no alternative; however, I am
forced to agree with many of the reviewers. While whatever implementation is required for a boolean
could certainly cause losses in performance (at least the first few releases it is present, these
things tend to clean up over time), the increased readability is a very important factor.
I have recently gotten into working with databases and as somebody who has always been for well
documented, easily readable code all SQL implementations have been a problem for me. In general
large SQL scripts and database types seem to be largely undecipherable compared to the usual code
of myself and my colleagues. This is further complicated by the fact that I am not a programmer by
trade and find that undocumented or unclear code is a lot harder for me to understand.
Furthermore, as an Electrical Engineer who often deals with digital applications, the convenience
of a BOOLEAN data type is particular obvious for small scale applications. When interfacing with a
wide scope of different programming languages including some assembly languages it does wonders for
readability of abstraction layers that are just a single step above hardware.
I've never been one to use just one technology or have a narrow sight when programming so for me
legibility is key. I need to know what things do when they talk to different languages,
implementations (high level or embedded), application types, etc. I see that it does not
necessarily add to the language from a technical level; however, its addition does not have any
obvious drawbacks. Certainly the previous implementation would still work, so why not add it for
the select few of us who might use it to some understandable end?
Thank you for any response.
Real need for boolean
August 27, 2008 - 11am Central time zone
Reviewer: Steve Appling from Atlanta, GA USA
My concern over the lack of a real Boolean type support isn't related to the size or format of the
data. Lack of a Boolean type limits the range of expressions that may be used in a select - in
other words, you must use only expressions and not boolean valued conditions.
Example:
With boolean valued columns C1 and C2:
In MySQL or PostgreSQL I can write:
SELECT C1 AND C2 FROM MYTABLE
In Oracle (assuming use of 0,1 for booleans) I would have to write:
SELECT CASE WHEN (C1=1) AND (C2=1) THEN 1 ELSE 0 FROM MYTABLE
This is much harder to read and I would expect much less efficient.
I think it is this lack of boolean results that prohibits use of all boolean valued conditions like
"SELECT A<B" when other numeric expressions like "SELECT A+B" work fine.
Followup August 29, 2008 - 12pm Central time zone:
You would really ultimately have to go back to ANSI and ask them to modify the language syntax and semantics. The language itself has no concept of "boolean", even in the current suggested approach, it would always be:
select * from t where something = TRUE;
if you select true from table, you get a number back - 1 or 0, not a boolean really.
The case statement would not be any less efficient and personally (honestly), the select c1 and c2 from t - I would expect (being a C programmer at heart, from the old days) something totally different from what you expect, I'd be expecting the result of c1 & c2 (bitwise and of two numbers). Being a C programmer that does a lot of database stuff, actually, select bitand(c1,c2) from t would do it.... using 1 and 0 anyway.
but the case statement doesn't seem any less "readable" to me,
select case when a<b then 1 else 0 end, ....

August 29, 2008 - 2pm Central time zone
Reviewer: G Siems from St. Paul, MN USA
With respect to ANSI, which "language syntax and semantics" are you referring to?
If you are referring to the SQL standard then I should point out that the boolean data type was
added to the standard starting with SQL99.
Followup August 30, 2008 - 9am Central time zone:
and the so called boolean datatype is simply a number
and the semantics would be
"where column = TRUE;"
not:
"where column"
it would be
"where column = false"
not
"where NOT column"
it is just a predefined constant. It is not any more boolean than Y/N, 1/0
Compile time errors
September 2, 2008 - 11am Central time zone
Reviewer: Salman Syed from Pittsburgh, PA
Tom,
Your points are valid. However, having a Boolean datatype would definitely be beneficial.
Here is a reason: We initially used Y/N with a check constraint. That caused the data in the
database to be okay. However, there was no way to ensure that all PL/SQL followed that convention.
We ran into issues with case etc.
Then we reverted to 0,1. However, even over there we ran into issues aswe could not enforce 0 and 1
to be the only values to be compared against in PL/SQL.
Having a boolean data type will allow to compiler to make, what are now runtime errors, into
compile time errors. That will be a huge plus.
We spent a lot of time hunting down where the issues might be and would have never had to do that.
why "=TRUE"?
September 9, 2008 - 5am Central time zone
Reviewer: Erich from Vienna, Austria
Should Oracle ever add a boolean datatype to SQL (and I surely hope so, for all the reasons already mentioned), I would strongly expect it not to be just a new name for number(1), but syntactically just as (or even more) powerful as in PL/SQL or other languages that support boolean variables.
i.e.
UPDATE orders SET has_active_items=EXISTS(SELECT x FROM items WHERE orderid=orders.id AND NOT item_cancelled);
SELECT * FROM orders WHERE NOT has_active_items AND NOT order_cancelled;
and even
CREATE FUNCTION xor(BOOLEAN v1, BOOLEAN v2) RETURN BOOLEAN AS
BEGIN
RETURN v1<>v2;
END;
/
SELECT xor(a,b)
FROM foobaar
WHERE xor(c,d)
GROUP BY a,b,c
HAVING xor(b,c);
This obviously requires the TRUE and FALSE literals to become native in SQL, too, as in
SELECT * FROM sometable WHERE FALSE;
Followup September 9, 2008 - 8am Central time zone:
tell it to the ANSI sql committee that states what the implementation should be.
enums
September 9, 2008 - 2pm Central time zone
Reviewer: rc from The Netherlands
Maybe not just booleans but also enumerations in SQL and PL/SQL?
Boolean Types
September 10, 2008 - 11am Central time zone
Reviewer: Shaun from UK
Hi Tom,
Like you, I have been and Oracle developer for many years and haven't felt any real loss for the
lack of a boolean type. In the new world of SOAP, however, it would really help!!! The proble
we're having is that we are using JDevleoper to expose a PL/SQL package as a web service and have
complex types coming in and going out, a few of the outgoing columns need to be classified as
BOOLEANS. The only way we are able to deal with complex record types is to define them on the
database and then reference them in the package. If we define the types locally in the package,
JDeveloper no longer allows us to expose that procedure as a web service. I am very vocal in
trying to ensure as much of the development here is done in Oracle, explaining that we too can
provide and call web services, but this is becoming a real limiting factor for us at the moment.
The concept is the point
September 20, 2008 - 2am Central time zone
Reviewer: Marc Wilson from Centennial, CO USA
Of course boolean types are just (often) a byte and there are many ways to represent or simulate the concept; that is not the point. The specific concept that something can be TRUE, or it can be FALSE, is the point of the BOOLEAN data type.
The possible values of the BOOLEAN data type are inherently unambiguous. True values are always represented by TRUE and false values are always represented by FALSE. It is this concept that is the whole point behind the BOOLEAN data type in any language. It is not because BOOLEAN data types save space, are easier to implement, easier to read, or are faster.
As touched on by an earlier reviewer, BOOLEAN values leave nothing up to interpretation, reinterpretation, or changing development team standards as an application evolves. The values are interpreted only by the compiler. They enable a consistency that removes the element of interpretation at the data element level altogether. A value of TRUE will always mean that a condition is true and FALSE will always mean that a value represents the concept of false. (I know I said it before)
The scope of a constraint on a single data element is only the single entity that it constrains. The constraint on the column does not ensure that the same type of data (or concept) will be represented the same way in another column in a different table. (I know that most all reviewer and readers here know this)
The scope of the constraint that a data type imposes, is the entire application that is developed with a language. Data types ensure that data of that type are represented consistently.
A BOOLEAN data type removes any chance that one person will decide to use 'Y', another 'y', another '1', another 'T', to represent the *concept* of TRUE. A BOOLEAN data type is a simple and concise way to ensure consistent representation, across an application, of a *very* common concept in computer programming and data representation; whether something is TRUE or not.
It would not be desirable to use a VARCHAR column to hold numbers (efficiency aside) and have one person represent the number 45 (forty-five) as '45', another as 'forty-five', another as 'FORTY FIVE', another as 'VL' (50 minus 5), and so on.
Mechanics are not the reason a BOOLEAN data type should exist; it is to assist in the consistent representation of an important and common concept. The BOOLEAN concept is so rudimentary, that how it is represented, should not be left up to interpretation of the personalities of multiple developers (or the multiple personalities of a single developer for that matter).
I have never heard a programmer tout the amazingly perfect and extra cool way they represented a TRUE value before. (The representation of BOOLEAN entities are just not that interesting)
Tom, I absolutely enjoy the raw representation of the facts that your insightful responses embody. However I feel that you are arguing for the sake of arguing on this subject.
...just my 499 words.
Thank you.
Followup September 21, 2008 - 1pm Central time zone:
why is boolean any different from any other domain value.
why is boolean different from the column that may only contain A, B, or C.
or the column that can only have the integers 1-10
All of the arguments have been "well, it would be consistent", but that is true for any domain value constrained type - all of them. They all need to use values consistently - for all domain constrainted types. I don't see anyone saying "we need a COLOR type, else someone might use magenta as a value instead of reddish-purple which we think is right"
I just don't see how TRUE and FALSE lead us into a greater place.
In fact, I see all kinds of issues where binds would never be used again :( Because how to you "bind" true or false. They become keywords all of a sudden. What does a client bind for trueness? (and this is especially true of enumerations - something which I hope sql never even remotely considers)
And what of the obvious ambiguity all of a sudden in plsql where true and false are already defined and are not zero and one.
It sounds like such an "easy quick change", but I see more questions, ambiguities, issues than "easy-ness" - truly.
I also think that the "concept is the point", here.
December 11, 2008 - 1pm Central time zone
Reviewer: Juan Calero from Madrid, Spain
I also think that the "concept is the point", here.
It's nice to have an abstraction of what means "Yes" and what means "No". We do not use everyday
"all the range of colors" or some other domain value constrained type or collection, but "Yes" or
"No" is used globally, by everybody, everyday.
Besides, you say that you always use the varchar 'Y', 'N'. It's important to you, then, to keep
that consistency by always using the same rule.
¿Why then, translate this effort to all us? Isn't it better , if we are using the same concept, to
use the same rules?
I'm sure every single Oracle database out there have implemented an "ad hoc" boolean data type and
the administrators and developers have to deal with it, spending time in the definition of how to
store Yes and No and how to check for it.
Yes and No it's pure logic and mathematics and, the same as NUMBER(9), it would be nice to have and
easy, intuitive and universal way of defining it in Oracle.
Maybe BOOLEAN it's not ANSI, but, hey, Oracle is not precisely standard SQL, anyway.
Boolean type is a conflictive one
March 21, 2009 - 2pm Central time zone
Reviewer: Javier Castañón from Mexico City
I was irritated with the lack of boolean type in several databases and thought Mr. Kyte was very stubborn in his views about this "issue". Now that I'm assembling an SQL and PL/SQL coding conventions manual for a customer, did some homework and I have to accept that I've changed my mind and now I side with Mr. Kyte. Furthermore, I plan to discourage the use of booleans in the data model. My rationale is as follows:
According to http://troels.arvin.dk/db/rdbms/#data_types-boolean:
"The BOOLEAN type is optional (has feature ID T031), which is a bit surprising for such a basic type. However, it seems that endless discussions of how NULL is to be interpreted for a boolean value is holding BOOLEAN from becoming a core type."
"The standard says that a BOOLEAN may be one of the following literals:
* TRUE
* FALSE
* UNKNOWN or NULL (unless prohibited by a NOT NULL constraint)"
Citing from Joe Celko's "Thinking in Sets" 1st Ed., page 228:
"The BIT and BIT VARYING data type were deprecated in the SQL:2003 Standards, ... While BOOLEAN had not yet been deprecated as of this writing, it also has problems with the rules about NULLs and the three-valued logic of SQL"
"The NULL cannot be treated as an UNKNOWN because one of the basic rules of NULLs is that they propagate. The resulting four-valued logic is inconsistent:
UNKNOWN AND TRUE = UNKNOWN
UNKNOWN AND FALSE = FALSE
NULL AND FALSE = NULL
NULL AND TRUE = NULL"
And from page 229, same book:
"There are two situations in practice. Either the bits are individual attributes, or they are used as a vector to represent a single attribute"
One example: "Is this garment domestic or imported?" the answer could be encoded with at least two values but some people think there is a problem because they would prefer to use Is_Domestic = True. Same case with answers like yes/no, according to Celko those eventually could expand to "Not Answered", "Not Applicable", etc. In the former example, the garment origin could be expanded to ISO country codes. Another example: "Is this item public?" could be expanded from yes/no or public/private to "public only for friends".
With a better data model, cases like:
WHERE Is_Invoiced = 'Y' AND Is_Paid = 'N'
would be:
WHERE Invoice_Number IS NOT NULL AND Payment_Date IS NOT NULL
Things like CREDIT_WORTHY_FLAG BOOLEAN perhaps should be computed values, not attributes to be stored. And what about columns used as boolean flags that are not consistent with data in other columns? In those cases either there are not constraints or triggers that check the values or there are so many that maintenance is a nightmare and not all checks are performed.
Last but no least, there are people that need boolean because either their user interface use them as in checkboxes or their web services transfer them through the wire. I could not comment on those cases, my data model usually come from requirements in the business domain, not from constraints in user interface technologies or infrastructure.
I believe Tom Kyte when he says "in 20 years, I've never 'missed' a boolean"
If boolean is not a useful data type, then what is?
August 14, 2009 - 10am Central time zone
Reviewer: Jeff V. from Cleveland, OH USA
First off, I appreciate this long standing discussion on the boolean data type in Oracle. I just
wanted to comment on the issue.
In my opinion, the comments of "boolean is a useless type because you can use a char(1) and a check
for Y/N" is not valid. By this same logic, we should then ditch the DATE type, because we can
represent date/time stamps with a NUMBER (ticks since epoch), and while we're at it, why keep a
NUMBER at all, since it can be a VARCHAR with a check for 0-9?
My point being, "we don't need a boolean because we can represent it with something else" is a bad
argument because everything can be represented by something else. But that doesn't mean we should
ditch every type and store everything as bits.
Oracle missing basic types
September 15, 2009 - 6pm Central time zone
Reviewer: Karsten from Germany
Of course, no one really needs a BOOLEAN type to achieve what s/he has in mind.
Of course, we don't need wireless broadband Internet, yes, and we don't need 2 TV's per household.
If that's your understanding of the word "progress", we should all crawl back into caves and wait
until the sun rises...
It's conceptual! Oracle builds every fancy thing into their products and doesn't manage to provide
a BOOLEAN type? That's ridiculous - given that Oracle is the market leader.
For booleans, the true/false check shouldn't involve any operator. In Java, one writes
if ( boolvar ) ...
In C/C++ you write
if ( intvar ) ...
In SQL you should be able to write
WHERE bool_col ...
...which you can't in Oracle (PostgreSQL can). MySQL offers an extension, you can at least do (with
any int):
WHERE int_col ...
Considering the BOOLEAN issue, Oracle is the worst DBMS I know of. Oracle doesn't even support
domains, so one might have thought: "Well, I'll emulate booleans via an integer" - bogus. You have
to repeat and can't reuse the boolean type declaration.
No one needs string BOOLEANs. They are just a kind of enumerated type, with their localization,
capitalization, typing, and mapping issues all having been addressed in this thread. Not to mention
the metadata issue... and the actual data:
The natural way to store BOOLEANs in computers has always been to use integers with 0 meaning false
and 1 (or non-zero) meaning true. It goes all the way down to processor instructions. Why should
anyone care about strings booleans then? I read all the above, it's rethoric...
Can JDBC prepare statement handle out parameters?
November 3, 2009 - 4am Central time zone
Reviewer: Patil from London
Tom,
For one of the queries above, you've mentioned the following workaround,
just prepare and execute:
declare
b1 boolean;
b2 boolean;
n1 number := 0;
n2 number := 0;
begin
sp_xxxx_map( ?, ?, ?, b1, b2 );
if (b1) then n1 := 1; end if;
if (b2) then n2 := 1; end if;
? := n1;
? := n2;
end;
from the jdbc app.
I've got the similar problem now, but i'm not sure how to register the outparameters for statement which is prepared with Preparestatement call.
I believe PreparedStatement class only provides the Set**** methods and doesn't have the method "registerOutParameter".
Please help me?
Followup November 9, 2009 - 2pm Central time zone:
you need to use a callable statement.
there are "statements", they should never be used except perhaps for DDL, but then again, most things should never do DDL either.
there are preparedstatements - send inputs to the statement. used for most all DML
there are callablestatements - send inputs and retrieve outputs from the statement. used for some dml (returning clause for example) and often for stored procedures.
|