zoukankan      html  css  js  c++  java
  • Oracle 存储过程,临时表,动态SQL测试

    --创建事务级别的结果临时表
    create global temporary table tmp_yshy(
     c1 varchar2(100),
     c2 varchar2(100)
    )on commit delete rows;
    --创建事务级别的存储sql语句的临时表
    create global temporary table tmp_sql(
     c1 varchar2(4000)
    )on commit delete rows;

    测试表:

    -- Create table
    create table T_USER
    (
      NAME VARCHAR2(20),
      AGE  NUMBER
    )
    --首先建包
    create or replace package pack_user 
    as
      -- 1:根据年龄查询所有用户
      procedure p_user_select(
        av_age        number,        --年龄
        av_suc out    varchar2       --是否成功标识  
      );
    
    end pack_user;
    --创建包体
    create or replace package body pack_user
    as
     --1:根据年龄查询所有用户
     procedure p_user_select(
       av_age         number,
       av_suc out     varchar2
     )
     as
       lv_sql         varchar2(4000);
     begin
       av_suc:='T';
       
       lv_sql:=' insert into tmp_yshy(c1,c2) '||
               ' select name,age '||
               ' from t_user '||
               ' where age >'||av_age;
       
       insert into tmp_sql(c1) values(lv_sql||';');
       
       execute immediate lv_sql;
       
       exception 
         when others then
           rollback;
           av_suc:='F'||' '||to_char(sqlcode)||' : '||sqlerrm;
           dbms_output.put_line(av_suc);
     end p_user_select;
     
    end pack_user;

    PL/SQL Developer SQLWindow测试:

     declare 
        a varchar2(100);
     begin 
        pack_user.p_user_select(25,a);
     end;
    select * from tmp_yshy;
    select * from tmp_sql;
  • 相关阅读:
    2019.1.8兔子问题和汉诺塔问题的解决代码
    REST
    存储过程和函数练习
    十六、性能优化
    十五、MySQl日志
    Shell入门
    十四、数据备份
    十三、MySQL触发器
    十二、视图
    十一、MySQL锁
  • 原文地址:https://www.cnblogs.com/yshyee/p/4392328.html
Copyright © 2011-2022 走看看