The most commonly used cursor operation is to Perform Batch modification or batch deletion operations in the stored procedure. For example, after deleting a master table record, you can execute a stored procedure to delete the detailed records corresponding to the record. Or modify the data of a table and then write the data of another table. This is often used in ERP software development. For example, the actual lifting weight on the contract should be reversed after the warehouse picking and submitting a single instance, which should also be supported by a good database design.
The following describes how to use a cursor in an oracle stored procedure:
- Procedure proc_fee_bymaindel (p_mainid in varchar2)
- Is
- -- ID of the pre-deletion ticket
- N_feeid varchar2 (32 );
- Cursor cur
- Is
- Select feeid
- From efi_feeadjustsubline
- Where isdel = 0 and mainid = hextoraw (p_mainid );
- Begin
- For cur_result in cur
- Loop
- Begin
- N_feeid: = cur_result.feeid;
- Proc_fee_del (n_feeid );
- Exception
- When others
- Then-insert an error
- -- Assign values to the return value
- Raise_application_error (-20000,
- 'Fee deletion error! '
- | Sqlerrm
- );
- Goto proc_end;
- End;
- End loop;
- <Proc_end>
- NULL;
- End proc_fee_bymaindel;