Write a simple program on cursors

Answer Posted / subhendu

CREATE OR REPLACE Function test( I_name IN varchar2 )
RETURN number
IS

CURSOR c1
IS
SELECT course_number,
instructor
from courses_tbl
where course_name = I_name
FOR UPDATE of instructor;

v_number courses_tbl.course_number%type;
v_instructor courses_tbl.instructor%type;

BEGIN

open c1;
fetch c1 into v_number,v_instructor ;

if c1%found then

UPDATE courses_tbl
SET instructor = 'SMITH'
WHERE CURRENT OF c1;

COMMIT;

end if;
close c1;
RETURN v_number;

END;

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to check if a column is nullable before setting to nullable?

768


Which is faster view or stored procedure?

688


Why do we need unique key in a table?

673


what is the command line end user interface - mysql? : Sql dba

690


What is difference between hql and sql?

700






Enlist the advantages of sql.

739


What are the basic sql commands?

741


write an sql query to get third maximum salary of an employee from a table named employee_table. : Sql dba

722


How do you sort in sql?

774


Explain 3 basic parts of a trigger.

1037


What is minus?

751


How do I run a sql script?

727


how to do backup entire database? : Transact sql

880


Is hadoop a nosql?

743


Why are sql stored procedures used?

795