Question: Can you
please show an example of PL/SQL using the BOOLEAN datatype? I
need to see how the BOOLEAN is used in PL/SQL.
Answer: Invented by George Boole (Boolean
Logic), Boolean values are single byte datatypes that correspond to
TRUE (1), FALSE (0) or NULL () values.
For more working examples of Boolean values in PL/SQL see the
code depot download in the book
Easy Oracle PL/SQL Programming.
Boolean values are great for checking complex evaluations in
PL/SQL.
A Boolean function can be wither a one (1) for TRUE and a zero
(0) for FALSE:
function false return
boolean
is
begin
return 0;
end;
function true return
boolean
is
begin
return 1;
end;
Here is an example of a Boolean condition within a PL/SQL
function:
create
function
credit_is_good
good_credit BOOLEAN := FALSE
. . .
Return BOOLEAN
BEGIN
if complex IF/then else test > 500 then
good_credit = := TRUE
END;
Here is another example of a Boolean operator in a PL/SQL
stored procedure:
PROCEDURE profiler_control(
start_stop IN VARCHAR2,
run_comm IN VARCHAR2,
ret OUT
BOOLEAN) AS ret_code INTEGER;
BEGIN
ret_code:=dbms_profiler.internal_version_check;
IF ret_code !=0 THEN
ret:=FALSE;
ELSIF start_stop NOT IN ('START','STOP')
THEN
ret:=FALSE;
ELSIF start_stop = 'START' THEN
ret_code:=DBMS_PROFILER.START_PROFILER(run_comment1=>run_comm);
IF ret_code=0 THEN
ret:=TRUE;
ELSE
ret:=FALSE;
END IF;
ELSIF start_stop = 'STOP' THEN
ret_code:=DBMS_PROFILER.FLUSH_DATA;
ret_code:=DBMS_PROFILER.STOP_PROFILER;
IF ret_code=0
THEN
ret:=TRUE;
ELSE
ret:=FALSE;
END IF;
END IF;
END profiler_control;
|
|
Get the Complete
Oracle SQL Tuning Information
The landmark book
"Advanced Oracle
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
buy it
for 30% off directly from the publisher.
|