IT忍者神龟之oracle存储过程简单从ODS抽取数据_面向对象思想

第一步:创建包接口类似java中的接口定义

create or replace
PACKAGE pack_sc_hmd_kh
IS
 --方法的声明
  PROCEDURE proc_hmd_kh(
      p_y VARCHAR2,
      p_m VARCHAR2,
      p_d VARCHAR2);

END pack_sc_hmd_kh;

第二步:常见包体又称包的实现类似于java中实现接口的具体类

create or replace 
PACKAGE body pack_sc_hmd_kh
IS
PROCEDURE proc_hmd_kh(
    p_y IN VARCHAR2 ,
    p_m IN VARCHAR2 ,
    p_d IN VARCHAR2)
IS
  CURSOR cis_sc_hmd_kh_cursor
  IS
    SELECT
      d_sems_rel_d_ddpa_appl_list.fact_date,
      d_sems_rel_d_ddpa_appl_list.apply_id,
      d_sems_rel_d_ddpa_appl_list.marketing_org,
      d_sems_rel_d_ddpa_appl_list.open_org,
      d_sems_rel_d_ddpa_appl_list.open_branch,
      d_sems_rel_d_ddpa_appl_list.open_area,
      d_sems_rel_d_ddpa_appl_list.cust_mgr,
      d_sems_rel_d_ddpa_appl_list.channel_type,
      d_sems_rel_d_ddpa_appl_list.cust_id,
      d_sems_rel_d_ddpa_appl_list.cert_no,
      d_sems_rel_d_ddpa_appl_list.cust_name,
      d_sems_rel_d_ddpa_appl_list.birthday,
      d_sems_rel_d_ddpa_appl_list.edu_grade,
      d_sems_rel_d_ddpa_appl_list.industry_name,
      d_sems_rel_d_ddpa_appl_list.bussiness_type,
      d_sems_rel_d_ddpa_appl_list.scheme_id,
      d_sems_rel_d_ddpa_appl_list.project_name,
      d_sems_rel_d_ddpa_appl_list.apply_amount,
      d_sems_rel_d_ddpa_appl_list.apply_date,
      d_sems_rel_d_ddpa_appl_list.term,
      d_sems_rel_d_ddpa_appl_list.loan_purpose,
      d_sems_rel_d_ddpa_appl_list.guaranty_type,
      d_sems_rel_d_ddpa_appl_list.return_card_no,
      d_sems_rel_d_ddpa_appl_list.final_approve_date,
      d_sems_rel_d_ddpa_appl_list.final_approve_user,
      d_sems_rel_d_ddpa_appl_list.final_approve_result,
      d_sems_rel_d_ddpa_appl_list.credit_result,
      d_sems_rel_d_ddpa_appl_list.comprehensive_mark,
      d_sems_rel_d_ddpa_appl_list.quarlity_check_time,
      d_sems_rel_d_ddpa_appl_list.credit_time,
      d_sems_rel_d_ddpa_appl_list.approve_time,
      d_sems_rel_d_ddpa_appl_list.return_num,
      d_sems_rel_d_ddpa_appl_list.return_time,
      d_sems_rel_d_ddpa_appl_list.contract_no,
      d_sems_rel_d_ddpa_appl_list.inputchannel,
      d_sems_rel_d_ddpa_appl_list.contract_amount,
      d_sems_rel_d_ddpa_appl_list.inputchannel_name
    FROM
      d_sems_rel_d_ddpa_appl_list
    WHERE
      fact_date=to_date(p_y
      || '-'
      || p_m
      || '-'
      || p_d, 'yyyy-mm-dd');
  v_fact_date cis_sc_hmd_kh.fact_date%TYPE;
  v_apply_id cis_sc_hmd_kh.apply_id%TYPE;
  v_marketing_org cis_sc_hmd_kh.marketing_org%TYPE;
  v_open_org cis_sc_hmd_kh.open_org%TYPE;
  v_open_branch cis_sc_hmd_kh.open_branch%TYPE;
  v_open_area cis_sc_hmd_kh.open_area%TYPE;
  v_cust_mgr cis_sc_hmd_kh.cust_mgr%TYPE;
  v_channel_type cis_sc_hmd_kh.channel_type%TYPE;
  v_cust_id cis_sc_hmd_kh.cust_id%TYPE;
  v_cert_no cis_sc_hmd_kh.cert_no%TYPE;
  v_cust_name cis_sc_hmd_kh.cust_name%TYPE;
  v_birthday cis_sc_hmd_kh.birthday%TYPE;
  v_edu_grade cis_sc_hmd_kh.edu_grade%TYPE;
  v_industry_name cis_sc_hmd_kh.industry_name%TYPE;
  v_bussiness_type cis_sc_hmd_kh.bussiness_type%TYPE;
  v_scheme_id cis_sc_hmd_kh.scheme_id%TYPE;
  v_project_name cis_sc_hmd_kh.project_name%TYPE;
  v_apply_amount cis_sc_hmd_kh.apply_amount%TYPE;
  v_apply_date cis_sc_hmd_kh.apply_date%TYPE;
  v_term cis_sc_hmd_kh.term%TYPE;
  v_loan_purpose cis_sc_hmd_kh.loan_purpose%TYPE;
  v_guaranty_type cis_sc_hmd_kh.guaranty_type%TYPE;
  v_return_card_no cis_sc_hmd_kh.return_card_no%TYPE;
  v_final_approve_date cis_sc_hmd_kh.final_approve_date%TYPE;
  v_final_approve_user cis_sc_hmd_kh.final_approve_user%TYPE;
  v_final_approve_result cis_sc_hmd_kh.final_approve_result%TYPE;
  v_credit_result cis_sc_hmd_kh.credit_result%TYPE;
  v_comprehensive_mark cis_sc_hmd_kh.comprehensive_mark%TYPE;
  v_quarlity_check_time cis_sc_hmd_kh.quarlity_check_time%TYPE;
  v_credit_time cis_sc_hmd_kh.credit_time%TYPE;
  v_approve_time cis_sc_hmd_kh.approve_time%TYPE;
  v_return_num cis_sc_hmd_kh.return_num%TYPE;
  v_return_time cis_sc_hmd_kh.return_time%TYPE;
  v_contract_no cis_sc_hmd_kh.contract_no%TYPE;
  v_inputchannel cis_sc_hmd_kh.inputchannel%TYPE;
  v_contract_amount cis_sc_hmd_kh.contract_amount%TYPE;
  v_inputchannel_name cis_sc_hmd_kh.inputchannel_name%TYPE;
  v_CUST_NAME_PY_QP cis_sc_hmd_kh.CUST_NAME_PY_QP%TYPE;
  v_CUST_NAME_PY_JP cis_sc_hmd_kh.CUST_NAME_PY_JP%TYPE;
  v_FILED1 cis_sc_hmd_kh.FILED1%TYPE;
  v_FILED2 cis_sc_hmd_kh.FILED2%TYPE;
  v_SPYJ cis_sc_hmd_kh.SPYJ%TYPE;
  v_cnt NUMBER;
