zoukankan      html  css  js  c++  java
  • PL/SQL 05 存储过程 procedure

    --存储过程(不带参数)

    create or replace procedure 存储过程名
    as
      变量、常量声明;
    begin
      代码;
    end;


    --存储过程(带输入参数)

    create or replace procedure 存储过程名(参数1 类型,参数2 类型,...)   --可以设默认值,如low int:=1000
    as
      变量、常量声明;
    begin
      代码;
    end;


    --存储过程(带输出参数)

    create or replace procedure 存储过程名(参数1 out 类型,参数2 类型,...)   --如avgscore out stu.score%type
    as
      变量、常量声明;
    begin
      代码;
    end;


    --存储过程内部返回用 return;


    --存储过程和游标配合使用

    create or replace procedure  test1(j emp.job%type)
    as
      cursor test
      is select empno,ename from emp where job=j;
      eno emp.empno%type;
      ena emp.ename%type;
    begin
      open test;
      loop
        fetch test into eno,ena;
        exit when test%notfound;
         dbms_output.put_line(eno||' '||ena);
      end loop;
      close test;
    end;


    --例子 常量加前缀v_  参数加前缀p_ (不要和表字段一样,会出问题)
    create or replace procedure
      pro_test(p_stuno varchar2)
    as
      v_score number(3);
      cursor cur_test is
      select sco.score from score sco 
      where sco.stuno=p_stuno;
    begin
      open cur_test;
      loop
      fetch cur_test into v_score;
      exit when cur_test%notfound;
      dbms_output.put_line(p_stuno|| ' score is: '||v_score);
      end loop;
      close cur_test;
    end;


    --调用存储过程
    begin
      pro_test('stu001');
    end;

  • 相关阅读:
    == Equals ReferenceEquals 比较
    数据库 数据类型
    C# 判断路径和文件存在
    OpenXml 2.0 读取Excel
    excel2003, 2007最大行列、sheet数
    将List中部分字段转换为DataTable中
    X64位PC上dsoframer兼容性问题
    winform 客户端 HTTP协议与服务端通信以及解决中文乱码
    VIsual Studio 2010 常用快捷键
    Web Pages(单页面模型)
  • 原文地址:https://www.cnblogs.com/john2017/p/6364505.html
Copyright © 2011-2022 走看看