Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

This is my program for cursor, but I am not getting how to execute the cursor on a database.

emp=# CREATE or replace function cursor_demo() returns integer as $$
declare 
emp_rec employee%rowtype;
emp cursor for select * from employee;
comm numeric(6,2);
begin
loop
fetch emp into emp_rec;
if emp_rec.deptno = 5 then 
comm:=emp_rec.salary*0.2;
else if emp_rec.deptno=8 then
comm:= emp_rec.salary*0.5;
else if emp_rec.deptno = 10 then
comm:=emp_rec.salary*0.3;
end if;
end if;
end if;
raise notice 'emp_rec.ename||emp_rec.deptno||emp_rec.salary||comm.';
exit when not found;
end loop;
close emp; 
end;
$$ language'plpgsql';
share|improve this question

migrated from serverfault.com Feb 27 at 5:16

This question came from our site for system and network administrators.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.