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;



























  • 相关阅读:
    kmp 算法
    jdk 和 cglib 的动态代理
    RestTemplate工具类
    bat脚本切换多个工程的分支
    字符串的左旋转
    输入一个正数s,打印出所有和为s的连续正数序列(至少含有两个数)。例如输入15,由于1+2+3+4+5=4+5+6=7+8=15,所以结果打印出3个连续序列1~5、4~6和7~8。
    枚举类型在JPA中的使用
    拾遗
    YAML DEMO
    kiali 1.26 anonymous策略修改为token
  • 原文地址:https://www.cnblogs.com/kexb/p/4460531.html
Copyright © 2011-2022 走看看