`
guilin20
  • 浏览: 10129 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

oracle 存储过程一例

阅读更多
留个备忘,以备将来参考

create or replace procedure GET_ALM_NDS_DD is

  par_last_run_date fm_system.last_run_date%TYPE;

  p_ccy                 rb_acct.ccy%TYPE;
  p_branch              rb_acct.branch%TYPE;
  p_cur_net_rate        alm_nds_dd.cur_net_rate%TYPE;
  p_cr_int_type         alm_nds_dd.cr_int_type%TYPE;
  p_dr_int_type         alm_nds_dd.dr_int_type%TYPE;
  p_prev_day_actual_bal rb_acct.prev_day_actual_bal%TYPE;
  p_internal_key        rb_acct.internal_key%TYPE;
  v_num                 number := 0;
  v_actual_rate         number := 0;
  v_balance             number := 0;

  CURSOR cur IS
    SELECT ccy, branch, cr_int_type, dr_int_type from T_TEMP;

  CURSOR cur_nds IS
    SELECT branch,
           currency_cd,
           cr_int_type,
           dr_int_type,
           nds_cur_book_bal,
           nds_id_number
      from alm_nds_dd
     where alm_nds_dd.rate_ladder = 'S';

  CURSOR cur_rate IS
    SELECT DISTINCT fbv.branch,
                    fbv.int_type,
                    fbv.ccy,
                    fbv.effect_date,
                    fbv.balance as balance,
                    fbv.min_rate,
                    fbv.max_rate,
                    fbv.day_basis,
                    (NVL(fbv.actual_rate, 0) + NVL(fiv.variance_rate, 0)) actual_rate,
                    NVL(fiv.var_effect_date, fbv.effect_date) var_effect_date
      FROM (SELECT fb.branch,
                   fit.int_type,
                   fir.ccy,
                   fir.effect_date,
                   fir.balance,
                   fir.min_rate,
                   fir.max_rate,
                   fir.day_basis,
                   NVL(fir.actual_rate, 0) actual_rate
              FROM fm_int_rate fir, fm_int_type fit, fm_branch_tbl fb
             WHERE fir.int_type = fit.int_type
               AND fir.status = 'A'
               AND fb.branch = p_branch
               AND fb.tran_br_ind = 'Y'
               AND fir.ccy = p_ccy
               AND fir.int_type IN (p_cr_int_type, p_dr_int_type)) fbv,
           (SELECT kiv.branch,
                   kiv.variance_rate,
                   kiv.effect_date,
                   kiv.ccy,
                   kiv.int_type,
                   kiv.balance,
                   kiv.var_effect_date
              FROM fm_int_variance kiv, fm_int_rate kir
             WHERE kiv.int_type = kir.int_type
               AND kiv.ccy = kir.ccy
               AND kiv.effect_date = kir.effect_date
               AND kiv.balance = kir.balance
               AND kiv.status = 'A'
               AND kir.status = 'A'
               AND kiv.branch = p_branch
               AND kir.int_type IN (p_cr_int_type, p_dr_int_type)
               AND kir.ccy = p_ccy) fiv
     WHERE fbv.branch = fiv.branch
       AND fbv.int_type = fiv.int_type
       AND fbv.balance = fiv.balance
       AND fbv.ccy = fiv.ccy
       AND fbv.effect_date = fiv.effect_date(+)
       AND ROWNUM = 1
     ORDER BY fbv.branch,
              fbv.int_type,
              fbv.ccy,
              fbv.effect_date DESC,
              fbv.balance;

  CURSOR cur_rate_s IS
 
    SELECT ff.balance, ff.actual_rate
      FROM (
           
            SELECT DISTINCT rownum as row_num,
                             fbv.branch,
                             fbv.int_type,
                             fbv.ccy,
                             fbv.effect_date,
                             fbv.balance as balance,
                             fbv.min_rate,
                             fbv.max_rate,
                             fbv.day_basis,
                             (NVL(fbv.actual_rate, 0) +
                             NVL(fiv.variance_rate, 0)) actual_rate,
                             NVL(fiv.var_effect_date, fbv.effect_date) var_effect_date
              FROM (SELECT fb.branch,
                            fit.int_type,
                            fir.ccy,
                            fir.effect_date,
                            fir.balance,
                            fir.min_rate,
                            fir.max_rate,
                            fir.day_basis,
                            NVL(fir.actual_rate, 0) actual_rate
                       FROM fm_int_rate fir, fm_int_type fit, fm_branch_tbl fb
                      WHERE fir.int_type = fit.int_type
                        AND fir.status = 'A'
                        AND fb.branch = p_branch
                        AND fb.tran_br_ind = 'Y'
                        AND fir.ccy = p_ccy
                        AND fir.int_type IN (p_cr_int_type, p_dr_int_type)) fbv,
                    (SELECT kiv.branch,
                            kiv.variance_rate,
                            kiv.effect_date,
                            kiv.ccy,
                            kiv.int_type,
                            kiv.balance,
                            kiv.var_effect_date
                       FROM fm_int_variance kiv, fm_int_rate kir
                      WHERE kiv.int_type = kir.int_type
                        AND kiv.ccy = kir.ccy
                        AND kiv.effect_date = kir.effect_date
                        AND kiv.balance = kir.balance
                        AND kiv.status = 'A'
                        AND kir.status = 'A'
                        AND kiv.branch = p_branch
                        AND kir.int_type IN (p_cr_int_type, p_dr_int_type)
                        AND kir.ccy = p_ccy) fiv
             WHERE fbv.branch = fiv.branch
               AND fbv.int_type = fiv.int_type
               AND fbv.balance = fiv.balance
               AND fbv.ccy = fiv.ccy
               AND fbv.effect_date = fiv.effect_date(+)
             ORDER BY fbv.branch,
                       fbv.int_type,
                       fbv.ccy,
                       fbv.effect_date DESC,
                       fbv.balance) ff
     where ff.row_num < 3;

begin
  EXECUTE IMMEDIATE 'truncate   table   alm_nds_dd';
  EXECUTE IMMEDIATE 'truncate table t_temp';

  select fs.last_run_date into par_last_run_date from fm_system fs;

  INSERT INTO alm_nds_dd
    (fms_product_id,
     --     fms_gl_account_id,
     fms_org_unit_id,
     nds_id_number,
     --     nds_as_of_dt,
     nds_cur_book_bal,
     accrual_basis_cd,
     adjustable_type_cd,
     --     cur_net_rate,
     currency_cd,
     cif_key,
     cif_type,
     cif_sub_type,
     branch,
     acct_type)
 
    SELECT fpm.global_product_id,
           --           '2待定',
           fb.cny_business_unit,
           ra.internal_key,
           --           fs.last_run_date,
           ABS(ra.prev_day_actual_bal),
           DECODE(fc.day_basis, 360, 2, 365, 6, 2),
           50,
           --           '9待定',
           ra.ccy,
           ra.client_no,
           ra.client_type,
           fmc.class_4,
           ra.branch,
           ra.acct_type
      FROM rb_acct            ra,
           fm_product_mapping fpm,
           fm_branch_tbl      fb,
           --           fm_system          fs,
           fm_currency fc,
           fm_client   fmc
     WHERE ra.deposit_type <> 'T'
       AND ra.prev_day_actual_bal < 0
       AND ra.acct_status <> 'C'
       AND fpm.product_type = ra.acct_type
       AND ra.branch = fb.branch
       AND fc.ccy = ra.ccy
       AND ra.client_no = fmc.client_no
       AND fb.tran_br_ind = 'Y';
  commit;

  --update 'nds_as_of_dt'
  update alm_nds_dd
     set nds_as_of_dt = to_char(par_last_run_date, 'YYYYMMDD');

  --update 'fms_gl_account_id' when fms is exist
  update alm_nds_dd a
     set a.fms_gl_account_id = (select c.nas_gl_code
                                  from rb_acct_type b, fm_da_glcode_mapping c
                                 where a.acct_type = b.acct_type
                                   AND b.gl_code_l = c.nds_gl_code
                                   AND a.cif_key = c.client_no
                                   AND a.branch = c.branch);

  --update 'fms_gl_account_id' when fms is not exist, get nds
  update alm_nds_dd a
     set a.fms_gl_account_id = (select b. gl_code_l
                                  from rb_acct_type b
                                 where a.acct_type = b.acct_type
                                   AND a.fms_gl_account_id is null)
   where a.fms_gl_account_id is null;

  --update 'CR_INT_TYPE','DR_INT_TYPE'
  update alm_nds_dd a
     set a.cr_int_type = (select cr_int_type
                            from rb_prod_default rpd
                           where a.acct_type = rpd.acct_type);

  update alm_nds_dd a
     set a.dr_int_type = (select dr_int_type
                            from rb_prod_default rpd
                           where a.acct_type = rpd.acct_type);

  --update 'rate_ladder'
  update alm_nds_dd a
     set a.rate_ladder = (select c.rate_ladder
                            from rb_int_detail b, fm_int_type c
                           where a.nds_id_number = b.internal_key
                             AND b.cr_int_type = c.int_type);

  --get the   cur_net_rate when the rate_ladder <>'s'
  --execute immediate 'CREATE GLOBAL TEMPORARY TABLE T_TEMP (
  --     ccy VARCHAR2(3),        
  --     branch VARCHAR2(6),
  --     cr_int_type VARCHAR2(3),
  --     dr_int_type VARCHAR2(3)
  --    
  --) ON COMMIT PRESERVE ROWS';

  INSERT INTO T_TEMP
    (ccy, branch, cr_int_type, dr_int_type)
    select distinct a.currency_cd, a.branch, a.cr_int_type, a.dr_int_type
      from alm_nds_dd a;

  For tmp_cur in cur loop
    p_ccy         := tmp_cur.ccy;
    p_branch      := tmp_cur.branch;
    p_cr_int_type := tmp_cur.cr_int_type;
    p_dr_int_type := tmp_cur.dr_int_type;
 
    for tmp_cur_rate in cur_rate loop
      p_cur_net_rate := tmp_cur_rate.actual_rate;
   
      update alm_nds_dd a
         set a.cur_net_rate = p_cur_net_rate
       where a.currency_cd = p_ccy
         and a.branch = p_branch
         and a.cr_int_type = p_cr_int_type
         and a.dr_int_type = p_dr_int_type
         and a.rate_ladder <> 'S'
         and p_cur_net_rate >= 0;
   
    END LOOP;
 
  END LOOP;

  For tmp_cur_nds in cur_nds loop
    p_ccy                 := tmp_cur_nds.currency_cd;
    p_branch              := tmp_cur_nds.branch;
    p_cr_int_type         := tmp_cur_nds.cr_int_type;
    p_dr_int_type         := tmp_cur_nds.dr_int_type;
    p_prev_day_actual_bal := tmp_cur_nds.nds_cur_book_bal;
    p_internal_key        := tmp_cur_nds.nds_id_number;
 
    For i in cur_rate_s loop
      If v_balance <> 0 then
        If p_prev_day_actual_bal <= v_balance then
          v_num := p_prev_day_actual_bal * v_actual_rate;
          Exit;
        ELSE
          v_num := (p_prev_day_actual_bal - v_balance) * i.
                   actual_rate + v_balance * v_actual_rate;
        END IF;
      END IF;
      v_balance     := i.balance;
      v_actual_rate := i.actual_rate;
    END LOOP;
 
    p_cur_net_rate := v_num / p_prev_day_actual_bal;
 
    update alm_nds_dd a
       set a.cur_net_rate = p_cur_net_rate
     where a.currency_cd = p_ccy
       and a.branch = p_branch
       and a.cr_int_type = p_cr_int_type
       and a.dr_int_type = p_dr_int_type
       and a.rate_ladder = 'S';
 
  END LOOP;

end GET_ALM_NDS_DD;
分享到:
评论

相关推荐

    oracle存储过程编译

    在本例中,我们将讨论如何使用 Oracle 存储过程编译,特别是使用 PL/SQL 语言编写的存储过程。 标题:Oracle 存储过程编译 描述:Oracle 存储过程编译 标签:Oracle 部分内容: 在上面的代码中,我们定义了一个...

    Oracle存储过程、游标、函数的详解

    通过以上对Oracle存储过程、游标和函数的详细介绍,我们可以看到这些特性为Oracle数据库提供了一种强大而灵活的方式来处理数据。掌握这些技术对于开发高效的应用程序至关重要。在未来的学习和实践中,我们应该不断...

    *oracle存储过程总结*oracle存储过程总结*

    根据提供的文件信息,我们可以归纳出以下Oracle存储过程的相关知识点: ### Oracle存储过程基础概念 - **存储过程**:是在数据库中存储的一组SQL语句和控制流语句的集合,可以接受输入参数、返回单个值、返回多个...

    oracle 存储过程语法例子

    在本例中,我们看到两个具体的存储过程`writeCount`和`testSandyInSert`,它们展示了如何创建和使用Oracle存储过程。 1. 创建包(Package): 在Oracle中,存储过程通常被组织到包(Package)中,以便更好地管理和...

    ibatis调用oracle存储过程

    在IT领域,特别是数据库操作与Java开发中,利用ibatis框架调用Oracle存储过程是一个常见的需求,这不仅能够提升代码的执行效率,还能增强应用程序的安全性。本文将深入解析ibatis如何与Oracle数据库中的存储过程进行...

    Oracle存储过程实例使用显示游标

    在本例中,“Oracle存储过程实例使用显示游标”着重展示了如何在存储过程中调用函数,并通过游标来处理和更新数据。 首先,我们需要了解存储过程的基本结构。一个存储过程通常包含以下部分: 1. **声明部分**:在...

    java调用oracle存储过程入门实例 增删改查

    在Java中调用Oracle存储过程,我们需要使用JDBC(Java Database Connectivity),这是Java标准库提供的一组接口和类,用于与各种数据库进行通信。首先,我们需要添加Oracle JDBC驱动到项目中,例如ojdbc.jar。 1. *...

    JAVA调用ORACLE存储过程

    ### JAVA调用ORACLE存储过程知识点详解 #### 一、背景与概述 在现代软件开发过程中,集成多种技术栈是常态。特别是在企业级应用中,Java 和 Oracle 数据库的组合非常常见。通过 Java 调用 Oracle 存储过程不仅能够...

    oracle数组存储过程批量插入

    在本例中,我们探讨了如何使用数组存储过程进行批量插入和删除。数组在Oracle中的使用通常涉及定义PL/SQL类型,这允许我们创建索引数组以存储特定数据类型。 首先,我们创建一个名为`MSGPAG`的包,其中定义了一个名...

    oracle存储过程详细介绍

    Oracle存储过程是数据库管理系统Oracle中的一个重要特性,它允许开发者编写一系列复杂的SQL和PL/SQL语句,形成可重用的代码块。存储过程在数据库中预先编译,提高了执行效率,降低了网络通信量,同时也提供了更好的...

    Oracle 分页的存储过程

    Oracle 分页存储过程是数据库管理中的一个重要概念,它允许用户以特定的页面大小获取数据,而不是一次性获取所有数据,这有助于提高性能并减轻服务器负担。在Oracle中,可以通过创建存储过程来实现这一功能,尤其在...

    Oracle第7章存储过程操作.pptx

    Oracle数据库是企业级广泛使用的数据库管理系统,其强大的功能之一就是支持存储过程的创建、管理和使用。存储过程是一组为了完成特定任务而预编译的SQL语句集合,它可以提高应用程序的性能和效率,同时减少网络流量...

    根据生日获取年龄及年龄单位的oracle存储过程

    在本例中,我们关注的是一个名为“根据生日获取年龄及年龄单位的oracle存储过程”的功能,它的主要任务是计算输入日期(生日)对应的人物的年龄,并返回年龄值及其单位。这样的存储过程在处理用户信息、数据分析或...

    Oracle存储过程应用实例

    本节以一个具体的GPS车辆监控系统为例,介绍如何在Visual C++开发环境下,使用ADO技术调用Oracle存储过程。 ##### 1. 开发环境与工具 本案例基于Visual C++ 6.0开发平台,利用ADO(ActiveX Data Object)技术实现...

    oracle 存储过程.pptx

    总之,Oracle存储过程是数据库开发中的关键组件,它们提供了结构化的方法来组织和执行复杂的数据库操作,同时提高了系统的安全性和性能。正确地设计和使用存储过程能够极大地提升数据库应用的效率和质量。

    oracle 自动执行存储过程

    ### Oracle自动执行存储过程 #### 一、背景与需求 在很多实际应用场景中,我们可能会遇到需要定时执行某些任务的情况,比如数据清理、备份、统计分析等。在Oracle数据库环境中,可以通过创建定时任务来实现对特定...

    java调用oracle存储过程

    首先,我们需要理解Oracle存储过程的概念。存储过程是预编译在数据库服务器上的SQL和PL/SQL代码集合,可以接收参数,执行特定任务并返回结果。调用存储过程可以提高性能,减少网络流量,并封装业务逻辑。 在Java中...

    Mybatis传list参数调用oracle存储过程的解决方法

    但是,如何将List类型参数传递给Oracle存储过程,实现批量插入数据却是一个棘手的问题,本文将给大家介绍Mybatis传List参数调用Oracle存储过程的解决方法。 使用Mybatis传List参数调用Oracle存储过程的解决方法 在...

    oracle存储过程

    ### Oracle存储过程详解 在Oracle数据库管理中,存储过程是一种重要的数据库对象,它允许开发者将一组SQL和PL/SQL语句封装在一起,作为单一单元在数据库服务器上存储和执行。这种封装不仅提高了代码的重用性和维护...

Global site tag (gtag.js) - Google Analytics