今天同事用到的临时表,遇到些问题,我们一起复习了一下临时表用法和编写存储过程中一些基础注意事项和写法,现在总结一下:
-- Create table
create global temporary table TRADE_WAIT_DELIVERY_TMP
(
POSITION_ACCOUNT VARCHAR2(32) not null,
GOODS_CODE VARCHAR2(50) not null,
QUANTITY NUMBER(12) not null,
APPLY_QUANTITY NUMBER(12)
)
on commit delete rows;
2、测试临时表的存储过程
create or replace procedure mahanso_tmptable(current_trade_date in VARCHAR2,o_cur out sys_refcursor) as
begin
--插入临时表中数据
insert into trade_wait_delivery_tmp
select position_account,
goods_code,
sum(Func_Position_Direction(fashion) * num_net) as quantity,
apply_quantity
from position_total p
group by position_account, goods_code;
open o_cur for
select * from trade_wait_delivery_tmp;
end mahanso_tmptable;
3、输出查询信息
SQL> declare
2 POSITION_ACCOUNT VARCHAR2(32);
3 GOODS_CODE VARCHAR2(50);
4 QUANTITY NUMBER(12);
5 APPLY_QUANTITY NUMBER(12);
6 o_cur sys_refcursor;
7 begin
8 mahanso_tmptable(sysdate,o_cur);
9 fetch o_cur into POSITION_ACCOUNT,GOODS_CODE,QUANTITY,APPLY_QUANTITY;
10 while o_cur%found loop
11 dbms_output.put_line('输出结果:'||POSITION_ACCOUNT||','||GOODS_CODE||','||QUANTITY||','||APPLY_QUANTITY);
12 fetch o_cur into POSITION_ACCOUNT,GOODS_CODE,QUANTITY,APPLY_QUANTITY;
13 end loop;
14 commit;
15 end;
16 /
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12272958/viewspace-681904/
,如需转载,请注明出处,否则将追究法律责任。