zoukankan      html  css  js  c++  java
  • 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;



























  • 相关阅读:
    解决:Requested 'libdrm_radeon >= 2.4.56' but version of libdrm_radeon is 2.4.52
    解决Ubuntun 12.04编译Mesa10.3 WARNING: 'aclocal-1.14' is missing on your system
    交叉编译Mesa,X11lib,Qt opengl
    Qt5.4.1移植到arm——Linuxfb篇
    Qt5.3.0的安装与测试
    gstreamer——文档/资源/使用
    gst-rtsp-server编译测试
    gstreamer-tips-picture-in-picture-compositing
    Matlab实现加性高斯白噪声信道(AWGN)下的digital调制格式识别分类
    Matlab实现单(双)极性(不)归零码
  • 原文地址:https://www.cnblogs.com/kexb/p/4460531.html
Copyright © 2011-2022 走看看