0% found this document useful (0 votes)
14 views1 page

Function

Uploaded by

b.nagnath194
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Function

Uploaded by

b.nagnath194
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

create table employee

( employee_id number,
emp_name varchar(100)
);

insert into employee (employee_id,emp_name) values (10,'SANJAY');


insert into employee (employee_id,emp_name) values (11,'VIJAY');
insert into employee (employee_id,emp_name) values (12,'JOHN');
insert into employee (employee_id,emp_name) values (13,'ABHI');
insert into employee (employee_id,emp_name) values (14,'ROHAN');
commit;

CREATE OR REPLACE Function employee_find


( empid_in IN varchar2 )
RETURN varchar2
IS
cname varchar2(20);
cursor emp_cur is
SELECT emp_name
FROM employee
WHERE employee_id = empid_in;
BEGIN
open emp_cur;
fetch emp_cur into cname;
if emp_cur%notfound then
cname := 'NO RECORDS';
end if;
close emp_cur;
RETURN cname;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR-
'||SQLERRM);
END;

declare
result varchar2(20);
begin
-- Call the function
result := employee_find('10');
Dbms_Output.Put_Line('The employee name is' ||result);
end;

You might also like