Home » SQL & PL/SQL » SQL & PL/SQL » Returning one boolean for mutiple inputs
Returning one boolean for mutiple inputs [message #37802] Thu, 28 February 2002 09:42 Go to next message
epro
Messages: 11
Registered: January 2002
Junior Member
Hi

I have function that returns a boolean(True or false),
It does in such a way, first it looks for rows in a table, where column1 = :parameter,

then the cursor gives 3 or 4 rows.

in my logic, one row is enough if that satisfies the requirement.

I have program like this
============
cursor c select * from tab_1
where emp_num = &p;
/* this cursor gives 3 or 4 rows *, I have to see each row, for condition and result*/

If 1st row satisfies, I dont want to process 2nd row with same emp_num., but if not I have to chek all rows.

begin
for c_rec in c
loop
if emp_dept in (a,b) then
return true /* and stop */
elsif emp_dept in ('c') then
call_proc(p1,p2)
if p2 = c2 then
return true /* and stop */

elsif....

end loop;

after checking all rows, if we can't return TRUE, then
we have return FALSE.

===================

any idea, please let me know.

Thanks
Re: Returning one boolean for mutiple inputs [message #37804 is a reply to message #37802] Thu, 28 February 2002 10:45 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Wouldn't just adding a 'return false;' after your loop accomplish what you want?

That is, if none of the conditions are satisfied as you run through your cursor, return false.

It would appear this is optimized since the first true condition you hit will exit the function.
**Re: Returning one boolean for mutiple inputs *** [message #37805 is a reply to message #37802] Thu, 28 February 2002 10:57 Go to previous messageGo to next message
epro
Messages: 11
Registered: January 2002
Junior Member
you are right, but IF none of the conditions are satisfied for all rows ( say 3 or 4), then only I want
to return false,
else

if one of any condition is satisfied ( even for one row), I want to return true.

Thanks for reply
Re: Returning one boolean for mutiple inputs [message #37807 is a reply to message #37802] Thu, 28 February 2002 11:26 Go to previous message
Jon
Messages: 483
Registered: May 2001
Senior Member
My suggestion:

declare l_boolean boolean := FALSE;
.
.
.
if p2 = c2 then l_boolean := TRUE;
end if;
.
.
RETURN (l_boolean);
Previous Topic: Re: whynot>rownum?
Next Topic: Re: Returning one boolean for mutiple inputs
Goto Forum:
  


Current Time: Thu Apr 18 14:48:31 CDT 2024