Tuesday, September 4, 2007

Function

Function

create or replace FUNCTION f1 (a1 number)
RETURN
varchar IS
a number;
v varchar2(25);
BEGIN
select ename into v from emp where empno=a1;
RETURN v;
END ;

**** To exec the fun ****

select f1(7369) from dual;

**** Func with select and boolean and exception****

create or replace FUNCTION f1 (a1 number)
RETURN
boolean IS
v varchar2(25);
t1 boolean;
BEGIN
select ename into v from emp where empno=a1;
if v='SMITH' then
return TRUE;
end if;

exception
when no_data_found then
return FALSE;
END ;

**** To exec the fun ****

declare
t2 boolean;
begin
t2:=f1(7368);
if t2 then
dbms_output.put_line('found');
else
dbms_output.put_line('not found');
end if;
end;

No comments: