Oracle/PLSQL WHERE CURRENT OF Statement

Posted 有没有成功

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle/PLSQL WHERE CURRENT OF Statement相关的知识,希望对你有一定的参考价值。

 
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.
译:如果你想删除或者更新被Select For Update引用的记录,你可以使用Where Current Of语句。
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.
译:Where Current Of语句允许你更新或者是删除最后由cursor取的记录。
Updating using the WHERE CURRENT OF Statement
Here is an example where we are updating records using the Where Current Of Statement:
译:下面一个使用Where Current Of更新记录的例子:
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 instructor;

BEGIN
open c1;
fetch c1 into cnumber;

if c1%notfound then
     cnumber := 9999;
else
     UPDATE courses_tbl
        SET instructor = ‘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:
译:下面一个使用Where Current Of删除记录的例子:
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 instructor;

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;
 
 

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow











































以上是关于Oracle/PLSQL WHERE CURRENT OF Statement的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Java 中执行 Oracle PLSQL 块

带有“where exists”的“Set”比没有的效果更好

不装oracle plsql怎么用

急! 换电脑之前PLSQL可以正常登陆 换电脑后PLSQL和 ORACLE 都没重装 现在运行plsql登录错误,有空白提示框

Redshift Cross join忽略where子句

转oracle PLSQL基础学习