0

I'm trying to write a procedure that gathers data for all given files. I want the procedure to be used for multiple files. You should be able to give the procedure any number of files, say 25 to it and it goes and gathers all of the data for these files.

Scripts to gather data from the individual tables is pretty easy to write. One of them is below:

     select * From Table_name a
          Where a.FILE_ID in  pi_fileid 
          and a.FILE_TYPE = 'L';

I also tried testing as shown below:

    EXECUTE IMMEDIATE  'select count(*) from Table_name 
                        where file_id in (' || pi_fileid || ')  
                        AND file_type = ''L'' 
                        AND status = ''FP''' INTO cnt;

pi_fileid is the varchar with file names in it. They would be comma delimited.

My Procedure execute call looks like this:

DECLARE 
  PI_FILETYPE VARCHAR2(200);
  PI_DATE DATE;
  PI_FILEID VARCHAR2(200);

BEGIN 
  PI_FILETYPE := 'BLA_BLA';
  PI_DATE := '30-dec-2009';
  PI_FILEID := (''Z1100E71g'' ,''Y1100E71g'');

  GATHER_PKG.GATHEREFILE ( PI_FILETYPE, PI_DATE, PI_FILEID );
  COMMIT; 
END; 

But, from the looks of it, this does not gather anything from the database as the server appears to be thinking I'm looking for ''Z1100E71g.def'', instead of 'Z1100E71g.def'. So, this returns nothing.

Is there a way to do this?

4

1 回答 1

0

最好是使用 sql 数组:

SQL> create type file_id_tab as table of varchar2(20);
  2  /

Type created.

SQL> create or replace package GATHER_PKG
  2  as
  3    procedure gatherfile(pi_filetype table_name.file_type%type,
  4                         pi_date     date,
  5                         pi_fileid   file_id_tab);
  6  end;
  7  /

Package created.

SQL> create or replace  package body GATHER_PKG
  2  as
  3    procedure gatherfile(pi_filetype table_name.file_type%type,
  4                         pi_date     date,
  5                         pi_fileid   file_id_tab)
  6    is
  7      v_cnt number;
  8    begin
  9
 10      select count(*)
 11        into v_cnt
 12        from table_name
 13       where file_id in (select /*+ cardinality(p, 10) */ p.column_value
 14                           from table(pi_fileid) p)
 15         and file_type = pi_filetype
 16         and status = 'FP';
 17
 18      dbms_output.put_line(v_cnt);
 19    end;
 20  end;
 21  /

Package body created.

SQL> DECLARE
  2    PI_FILETYPE VARCHAR2(200);
  3    PI_DATE DATE;
  4    PI_FILEID file_id_tab;
  5
  6  BEGIN
  7    PI_FILETYPE := 'BLA_BLA';
  8    PI_DATE := '30-dec-2009';
  9    PI_FILEID := file_id_tab('Z1100E71g' ,'Y1100E71g');
 10
 11    GATHER_PKG.GATHERFILE ( PI_FILETYPE, PI_DATE, PI_FILEID );
 12    COMMIT;
 13  END;
 14  /
2

PL/SQL procedure successfully completed.

基数提示/*+ cardinality(p, 10) */用于告诉 oracle 大约行数。最好将其设置为您希望数组保存的近似数字(因为 oracle 将默认为 8k 的卡片猜测)

于 2013-01-24T21:29:35.340 回答