Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Use of boolean returning functions in a project

746586Jan 14 2010 — edited Jan 18 2010
Hello all gurus,

in my project, we have a fairly important packaged functions that return boolean values. Working with these ones in pl/sql is very fine. But sometimes we need to reuse these functions in SQL, but no luck because bools are usable under pl/sql only and can't interact in any way in SQL statements. So the workaround should be to use these functions to return us some Y/N or 1/0 to emulate boolean behavior in SQL statements.

Here what i tested with not luck:
-- not work
select r.role, sys.diutil.bool_to_int(dbms_session.is_role_enabled(r.role)) as is_role_enabled
from   dba_roles r;

-- not work
select r.role
from   dba_roles r
where  sys.diutil.bool_to_int(dbms_session.is_role_enabled(r.role)) = 1;

-- not work
select t1.id, 
       bool_to_char(my_bool_func(t1.x, t1.y, ...)) as is_something
from   t1;

-- not work
select t1.id, 
       sys.diutil.bool_to_int(my_bool_func(t1.x, t1.y, ...)) as is_something
from   t1;
The odd wrapping trick as a last resort solution is working....
-- Works! Seems the only way, but a lot of wrapping work...
create or replace function my_bool_func_wrap(p_x number, p_y number, ...) return varchar2 as
begin
   return bool_to_char(my_bool_func(p_x, p_y, ...)); 
end;
/

select t1.id, 
       my_bool_func_wrap((t1.x, t1.y, ...)) as is_something
from   t1;
I read a lot, but no elegant and working way.
Is there a more standard, elegant universal way to call bool functions from SQL?
Is creating a custom type visible and usable from both pl/sql and sql, if possible, a way to go?
Any other pointers?

For new development, is it good to make my boolean type returning functions using SQL compatible type like CHAR (Y/N) or NUMBER (1/0) ? It will make us less wrapping job, but more and less elegant bool handling code on the pl/sql side.

What is the goal to have bool only in pl/sql and not usable in SQL? It's kind of a feature incompatibility in the same product. Strange...

Thanks a lot
Bruno
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 15 2010
Added on Jan 14 2010
6 comments
4,160 views