BEGIN
  pack2_gg.proc_add_list_partition('cis_sc_hmd_kh', p_y || p_m || p_d);
  COMMIT;
  FOR v_row IN cis_sc_hmd_kh_cursor
  LOOP
    v_fact_date           := v_row.fact_date;
    v_apply_id            :=v_row.apply_id;
    v_marketing_org       :=v_row.marketing_org;
    v_open_org            :=v_row.open_org;
    v_open_branch         := v_row.open_branch;
    v_open_area           := v_row.open_area;
    v_cust_mgr            := v_row.cust_mgr;
    v_channel_type        := v_row.channel_type;
    v_cust_id             :=v_row.cust_id;
    v_cert_no             := v_row.cert_no;
    v_cust_name           :=v_row.cust_name;
    v_birthday            :=v_row.birthday;
    v_edu_grade           :=v_row.edu_grade;
    v_industry_name       :=v_row.industry_name;
    v_bussiness_type      :=v_row.bussiness_type;
    v_scheme_id           :=v_row.scheme_id;
    v_project_name        :=v_row.project_name;
    v_apply_amount        :=v_row.apply_amount;
    v_apply_date          :=v_row.apply_date;
    v_term                :=v_row.term;
    v_loan_purpose        :=v_row.loan_purpose;
    v_guaranty_type       := v_row.guaranty_type;
    v_return_card_no      :=v_row.return_card_no;
    v_final_approve_date  := v_row.final_approve_date;
    v_final_approve_user  :=v_row.final_approve_user;
    v_final_approve_result:= v_row.final_approve_result;
    v_credit_result       :=v_row.credit_result;
    v_comprehensive_mark  :=v_row.comprehensive_mark;
    v_quarlity_check_time := v_row.quarlity_check_time;
    v_credit_time         :=v_row.credit_time;
    v_approve_time        :=v_row.approve_time;
    v_return_num          :=v_row.return_num;
    v_return_time         :=v_row.return_time;
    v_contract_no         :=v_row.contract_no;
    v_inputchannel        :=v_row.inputchannel;
    v_contract_amount     :=v_row.contract_amount;
    v_inputchannel_name   :=v_row.inputchannel_name;
    v_CUST_NAME_PY_QP     :=f_getSpell(v_row.CUST_NAME,1);
    v_CUST_NAME_PY_JP     :=f_getSpell(v_row.CUST_NAME);
    v_SPYJ                :='hhhh';
    INSERT
    INTO
      cis_sc_hmd_kh
      (
        fact_date,
        apply_id,
        marketing_org,
        open_org,
        open_branch,
        open_area,
        cust_mgr,
        channel_type,
        cust_id,
        cert_no,
        cust_name ,
        birthday,
        edu_grade,
        industry_name,
        bussiness_type,
        scheme_id,
        project_name,
        apply_amount,
        apply_date,
        term,
        loan_purpose,
        guaranty_type,
        return_card_no,
        final_approve_date,
        final_approve_user,
        final_approve_result,
        credit_result,
        comprehensive_mark,
        quarlity_check_time,
        credit_time,
        approve_time,
        return_num,
        return_time,
        contract_no,
        contract_amount,
        inputchannel,
        inputchannel_name,
        cust_name_py_qp,
        cust_name_py_jp,
        filed1,
        filed2,
        spyj
      )
      VALUES
      (
        v_fact_date,
        v_apply_id,
        v_marketing_org,
        v_open_org,
        v_open_branch,
        v_open_area,
        v_cust_mgr,
        v_channel_type,
        v_cust_id,
        v_cert_no,
        v_cust_name,
        v_birthday,
        v_edu_grade,
        v_industry_name,
        v_bussiness_type,
        v_scheme_id ,
        v_project_name,
        v_apply_amount,
        v_apply_date,
        v_term,
        v_loan_purpose,
        v_guaranty_type,
        v_return_card_no,
        v_final_approve_date,
        v_final_approve_user,
        v_final_approve_result,
        v_credit_result,
        v_comprehensive_mark,
        v_quarlity_check_time,
        v_credit_time,
        v_approve_time,
        v_return_num,
        v_return_time,
        v_contract_no,
        v_inputchannel,
        v_contract_amount,
        v_inputchannel_name,
        v_CUST_NAME_PY_QP,
        v_CUST_NAME_PY_JP,
        '',
        '',
        v_SPYJ
      );
    v_cnt   := v_cnt + 1;
    IF v_cnt = 10000 THEN
      COMMIT;
      v_cnt := 0;
    END IF;
  END LOOP;
  COMMIT;
