Oracle/PLSQL: where current of statement

Source: Internet
Author: User

Oracle/PLSQL: where current of statement

 

--------------------------------------------------------------------------------

If you plan on updating or deleting records that have been referenced by a select for update statement, you can use the where current of statement.
If you want to delete or update records referenced by select for update, you can use the where current of statement.
The syntax for the where current of statement is either:
Update table_name
Set set_clause
Where current of cursor_name;
Or
Delete from table_name
Where current of cursor_name;
 
The where current of statement allows you to update or delete the record that was last fetched by the cursor.
The where current of statement allows you to update or delete the records finally obtained by cursor.
Updating using the where current of statement
Here is an example where we are updating records using the where current of statement:
The following example uses where current of to update a record:
Create or replace function findcourse
(Name_in in varchar2)
Return number
Is
Cnumber number;
Cursor C1
Is
Select course_number, instructor
From courses_tbl
Where course_name = name_in
For update of policuctor;

Begin
Open C1;
Fetch C1 into cnumber;

If C1 % notfound then
Cnumber: = 9999;
Else
Update courses_tbl
Set policuctor = 'Smith'
Where current of C1;
Commit;
End if;

Close C1;
Return cnumber;
End;
 
Deleting using the where current of statement
Here is an example where we are deleting records using the where current of statement:
The following example uses where current of to delete a record:
Create or replace function findcourse
(Name_in in varchar2)
Return number
Is
Cnumber number;
Cursor C1
Is
Select course_number, instructor
From courses_tbl
Where course_name = name_in
For update of policuctor;

Begin
Open C1;
Fetch C1 into cnumber;

If C1 % notfound then
Cnumber: = 9999;
Else
Delete from courses_tbl
Where current of C1;
Commit;
End if;

Close C1;
Return cnumber;
End;

Article Source: http://www.diybl.com/course/7_databases/oracle/2007114/84247.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.