• oracle数据库中的存储过程


    存储过程是一组为了完成特定功能的sql语句集,是一段sql代码片段,经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数(如果存储过程存在参就给出,不存在就不用给出参数)来执行它。因为它是一段sql语句代码并且已经编译好了存放在数据库中,所以它的执行效率非常高。

    存储过程的创建如下:

        create [or replace] procedure 过程名 [(参数名 in|out 数据类型)]
        as|is
          变量的声明
        begin
          plsql的子程序体;
        end;//如果是is,end 后面要加上过程名。

    存储过程的调用

      第一种:call 存储过程名(参数);

      第二种:begin

             存储过程名(参数);

          end;

    例如1:给指定的员工涨工资100,并打印出涨前和涨后的工资

    创建存储过程:

        create or replace procedure addsal(eno in number) is

          pemp emp%rowtype;
        begin
          select * into pemp from emp where empno = eno;
          update emp set sal = sal + 100 where empno = eno;
          dbms_output.put_line('ename:' || pemp.ename || 'after' || (pemp.sal+100));
        end addsal;

    调用存储过程:

        第一种调用:call addsal(7369);

        第二种调用:

          begin
            addsal(eno=>7369);
            commit;//因为oracle数据库是手动提交的,所有涉及到的增删改都必须commit;
          end;

    例如2:输出所有员工的姓名和工资

    创建存储过程:

        create or replace procedure infoemp as
          cursor allemp is
            select * from emp;//创建一个游标
          enemp emp%rowtype;
        begin
          open allemp;
          loop
            fetch allemp
              into enemp;//利用循环从游标中取数据
            dbms_output.put_line(enemp.ename || ' '||enemp.sal);
          exit when allemp%notfound;//退出循环条件
          end loop;
          close allemp;
        end;

    调用存储过程:

    第一种: call infoemp();

    第二种: begin
          infoemp();
        end;

    以上就是oracle数据库的存储过程的基本知识和用法。

  • 相关阅读:
    SQL Server 触发器
    T-SQL查询进阶-10分钟理解游标
    有关T-SQL的10个好习惯
    iOS 画虚线以及drawRect的使用总结:
    iOS一个for循环实现,几行 几列 的布局形式
    IOS 符合某类型的子视图批量从父视图中移除
    DESC 和 ASC
    把数组格式数据转换成字符串存入数据库
    Swift :?和 !
    Swift 类构造器的使用
  • 原文地址:https://www.cnblogs.com/jasonboren/p/10944704.html
Copyright © 2020-2023  润新知