Declare
Cursor
Stus_cur
Is
Select*
FromStudents; -- defines the cursor and assigns a value (is cannot be used separately from cursor) cur_stu students %
Rowtype; -- Define rowtype
Begin
Open
Stus_cur; -- Enable cursor
Loop-- Loop
Exit
WhenStus_cur %
Notfound; -- Cyclic Condition
Fetch
Stus_cur
IntoCur_stu; -- the cursor value is assigned to rowtype dbms_output.put_line (cur_stu.name); -- output
End
Loop; -- End the loop
Close
Stus_cur; -- Close the cursor
End;
PLSQL is a process-oriented language. This type of language also has c, COBOL, etc. The common feature of this type of language is that only one piece of data can be processed at a time, and the object returned by database SQL is a set, in this way, problems may occur when you directly use the PLSQL program. In this environment, a cursor is displayed. The cursor is actually a memory address and points to the result set queried by SQL, when necessary, fetch data [fetch] One by one based on the cursor until all data is obtained.
Cursor
Mininter1
Is
SelectT1.rm _ interface, t1.rm _ merchno,
Min(Getexp (t1.rr _ id, tradeamount, '','', '0') minexp
FromT_r_merchant T1
WhereT1.rm _ interface = interid1
OrT1.rm _ interface = interid2
Group
ByT1.rm _ interface, t1.rm _ merchno;
Open
Mininter1;
Loop
Exit
When
Mininter1%
Notfound;
Fetch
Mininter1
IntoNresult, tmpmchno, minexp; icount: = mininter1 %
Rowcount;
End
Loop;
Close
Mininter1;
Cursor cursor: (loop operation of batch data)