循环中的Oracle查找函数返回rowtype如何从rowtype获取字段

时间:2017-08-25 15:10:37

标签: oracle cursor bulk collect rowtype

我有一个运行select的程序(我测试的是56条记录好) 然后,当我运行游标时,我想将3个字段传递给一个函数(见上文) 查找/从包含1500万条记录(价值10年)的表中选择一条记录。

它返回一个我想要的行类型,然后从这个rowtype记录中提取字段 使用第一个选择的记录和获取的其他字段运行插入 来自查找功能。

如果我运行该程序,控制台会打印出我的测试消息,但是当我尝试运行时

从v_processed_claim中选择*批量收集到v_tab_proc_claim_recs;

由于错误(97,65)而无法编译:PL / SQL:ORA-00942:表或视图不存在

好像其中任何一个都不是表格。

我这样做是对的......我怎么能这样做,为什么它不能看到我试图提取的表?

我应该以其他方式这样做..

感谢您提供任何帮助/建议:)

功能如下......

create or replace function get_processed_claim_rec(

    p_provider VARCHAR2,
    p_rx VARCHAR2,
    p_record_no  NUMBER 
)


 return i_idb.processed_claim%rowtype
  as
    l_claim_record i_idb.processed_claim%rowtype;
  begin

    select * into l_claim_record from i_idb.processed_claim
      where source_date = p_provider
      AND rx = p_rx
      AND rec_no = p_record_no;


   return(l_claim_record);
  end;

程序是......

create or replace PROCEDURE import_mailer_data

  AS
    -------------------------------

    /**
        for the lookup table
    **/
    v_processed_claim  i_idb.processed_claim%rowtype;
    TYPE proc_claim_recs IS TABLE OF v_processed_claim%ROWTYPE INDEX BY PLS_INTEGER;
    v_tab_proc_claim_recs proc_claim_recs;
    --------------------------------

    CURSOR myCursor
    IS
    SELECT * 
      from
      (   
      SELECT
        j.create_date as open_date,
        case when (j.create_date < (sysdate - 20) )
            then 'POD'
            else 'REG'
        end as priority,
        c.division,
        c.unit,
        --p.refill as days_supply,
        --p.din_name,
       'CM_JOHN' as log_code,
        c.first_name,
        c.last_name,
        --p.UNLISTED_compound,
        --p.intervention_code,
        --p.substitution,
        --p.confirm,
        c.PROVIDER,
        c.rx,
        c.DISPENSE_DATE,
        c.DIN,
        c.QTY,
        c.DIN_COST_PAID,
        c.DISP_FEE_PAID,
        c.PAID_AMOUNT,
        c.SOURCE_DATE,
        c.RECORD_NO,
        c.RELATIONSHIP,
        c.INSURER_NO,
        c.GROUP_NO,
        c.CERTIFICATE,
        c.BIRTH_DATE,
        c.USER_ID,
        --p.rej_code --v_seq_no
          rank() over
          (
            partition by c.provider, c.rx, c.record_no Order by c.provider desc, c.rx desc

          ) as RNK         
      FROM AUDITCOLLECTIONS.MAILER_CLAIMS c,
        AUDITCOLLECTIONS.MAILER_JOBS j
      WHERE MAILER_JOB_DETAIL_ID IN
        (SELECT MAILER_JOB_DETAIL_ID
        FROM AUDITCOLLECTIONS.MAILER_JOB_DETAILS
        WHERE MAILER_JOB_ID IN
          ( SELECT MAILER_JOB_ID FROM AUDITCOLLECTIONS.MAILER_JOBS
          )
        )

        AND ( c.PROVIDER, c.rx, c.record_no ) NOT IN
          ( SELECT provider, rx, rec_no FROM  AUDITCOLLECTIONS.COLLECTION_AUDIT_STAGING
          )
        AND j.create_date > (sysdate - 30)
        AND c.provider = '2010500042'
      ) A_Latest
      where A_Latest.RNK = 1;

    BEGIN
    v_report_id := audit_load.create_loaded_report(v_report_type_id);

      FOR curRec IN myCursor
      LOOP
        BEGIN
          dbms_output.put_line ('===>>>> PRINTING TEST1 = ');        

        v_processed_claim := get_processed_claim_rec(curRec.PROVIDER, curRec.RX, curRec.RECORD_NO);


        select * bulk collect into v_tab_proc_claim_recs from v_processed_claim; 



      END LOOP;

      audit_load.update_status_to_loaded(v_report_id);
    END import_mailer_data;  

1 个答案:

答案 0 :(得分:1)

你可以这样做:

 FOR curRec IN myCursor
  LOOP

      v_processed_claim := 
         get_processed_claim_rec(curRec.PROVIDER, curRec.RX, curRec.RECORD_NO);

      v_tab_proc_claim_recs (v_tab_proc_claim_recs.COUNT+1) := v_processed_claim;

  END LOOP;

或简化为:

 FOR curRec IN myCursor
  LOOP

      v_tab_proc_claim_recs (v_tab_proc_claim_recs.COUNT+1) :=
        get_processed_claim_rec(curRec.PROVIDER, curRec.RX, curRec.RECORD_NO);

  END LOOP;