• oracle 游标的使用


    create or replace procedure P_TRAN_SIMULATION1
    (
     v_ComputeDate1 in date,
     v_ComputeDate2 in date
    )
    /* Oracle:Authid Current_User的使用

     我们知道,用户拥有的role权限在存储过程是不可用的。遇到这种情况,我们一般需要显式授权,
     如grant create table to usera;但这种方法太麻烦,有时候可能需要进行非常多的授权才能执行存储过程,
     实际上,oracle给我们提供了在存储过程中使用role权限的方法:修改存储过程,加入Authid Current_User时存储过程可以使用role权限。下面来举个例子: */
    authid current_user
     is vn_ctn number(2);
    begin

      select count(*) into vn_ctn from user_all_tables a where a.table_name like upper('tbl');
       if vn_ctn > 0 then
          execute immediate 'drop table tbl';  
       end if;
       execute immediate 'create table tbl(id1 number,id2 number)';    
       COMMIT;
       
    declare cashflowPOSITIVE NUMBER:=0;
          cashflowNEGATIVE NUMBER:=0;
          cursor mycur is
          select *
          from TRAN_CASH_FLOW
          where as_of_date = v_ComputeDate1
          and payment_date >=v_ComputeDate1
          and payment_date < v_ComputeDate2;
          cashFlowRow TRAN_CASH_FLOW%rowtype;
    begin     
      open mycur; --打开游标
         loop
             fetch mycur into cashFlowRow; --把游标所指的纪录放到变量中
             exit  when (mycur%notfound); --当游标没有指向行时退出循环
             if cashFlowRow.cashflow_value>0 then
               cashflowPOSITIVE:=cashflowPOSITIVE+cashFlowRow.cashflow_value;
               else
                 cashflowNEGATIVE:=cashflowNEGATIVE+cashFlowRow.cashflow_value;
                 end if;
         end loop;
    dbms_output.put_line(cashflowPOSITIVE);
        
         close mycur;  --关闭游标

    /*  insert into tbl values(cashflowPOSITIVE,cashflowNEGATIVE);*/

    end;

    end P_TRAN_SIMULATION1;



























  • 相关阅读:
    向量求导几则公式备忘
    电脑硬件接触不良
    caffe编译新问题
    faster-rcnn 目标检测 数据集制作
    py-faster-rcnn 的makefile.config 注意事项
    ubuntu14.04 python + opencv 傻瓜式安装解决方案
    轻量级神经网络平台tiny-dnn实践
    OpenMP 并行编程
    React在Render中使用bind可能导致的问题
    为了cider,尝试emacs的坑
  • 原文地址:https://www.cnblogs.com/kexb/p/4460531.html
Copyright © 2020-2023  润新知