首页 > 其他 > 详细

WHERE CURRENT OF

时间:2014-05-26 01:33:05      阅读:411      评论:0      收藏:0      [点我收藏+]

果你想删除或者更新被Select For Update引用的记录,你可以使用Where Current Of语句。

bubuko.com,布布扣
UPDATE table_name
    SET set_clause
    WHERE CURRENT OF cursor_name;
OR
DELETE FROM table_name
WHERE CURRENT OF cursor_name;
bubuko.com,布布扣

Where Current Of语句允许你更新或者是删除最后由cursor取的记录。
下面一个使用Where Current Of更新记录的例子:

bubuko.com,布布扣
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;
bubuko.com,布布扣

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删除记录的例子:

bubuko.com,布布扣
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;
bubuko.com,布布扣

 

WHERE CURRENT OF,布布扣,bubuko.com

WHERE CURRENT OF

原文:http://www.cnblogs.com/nuaa/p/3749861.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!