Write a simple program on cursors

Answers were Sorted based on User's Feedback



Write a simple program on cursors..

Answer / a.jyothsna

declare
cursor cur_t is select * from test;

var_t test%rowtype;
begin
open cur_t;
loop
fetch cur_t into var_t;
exit when cur_t%notfound;
dbms_output.put_line('a: ' || var_t.a || ', b: ' ||
var_t.b);
end loop;
end;
/

Is This Answer Correct ?    12 Yes 2 No

Write a simple program on cursors..

Answer / 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

More SQL PLSQL Interview Questions

column A column b | output 10 7 | 10 5 8 | 8 7 -9 | 7 3 5 | 5 0 6 | 6 Write a sql query to print such output.

4 Answers  


Does truncate require commit?

0 Answers  


Why do we use %rowtype & %type in plsql?

0 Answers  


What are all the different normalization?

0 Answers  


What is the difference between rename and alias?

0 Answers  






What are the data types allowed in a table?

3 Answers  


In pl/sql, what is bulk binding, and when/how would it help performance?

0 Answers  


what is the correct way of selection statement a. select/from/table_name/orderby/groupby/having b. select/from/table_name/groupby/having/orderby

5 Answers   HCL, JPMorgan Chase,


What is an implicit commit?

0 Answers  


What is pl sql variable?

0 Answers  


What problem one might face while writing log information to a data-base table in pl/sql?

0 Answers  


diff b/w function and procedure?

9 Answers   iFlex,


Categories