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;

  • 相关阅读:
    python刷新七牛云CDN缓存
    python 操作redis
    redis 设置密码
    redis 允许其他机器连接设置方法
    redis持久化
    redis操作
    redis简介及与memcached比较
    dataframe 处理某列的小数位数并加特殊符号
    django 生成和下载CSV文件
    django 重定向
  • 原文地址:https://www.cnblogs.com/john2017/p/6364505.html
Copyright © 2011-2022 走看看