Ishita
Ishita

Reputation: 41

How to get next and previous record from cursor?

I have a table named testtransaction which stores pervQuestionId and NextQuestionId... How to insert records in this table through cursor? there is something cursoe.getnext()...how do i implement it? My code is shown below:

 create or replace function store_data(disciplineid in char,
                                       NoOfQuestions in number)
  is
  cur_out sys_refcursor;
 begin         
     open cur_out for
     select getguid() tmp,
     QuestionNo,Disciplineid
     from tbliffcoQuestionmaster
     where (DisciplineId=discipline1 AND  rownum <= disc1_NoOfQuestions)
     order by tmp ;
 ///now it should insert records.
end;

Upvotes: 1

Views: 2621

Answers (1)

wadesworld
wadesworld

Reputation: 13763

I don't want to completely write the answer since it's homework and you're supposed to be doing the work. One of the basic formats of a cursor loop is:

LOOP
   FETCH cursor INTO x;
   EXIT WHEN cursor%NOTFOUND;
   --do something
END LOOP;

Maybe that will get you on the right track. Googling for "Oracle cursor" should get you dozens of examples of how cursors are used.

Upvotes: 2

Related Questions