ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 编写存储过程基本注意事项

编写存储过程基本注意事项

原创 Linux操作系统 作者:mahanso 时间:2010-12-15 14:30:22 0 删除 编辑
     今天同事用到的临时表,遇到些问题,我们一起复习了一下临时表用法和编写存储过程中一些基础注意事项和写法,现在总结一下:

     1、临时表建立(临时具体信息参考:http://space.itpub.net/12272958/viewspace-681831)
-- 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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-10-18

  • 博文量
    160
  • 访问量
    641047