zoukankan      html  css  js  c++  java
  • 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;
     
    文章出处:http://www.diybl.com/course/7_databases/oracle/2007114/84247.html

  • 相关阅读:
    作为一名JAVA程序员应该有怎样的就业思维
    Html +++++css总结
    spring知识点全部复习
    Spring注解问题,[action中注入service失败
    VMware中Ubuntu18配置静态IP地址
    MySQL5.7修改登录密码的几种方式
    MySQL忘记root密码
    Windows安装Redis
    Java两个整数相除保留n位小数
    Java四舍五入保留n位小数的常用写法
  • 原文地址:https://www.cnblogs.com/jimeper/p/1389535.html
Copyright © 2011-2022 走看看