It is sometimes necessary to modify the data in large areas, this time with a circular statement efficiency is not high. The cursor seems like a good choice when the temporal table doesn't meet the point-to-point modifications (PS: It's like a cursor is a loop)
Now there are two tables T1 (Ryid number,name nvarchar2 (), salary number,paydate date ...) To keep the employee's monthly salary.
T2 (Ryid number,paysalary number) Monthly payroll is now adding paysalary from T2 to T1
Can be implemented directly with update;
Now uses Oracle's for cursors to implement
1 --Defining Cursors2 Declare3 cursorId--Cursor name4 is5 Selectryid,salary from T2; --Insert the required content into the cursor 6R_ID ID%RowType--sort of like rows in DS.7 8 begin9 forr_idinchID LoopTen UpdateT1SetT1.salary=r_id.paysalary--Content One whereT1.ryid=R_id.ryid; A EndLoop; - End;
Other types of cursors are similar.
The content section cannot output content with a SELECT statement.
As a memo
Http://www.cnblogs.com/sc-xx/archive/2011/12/03/2275084.html Reference Address