--创建事务级别的结果临时表 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;
时间: 2024-11-12 09:50:41