一. 存储过程

  1. 语法

create or replace procedure procedureName(seqName varchar2)
is
    /*声明变量*/
    n number(10);
    cursor cur is select * from tableName;
    /*用来放置游标中的一行*/
    cRow cur%rowtype;

begin
    /*变量赋值*/
    n := 5;

    /*循环方式一*/
    for i in 1..n loop
        /*做点什么*/
    end loop;

    /*循环方式二*/
    loop
        exit when n = 0;
        n := n - 1;
    end loop;
    
    /*循环方式三*/
    while i < n loop
        exit;
    end loop;
    
    /*游标用法一:隐式打开和关闭*/
    for c in cur loop
        /*做点什么*/
    end loop;

    /*游标用法一:显式打开和关闭*/
    open cur;
    loop
        fetch cur into cRow;
        exit when cur%notfound;
    end loop;
    close cur;

    /*修改游标的所在行*/
    update tableName set columnName=columnValue where current of cur;

    /*判断*/
    if (n = 0) then
        /*动态执行sql语句*/
        execute immediate 'select '||seqName||'.nextval from dual' into n;
    else
        /*控制台输出*/
        dbms_output.put_line(n);
    end if;

    commit;
end procedureName;
View Code

相关文章:

  • 2021-09-18
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2022-01-07
  • 2019-03-24
  • 2021-11-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案