END proc_hmd_kh;
BEGIN
  NULL;
END pack_sc_hmd_kh;
时间: 2024-10-08 23:58:36

IT忍者神龟之oracle存储过程简单从ODS抽取数据_面向对象思想的相关文章

IT忍者神龟之oracle存储过程——面向对象编程

第一步:创建包接口类似java中的接口定义 create or replace PACKAGE pack_sc_hmd_kh IS --方法的声明 PROCEDURE proc_hmd_kh( p_y VARCHAR2, p_m VARCHAR2, p_d VARCHAR2); END pack_sc_hmd_kh; 第二步:常见包体又称包的实现类似于java中实现接口的具体类 create or replace PACKAGE body pack_sc_hmd_kh IS PROCEDURE

IT忍者神龟之Oracle查询树形结构

Oracle中的select语句可以用START WITH...CONNECT BY PRIOR子句实现递归查询,connect by 是结构化查询中用到的, 其基本语法是: ------------------------------------------------------------------------------------- select * from 表名start with 查询条件1 connect by  查询条件2 where 查询条件3; ------------

IT忍者神龟之oracle 在分组内排序的方法回顾

oracle分析函数十分强大,我们只要掌握这些方法,更直接的说法就是知道这些分析函数的作用就能完成很多工作. 下边贴出这些函数,及简单应用. 其中我想对lag()和lead()函数坐下说明:lag()本身是延后的意思也就是延后出现某列的数,而lead()有引领.领先的意思也就是提前几行显示某列数据 RANK() dense_rank() [语法]RANK ( ) OVER ( [query_partition_clause] order_by_clause ) dense_RANK ( ) OV

IT忍者神龟之Oracle 的数据导入导出及 Sql Loader (sqlldr) 的用法

在 Oracle 数据库中,我们通常在不同数据库的表间记录进行复制或迁移时会用以下几种方法: 1. A 表的记录导出为一条条分号隔开的 insert 语句,然后执行插入到 B 表中 2. 建立数据库间的 dblink,然后用 create table B as select * from [email protected] where ...,或 insert into B select * from [email protected] where ... 3. exp A 表,再 imp 到

IT忍者神龟之Oracle 树操作(select…start with…connect by…prior)

oracle树查询的最重要的就是select-start with-connect by-prior语法了.依托于该语法,我们可以将一个表形结构的以树的顺序列出来.在下面列述了oracle中树型查询的常用查询方式以及经常使用的与树查询相关的oracle特性函数等,在这里只涉及到一张表中的树查询方式而不涉及多表中的关联等. 1.准备测试表和测试数据 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

IT忍者神龟之oracle 集合的使用

每组查询均能得到其结果集,若需将多个查询结果合并成一个结果集,则可利用集合运算来实现. 如并集(UNION).并集且不去除重复行(UNOIN  ALL).交集(INTERSECT).差集(MINUS). 集合命令的目的是将两个(含以上)SQL语句产生的结果合并.由于需要将两个(含以上)数据集合并 因此字段数量必须相等,且类型也必须兼容.如果字段数量无法相同,可以将不足部分以NULL值取代, 以使其字段数量符合要求. 新建两张表并插入数据进行测试: [sql] view plaincopy cre

IT忍者神龟之oracle connect by用法回顾

先用scott用户下的emp表做实验. emp表有个字段,一个是empno(员工编号),另一个是mgr(上级经理编号) 下面是表中所有数据 1 select * from emp start with empno=7698 connect by  mgr=prior empno; 执行结果如下: 得到的结果是empno=7698的数据,以及会得到mgr=7698的数据. 它是向下递归的, 即我们从empno=7698开始遍历,去找出mgr=7698的所有数据S(用S代表查出的所有数据.), 然后

IT忍者神龟之Oracle DBA常用查询吐血列举

–1. 查询系统所有对象 select owner, object_name, object_type, created, last_ddl_time, timestamp, status from dba_objects where owner=upper('scott') –2. 查看系统所有表 select owner, table_name, tablespace_name from dba_tables –3. 查看所有用户的表 select owner, table_name, ta

Oracle 存储过程简单语法

一.无参数的存储过程 --创建存储过程create or replace procedure getdate as datetime varchar2(100); begin select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') into datetime from dual; dbms_output.put_line('当前时间为:'||datetime); end; --调用存储过程begin   getdate;end: 执行结果输出系统当前时间