Collection in cursor

Hello,
I am in a situation where i have to use the array in the cursor, something like below, can i ?? if not, what is the alternative
CREATE OR REPLACE PROCEDURE p is
TYPE tbl_user_id IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
v_user_id TBL_user_ID;
cursor c1 is select * from users where user_id = v_user_id (i);
begin
null;
end;
/

here is the example below what you are trying to do
SQL> DECLARE
  2     TYPE tbl_order_id IS TABLE OF NUMBER
  3        INDEX BY BINARY_INTEGER;
  4 
  5     v_user_id   tbl_order_id;
  6 
  7     CURSOR c1 (a IN NUMBER)
  8     IS
  9        SELECT empno, ename
10          FROM emp
11         WHERE deptno = a;
12  BEGIN
13     SELECT deptno
14     BULK COLLECT INTO v_user_id
15       FROM dept;
16 
17     FOR i IN v_user_id.FIRST .. v_user_id.LAST
18     LOOP
19        FOR rec IN c1 (v_user_id (i))
20        LOOP
21           DBMS_OUTPUT.put_line (rec.empno||'   '||rec.ename);
22        END LOOP;
23     END LOOP;
24  END;
25  /
7782   CLARK
7839   KING
7934   MILLER
7369   SMITH
7566   JONES
7788   SCOTT
7876   ADAMS
7902   FORD
7499   ALLEN
7521   WARD
7654   MARTIN
7698   BLAKE
7844   TURNER
7900   JAMES
PL/SQL procedure successfully completed.formatted

Similar Messages

  • "table of" collection into cursor

    Let say i have a collection-variable called "emps":
    TYPE emp_table IS TABLE OF employee%ROWTYPE;
    emps emp_table;Now i'm inserting data into it. And then i want to put all data from "emps" to variable
    "o_annuity_payments out SYS_REFCURSOR"
    soemthing like this:
    open o_annuity_payments for
    bulk collect from emps;
    how should i do?

    CharlesRoos wrote:
    Maybe such syntacts is allowed:
    1. declare cursor type variable.Yes.
    2. insert a row into cursor type variableNo.
    Re: "table of" collection into cursor
    A cursor is a pointer to a compiled SQL statement
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10713/sqllangu.htm#CHDFCAGA
    When an application issues a SQL statement, the application makes a parse call to the database to prepare the statement for execution. The parse call opens or creates a cursor, which is a handle for the session-specific private SQL area that holds a parsed SQL statement and other processing information. It is not a result set.
    You cannot insert a row into a cursor because you cannot insert a row into a compiled SQL statement.
    maybe if you explain what you are trying to do more help can be given.

  • Advantages of Collection over Cursor

    Hello All,
    Cursor acts like a pointer to the query result.
    Collections stores the query result.
    But,
    What are the advantages of collection over cursor?
    I Googled it but didn't find the exact info.
    Thx

    Prabodh wrote:
    Hi,
    Each has its own use. They do not compete but supplement each other.
    One has to use them , mix and match, together.
    If collections were all that useless then they would not have existed , and neither would have BULK COLLECT.
    Within COLLECTIONs, you have NESTED TABLES, ASSOCIATIVE ARRAY and VARRAY. The VARRAY is probably still around for backward compatibility, but other 2 are extremely useful.
    Points to consider:
    a) Bulk Collect is much faster than CURSOR loop
    b)Collection once loaded can be manipulated in memory. Faster but heavy on PGA.Faster than what exactly? Certainly not faster than just doing it in SQL. Faster than row by row cursor loop processing? Depends what "manipulation" is required.
    c) NESTED tables allow you to organize data, can be used with Cursor!
    d) String to table and table yo string (like java String.split method) possible only with Collection. Not possible without Collect / arrayAlso possible with pure SQL.
    I cannot imagine a world without COLLECTIONs. I use them extensively, just like I use CURSORS.I've had a few uses for them... but only a few. Most of the hard work is done on the database using SQL.
    Still not convinced? Look up the Specs of OWA_UTIL, DBMS_SQL, APEX_APPLICATION_GLOBAL, etc. They have Associative Arrays all over the place.
    In fact Application Apex would not have come into existence with Associate Arrays; they are used left, right and center in it
    All the negative opinions expressed on Collections only reflects ignorance.
    "How to make friends and influence people" by Prabodh

  • Bulk Collects in Cursors

    Im enhancing a piece of code I have written and would like to use a bulk collect to enter values into my collection, rather than multiple switches.
    Can someone advise me on the correct use of bulk collects with cursors? Is it possible, or should I simply enter the SQL directly into the PLSQL?
    Thanks

    It's not only possible but preferrable to use BULK COLLECT to fetch cursor data into collections. If you search the Oracle documentation at http://tahiti.oracle.com for BULK COLLECT, you'll get plenty of hits that walk you through the details. Basically, though, you want something like this (lifted from the PL/SQL User's Guide)
    DECLARE
       TYPE NumTab IS TABLE OF emp.empno%TYPE;
       TYPE NameTab IS TABLE OF emp.ename%TYPE;
       enums NumTab;  -- no need to initialize
       names NameTab;
    BEGIN
       SELECT empno, ename  
         BULK COLLECT INTO enums, names
         FROM emp;
    END;Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • Need to increase performance-bulk collect in cursor with limit and in the for loop inserting into the trigger table

    Hi all,
    I have a performance issue in the below code,where i am trying to insert the data from table_stg into target_tab and in parent_tab tables and then to child tables via cursor with bulk collect .the target_tab and parent_tab are huge tables and have a row wise trigger enabled on it .the trigger is mandatory . This timetaken for this block to execute is 5000 seconds.Now my requirement is to reduce it to 5 to 10 mins.
    can someone please guide me here.Its bit urgent .Awaiting for your response.
    declare
    vmax_Value NUMBER(5);
      vcnt number(10);
      id_val number(20);
      pc_id number(15);
      vtable_nm VARCHAR2(100);
      vstep_no  VARCHAR2(10);
      vsql_code VARCHAR2(10);
      vsql_errm varchar2(200);
      vtarget_starttime timestamp;
      limit_in number :=10000;
      idx           number(10);
              cursor stg_cursor is
             select
                   DESCRIPTION,
                   SORT_CODE,
                   ACCOUNT_NUMBER,
                     to_number(to_char(CORRESPONDENCE_DATE,'DD')) crr_day,
                     to_char(CORRESPONDENCE_DATE,'MONTH') crr_month,
                     to_number(substr(to_char(CORRESPONDENCE_DATE,'DD-MON-YYYY'),8,4)) crr_year,
                   PARTY_ID,
                   GUID,
                   PAPERLESS_REF_IND,
                   PRODUCT_TYPE,
                   PRODUCT_BRAND,
                   PRODUCT_HELD_ID,
                   NOTIFICATION_PREF,
                   UNREAD_CORRES_PERIOD,
                   EMAIL_ID,
                   MOBILE_NUMBER,
                   TITLE,
                   SURNAME,
                   POSTCODE,
                   EVENT_TYPE,
                   PRIORITY_IND,
                   SUBJECT,
                   EXT_PRD_ID_TX,
                   EXT_PRD_HLD_ID_TX,
                   EXT_SYS_ID,
                   EXT_PTY_ID_TX,
                   ACCOUNT_TYPE_CD,
                   COM_PFR_TYP_TX,
                   COM_PFR_OPT_TX,
                   COM_PFR_RSN_CD
             from  table_stg;
    type rec_type is table of stg_rec_type index by pls_integer;
    v_rt_all_cols rec_type;
    BEGIN
      vstep_no   := '0';
      vmax_value := 0;
      vtarget_starttime := systimestamp;
      id_val    := 0;
      pc_id     := 0;
      success_flag := 0;
              vstep_no  := '1';
              vtable_nm := 'before cursor';
        OPEN stg_cursor;
              vstep_no  := '2';
              vtable_nm := 'After cursor';
       LOOP
              vstep_no  := '3';
              vtable_nm := 'before fetch';
    --loop
        FETCH stg_cursor BULK COLLECT INTO v_rt_all_cols LIMIT limit_in;
                  vstep_no  := '4';
                  vtable_nm := 'after fetch';
    --EXIT WHEN v_rt_all_cols.COUNT = 0;
        EXIT WHEN stg_cursor%NOTFOUND;
    FOR i IN 1 .. v_rt_all_cols.COUNT
      LOOP
       dbms_output.put_line(upper(v_rt_all_cols(i).event_type));
        if (upper(v_rt_all_cols(i).event_type) = upper('System_enforced')) then
                  vstep_no  := '4.1';
                  vtable_nm := 'before seq sel';
              select PC_SEQ.nextval into pc_id from dual;
                  vstep_no  := '4.2';
                  vtable_nm := 'before insert corres';
              INSERT INTO target1_tab
                           (ID,
                            PARTY_ID,
                            PRODUCT_BRAND,
                            SORT_CODE,
                            ACCOUNT_NUMBER,
                            EXT_PRD_ID_TX,         
                            EXT_PRD_HLD_ID_TX,
                            EXT_SYS_ID,
                            EXT_PTY_ID_TX,
                            ACCOUNT_TYPE_CD,
                            COM_PFR_TYP_TX,
                            COM_PFR_OPT_TX,
                            COM_PFR_RSN_CD,
                            status)
             VALUES
                            (pc_id,
                             v_rt_all_cols(i).party_id,
                             decode(v_rt_all_cols(i).product_brand,'LTB',2,'HLX',1,'HAL',1,'BOS',3,'VER',4,0),
                             v_rt_all_cols(i).sort_code,
                             'XXXX'||substr(trim(v_rt_all_cols(i).ACCOUNT_NUMBER),length(trim(v_rt_all_cols(i).ACCOUNT_NUMBER))-3,4),
                             v_rt_all_cols(i).EXT_PRD_ID_TX,
                             v_rt_all_cols(i).EXT_PRD_HLD_ID_TX,
                             v_rt_all_cols(i).EXT_SYS_ID,
                             v_rt_all_cols(i).EXT_PTY_ID_TX,
                             v_rt_all_cols(i).ACCOUNT_TYPE_CD,
                             v_rt_all_cols(i).COM_PFR_TYP_TX,
                             v_rt_all_cols(i).COM_PFR_OPT_TX,
                             v_rt_all_cols(i).COM_PFR_RSN_CD,
                             NULL);
                  vstep_no  := '4.3';
                  vtable_nm := 'after insert corres';
        else
              select COM_SEQ.nextval into id_val from dual;
                  vstep_no  := '6';
                  vtable_nm := 'before insertcomm';
          if (upper(v_rt_all_cols(i).event_type) = upper('REMINDER')) then
                vstep_no  := '6.01';
                  vtable_nm := 'after if insertcomm';
              insert into parent_tab
                 (ID ,
                 CTEM_CODE,
                 CHA_CODE,            
                 CT_CODE,                           
                 CONTACT_POINT_ID,             
                 SOURCE,
                 RECEIVED_DATE,                             
                 SEND_DATE,
                 RETRY_COUNT)
              values
                 (id_val,
                  lower(v_rt_all_cols(i).event_type), 
                  decode(v_rt_all_cols(i).product_brand,'LTB',2,'HLX',1,'HAL',1,'BOS',3,'VER',4,0),
                  'Email',
                  v_rt_all_cols(i).email_id,
                  'IADAREMINDER',
                  systimestamp,
                  systimestamp,
                  0);  
         else
                vstep_no  := '6.02';
                  vtable_nm := 'after else insertcomm';
              insert into parent_tab
                 (ID ,
                 CTEM_CODE,
                 CHA_CODE,            
                 CT_CODE,                           
                 CONTACT_POINT_ID,             
                 SOURCE,
                 RECEIVED_DATE,                             
                 SEND_DATE,
                 RETRY_COUNT)
              values
                 (id_val,
                  lower(v_rt_all_cols(i).event_type), 
                  decode(v_rt_all_cols(i).product_brand,'LTB',2,'HLX',1,'HAL',1,'BOS',3,'VER',4,0),
                  'Email',
                  v_rt_all_cols(i).email_id,
                  'CORRESPONDENCE',
                  systimestamp,
                  systimestamp,
                  0); 
            END if; 
                  vstep_no  := '6.11';
                  vtable_nm := 'before chop';
             if (v_rt_all_cols(i).ACCOUNT_NUMBER is not null) then 
                      v_rt_all_cols(i).ACCOUNT_NUMBER := 'XXXX'||substr(trim(v_rt_all_cols(i).ACCOUNT_NUMBER),length(trim(v_rt_all_cols(i).ACCOUNT_NUMBER))-3,4);
              insert into child_tab
                 (COM_ID,                                            
                 KEY,                                                                                                                                            
                 VALUE)
              values
                (id_val,
                 'IB.Correspondence.AccountNumberMasked',
                 v_rt_all_cols(i).ACCOUNT_NUMBER);
             end if;
                  vstep_no  := '6.1';
                  vtable_nm := 'before stateday';
             if (v_rt_all_cols(i).crr_day is not null) then 
              insert into child_tab
                 (COM_ID,                                            
                 KEY,                                                                                                                                            
                 VALUE)
              values
                (id_val,
                 --'IB.Correspondence.Date.Day',
                 'IB.Crsp.Date.Day',
                 v_rt_all_cols(i).crr_day);
             end if;
                  vstep_no  := '6.2';
                  vtable_nm := 'before statemth';
             if (v_rt_all_cols(i).crr_month is not null) then 
              insert into child_tab
                 (COM_ID,                                            
                 KEY,                                                                                                                                            
                 VALUE)
              values
                (id_val,
                 --'IB.Correspondence.Date.Month',
                 'IB.Crsp.Date.Month',
                 v_rt_all_cols(i).crr_month);
             end if;
                  vstep_no  := '6.3';
                  vtable_nm := 'before stateyear';
             if (v_rt_all_cols(i).crr_year is not null) then 
              insert into child_tab
                 (COM_ID,                                            
                 KEY,                                                                                                                                            
                 VALUE)
              values
                (id_val,
                 --'IB.Correspondence.Date.Year',
                 'IB.Crsp.Date.Year',
                 v_rt_all_cols(i).crr_year);
             end if;
                  vstep_no  := '7';
                  vtable_nm := 'before type';
               if (v_rt_all_cols(i).product_type is not null) then
                  insert into child_tab
                     (COM_ID,                                            
                     KEY,                                                                                                                                        
                     VALUE)
                  values
                    (id_val,
                     'IB.Product.ProductName',
                   v_rt_all_cols(i).product_type);
                end if;
                  vstep_no  := '9';
                  vtable_nm := 'before title';         
              if (trim(v_rt_all_cols(i).title) is not null) then
              insert into child_tab
                 (COM_ID,                                            
                 KEY,                                                                                                                                            
                 VALUE )
              values
                (id_val,
                 'IB.Customer.Title',
                 trim(v_rt_all_cols(i).title));
              end if;
                  vstep_no  := '10';
                  vtable_nm := 'before surname';
              if (v_rt_all_cols(i).surname is not null) then
                insert into child_tab
                   (COM_ID,                                            
                   KEY,                                                                                                                                          
                   VALUE)
                values
                  (id_val,
                  'IB.Customer.LastName',
                  v_rt_all_cols(i).surname);
              end if;
                            vstep_no  := '12';
                            vtable_nm := 'before postcd';
              if (trim(v_rt_all_cols(i).POSTCODE) is not null) then
              insert into child_tab
                 (COM_ID,                                            
                 KEY,                                                                                                                                            
                 VALUE)                              
               values
                (id_val,
                 'IB.Customer.Addr.PostCodeMasked',
                  substr(replace(v_rt_all_cols(i).POSTCODE,' ',''),length(replace(v_rt_all_cols(i).POSTCODE,' ',''))-2,3));
              end if;
                            vstep_no  := '13';
                            vtable_nm := 'before subject';
              if (trim(v_rt_all_cols(i).SUBJECT) is not null) then
              insert into child_tab
                 (COM_ID,                                            
                 KEY,                                                                                                                                            
                 VALUE)                              
               values
                (id_val,
                 'IB.Correspondence.Subject',
                  v_rt_all_cols(i).subject);
              end if;
                            vstep_no  := '14';
                            vtable_nm := 'before inactivity';
              if (trim(v_rt_all_cols(i).UNREAD_CORRES_PERIOD) is null or
                  trim(v_rt_all_cols(i).UNREAD_CORRES_PERIOD) = '3' or
                  trim(v_rt_all_cols(i).UNREAD_CORRES_PERIOD) = '6' or
                  trim(v_rt_all_cols(i).UNREAD_CORRES_PERIOD) = '9') then
              insert into child_tab
                 (COM_ID,                                            
                 KEY,                                                                                                                                            
                 VALUE)                              
               values
                (id_val,
                 'IB.Correspondence.Inactivity',
                  v_rt_all_cols(i).UNREAD_CORRES_PERIOD);
              end if;
                          vstep_no  := '14.1';
                          vtable_nm := 'after notfound';
        end if;
                          vstep_no  := '15';
                          vtable_nm := 'after notfound';
        END LOOP;
        end loop;
                          vstep_no  := '16';
                          vtable_nm := 'before closecur';
        CLOSE stg_cursor;
                          vstep_no  := '17';
                          vtable_nm := 'before commit';
        DELETE FROM table_stg;
      COMMIT;
                          vstep_no  := '18';
                          vtable_nm := 'after commit';
    EXCEPTION
    WHEN OTHERS THEN
      ROLLBACK;
      success_flag := 1;
      vsql_code := SQLCODE;
      vsql_errm := SUBSTR(sqlerrm,1,200);
      error_logging_pkg.inserterrorlog('samp',vsql_code,vsql_errm, vtable_nm,vstep_no);
      RAISE_APPLICATION_ERROR (-20011, 'samp '||vstep_no||' SQLERRM:'||SQLERRM);
    end;
    Thanks

    Its bit urgent
    NO - it is NOT urgent. Not to us.
    If you have an urgent problem you need to hire a consultant.
    I have a performance issue in the below code,
    Maybe you do and maybe you don't. How are we to really know? You haven't posted ANYTHING indicating that a performance issue exists. Please read the FAQ for how to post a tuning request and the info you need to provide. First and foremost you have to post SOMETHING that actually shows that a performance issue exists. Troubleshooting requires FACTS not just a subjective opinion.
    where i am trying to insert the data from table_stg into target_tab and in parent_tab tables and then to child tables via cursor with bulk collect .the target_tab and parent_tab are huge tables and have a row wise trigger enabled on it .the trigger is mandatory . This timetaken for this block to execute is 5000 seconds.Now my requirement is to reduce it to 5 to 10 mins.
    Personally I think 5000 seconds (about 1 hr 20 minutes) is very fast for processing 800 trillion rows of data into parent and child tables. Why do you think that is slow?
    Your code has several major flaws that need to be corrected before you can even determine what, if anything, needs to be tuned.
    This code has the EXIT statement at the beginning of the loop instead of at the end
        FETCH stg_cursor BULK COLLECT INTO v_rt_all_cols LIMIT limit_in;
                  vstep_no  := '4';
                  vtable_nm := 'after fetch';
    --EXIT WHEN v_rt_all_cols.COUNT = 0;
        EXIT WHEN stg_cursor%NOTFOUND;
    The correct place for the %NOTFOUND test when using BULK COLLECT is at the END of the loop; that is, the last statement in the loop.
    You can use a COUNT test at the start of the loop but ironically you have commented it out and have now done it wrong. Either move the NOTFOUND test to the end of the loop or remove it and uncomment the COUNT test.
    WHEN OTHERS THEN
      ROLLBACK;
    That basically says you don't even care what problem occurs or whether the problem is for a single record of your 10,000 in the collection. You pretty much just throw away any stack trace and substitute your own message.
    Your code also has NO exception handling for any of the individual steps or blocks of code.
    The code you posted also begs the question of why you are using NAME=VALUE pairs for child data rows? Why aren't you using a standard relational table for this data?
    As others have noted you are using slow-by-slow (row by row processing). Let's assume that PL/SQL, the bulk collect and row-by-row is actually necessary.
    Then you should be constructing the parent and child records into collections and then inserting them in BULK using FORALL.
    1. Create a collection for the new parent rows
    2. Create a collection for the new child rows
    3. For each set of LIMIT source row data
      a. empty the parent and child collections
      b. populate those collections with new parent/child data
      c. bulk insert the parent collection into the parent table
      d. bulk insert the child collection into the child table
    And unless you really want to either load EVERYTHING or abandon everything you should use bulk exception handling so that the clean data gets processed and only the dirty data gets rejected.

  • Problem with collection in cursor

    hi ,
    oracle srvr : 10.2.0.1.0
    when I'm executing the following
    declare
    type i_values is varray(20000) of employee_details%rowtype;
    s_values i_values :=i_values();
    cursor c1 is select * from employee_details where rownum < 11;
    begin
    loop
    begin
    fetch c1  into s_values  ;
    s_values.extend;
    exit when c1%NOTFOUND;
    exception
    when  invalid_cursor then
    dbms_output.put_line('Cursor invalid');
    when others then
    dbms_output.put_line('Others');
    end ;
    end loop;
    for i in 1 .. s_values.count loop
    dbms_output.put_line(s_values(i).eid);
    end loop;
    end;
    / I get the error as
    ERROR at line 8:
    ORA-06550: line 8, column 16:
    PLS-00597: expression 'S_VALUES' in the INTO list is of wrong type
    ORA-06550: line 8, column 1:
    PL/SQL: SQL Statement ignoredInstead when I run cursor as bulk collect its executing but going to a infinite loop
    please help

    As Justin showed, you want to use BULK collect if you need to fetch data into a collection.
    e.g.
    SQL> set serverout on
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    type t_emps is table of emp%rowtype;
      3    v_emps t_emps;
      4    cursor c1 is
      5      select *
      6      from emp
      7      where rownum <= 10;
      8  begin
      9    open c1;
    10    fetch c1 bulk collect into v_emps;
    11    close c1;
    12    for i in 1 .. v_emps.count
    13    loop
    14      dbms_output.put_line(v_emps(i).empno||' - '||v_emps(i).ename);
    15    end loop;
    16* end;
    SQL> /
    7369 - SMITH
    7499 - ALLEN
    7521 - WARD
    7566 - JONES
    7654 - MARTIN
    7698 - BLAKE
    7782 - CLARK
    7788 - SCOTT
    7839 - KING
    7844 - TURNER
    PL/SQL procedure successfully completed.
    SQL>If your code has got stuck in an infinite loop, you've probably left the LOOP construct in your code. That isn't needed with a bulk collect, unless you limit the number of rows fetched and need to process in set sized chunks.
    If you planning on extracting the data to a load of INSERT statements then consider that as being bad practice.
    You would be better to export the data to a flat file (CSV) and then have the receiving database use an external table (or SQL*Loader) if you must, to load that data back in. Lots of insert statements WILL be slow.
    If you want to export data to a flat file you can use something like:
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

  • Which is more (faster) performance oriented? Collections or Cursor For Loop

    Hi,
    Please help me regarding a dilemma.
    Is, using a Cursor For Loop faster than a loop run upon a collection variable that was being populated using bulk collect? Why?
    Thanks in advance
    rollerz

    You can just test it by yourself. Can’t you? Ok I was bit curious to know myself so I did this…
    TEST ROUND 1
    SQL> declare
      2     ltime integer;
      3  begin
      4     ltime := dbms_utility.get_time;
      5
      6     for i in (select level from dual connect by level <= 100000)
      7     loop
      8             null;
      9     end loop;
    10
    11     ltime := dbms_utility.get_time - ltime;
    12     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    13  end;
    14  /
    ExecTime:.19 seconds...
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3     type my_type is table of integer;
      4     lType my_type;
      5  begin
      6     ltime := dbms_utility.get_time;
      7     select level bulk collect into lType from dual connect by level <= 100000;
      8
      9     for i in 1..lType.count
    10     loop
    11             null;
    12     end loop;
    13
    14     ltime := dbms_utility.get_time - ltime;
    15     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    16  end;
    17  /
    ExecTime:.14 seconds...
    PL/SQL procedure successfully completed.
    TEST ROUND 2
    SQL> declare
      2     ltime integer;
      3  begin
      4     ltime := dbms_utility.get_time;
      5
      6     for i in (select level from dual connect by level <= 100000)
      7     loop
      8             null;
      9     end loop;
    10
    11     ltime := dbms_utility.get_time - ltime;
    12     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    13  end;
    14  /
    ExecTime:.17 seconds...
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3     type my_type is table of integer;
      4     lType my_type;
      5  begin
      6     ltime := dbms_utility.get_time;
      7     select level bulk collect into lType from dual connect by level <= 100000;
      8
      9     for i in 1..lType.count
    10     loop
    11             null;
    12     end loop;
    13
    14     ltime := dbms_utility.get_time - ltime;
    15     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    16  end;
    17  /
    ExecTime:.13 seconds...
    TEST ROUND 3
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3  begin
      4     ltime := dbms_utility.get_time;
      5
      6     for i in (select level from dual connect by level <= 100000)
      7     loop
      8             null;
      9     end loop;
    10
    11     ltime := dbms_utility.get_time - ltime;
    12     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    13  end;
    14  /
    ExecTime:.16 seconds...
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3     type my_type is table of integer;
      4     lType my_type;
      5  begin
      6     ltime := dbms_utility.get_time;
      7     select level bulk collect into lType from dual connect by level <= 100000;
      8
      9     for i in 1..lType.count
    10     loop
    11             null;
    12     end loop;
    13
    14     ltime := dbms_utility.get_time - ltime;
    15     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    16  end;
    17  /
    ExecTime:.13 seconds...
    TEST ROUND 4
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3  begin
      4     ltime := dbms_utility.get_time;
      5
      6     for i in (select level from dual connect by level <= 100000)
      7     loop
      8             null;
      9     end loop;
    10
    11     ltime := dbms_utility.get_time - ltime;
    12     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    13  end;
    14  /
    ExecTime:.16 seconds...
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ltime integer;
      3     type my_type is table of integer;
      4     lType my_type;
      5  begin
      6     ltime := dbms_utility.get_time;
      7     select level bulk collect into lType from dual connect by level <= 100000;
      8
      9     for i in 1..lType.count
    10     loop
    11             null;
    12     end loop;
    13
    14     ltime := dbms_utility.get_time - ltime;
    15     dbms_output.put_line('ExecTime:'||ltime/100||' seconds...');
    16  end;
    17  /
    ExecTime:.13 seconds...
    PL/SQL procedure successfully completed.So bulk collect looks faster...
    Thanks,
    Karthick.

  • How to crate a dynamic size array, collection

    Hi,
    Can someone point me to some tutorial on how to create a dynamic size array. Actually I have multiple cursors and on different tables and want to loop through each cursor and get some values from each cursor and put it in an array. But don't know how to create or initialize an array as I don't know the size. Is there any other way.
    Here is what I am doing I have 6 cursors on different tables, I loop through each cursor and get some specific data that I need to place at one place after looping through all the cursors which then finally needs to be inserted in one table. But before the insert I need to validate each data so want to have all the data in some array or some other place for temporary storage from it's easier to do the validate and insert rather than while looping through the cursors as there may be duplicates which I am trying to remove.
    As this procedure will be called multiple times so wanted to save the cursor data in temporary array before inserting in the final table. Looking for some faster and efficient way.
    Any help is appreciated.
    Thanks

    guest0012 wrote:
    All the 6 cursors are independent and no relation i.e. can have a join and have one sql as no relationship in tables.If there is no relation, then what are your code doing combining unrelated rows into the same GTT/array?
    Now using GTT when I do an insert how do I make sure the same data doesnot already exists. i.e. GTT will only have one column. Then create a unique index or primary key for the GTT and use that to enforce uniqueness.
    So everytime I iterate over a cursor I have to insert into GTT and then finally again have to iterate over GTT and then do an insert in the final table which maybe a performance issue Which is why using SQL will be faster and more scalable - and if PL/SQL code/logic can be used to glue these "no relationship" tables together, why can't that not be done in SQL?
    that's why i was wondering if can use any kind of array or collection as it will be a collection of numbersAnd that will reside in expensive PGA memory. Which means a limit on the size of the collection/array you can safely create without impacting server performance, or even cause a server crash by exhausting all virtual memory and causing swap space to trash.
    and finally will just iterate ovr array and use FOR ALL for insert but don't know what will be the size of the array as I only know after looping the cursors the total number of records to be stored. So wondering if how to do it through collection/array is there a way to intialize the array and keep populating it with the data with defining the size before hand.You cannot append the bulk collect of one cursor into the collection used for bulk collecting another cursor.
    Collections are automatically sized to the number of rows fetched. If you want to manually size collection, the Extend() method needs to be used, where the method's argument specifies the number of cells/locations to add to the collection.
    From what you describe about the issue you have - collections are not the correct choice. If you are going to put the different tables's data into the same collection, then you can also combine those tables's data using a single SQL projection (via a UNION for example).
    And doing the data crunching side in SQL is always superior in scalability and performance, than doing it in PL/SQL.

  • Error in using one's collection values in other collection

    hi,
    I want to fetch cursor s values based upon cursor r part_no column to populate childbkp table.but i m getting eror .plz help me to resolve.in code it might b many mistakes also.
    declare
              TYPE PartNum IS TABLE OF parent.part_num%TYPE
              INDEX BY BINARY_INTEGER;
              pnum_t PartNum;
              TYPE PartName IS TABLE OF parent.part_name%TYPE
              INDEX BY BINARY_INTEGER;
              pnam_t PartName;
              CURSOR r IS
                   SELECT part_num, part_name
                   FROM parent;
              type r_part_num_arry IS TABLE OF r%rowtype;
              r_part_num r_part_num_arry;
              r_pnum_t parent.PART_NO%type;
              CURSOR s IS
                   SELECT part_num, part_name
                   FROM parent p where rownum=1 and p.PART_NO = r_pnum_t ;          
    BEGIN
    OPEN r;
    LOOP
    FETCH r BULK COLLECT INTO pnum_t, pnam_t LIMIT 1000;
         FORALL i IN pnum_t.FIRST .. pnum_t.LAST
         INSERT INTO child
         (part_num, part_name)
         VALUES
         (pnum_t(i), pnam_t(i));
         COMMIT;
                   begin
                             OPEN s;
                             LOOP
                                  r_pnum_t := pnum_t(i);
                             FETCH s BULK COLLECT INTO pnum_t, pnam_t LIMIT 1000;
                                  FORALL i IN pnum_t.FIRST .. pnum_t.LAST
                                  INSERT INTO child_bkp
                                  (part_num, part_name)
                                  VALUES
                                  (pnum_t(i), pnam_t(i));
                                  COMMIT;
                             EXIT WHEN s%NOTFOUND;
                             END LOOP;
                             COMMIT;
                             CLOSE s;     
                   end;
    EXIT WHEN r%NOTFOUND;
    END LOOP;
    COMMIT;
    CLOSE r;
    END ;

    i need to run 1st qry based upoin below senerio.i need to do this work in collection case also.how to do it by collection.
    declare
         CURSOR r IS
              SELECT part_num, part_name
              FROM parent;
              r_pnum_t parent.PART_Num%type;
              pnum_t      parent.PART_Num%type;
              pnam_t      parent.PART_Name%type;
              CURSOR s IS
              SELECT part_num, part_name
              FROM parent p where rownum=1 and p.PART_Num = r_pnum_t ;
    BEGIN
         OPEN r;
         LOOP
              FETCH r INTO pnum_t, pnam_t ;
              INSERT INTO child(part_num, part_name)
              VALUES(pnum_t, pnam_t);
                                  begin
                                       OPEN s;
                                       LOOP
                                            r_pnum_t := pnum_t ;
                                            FETCH s INTO pnum_t, pnam_t ;
                                            INSERT INTO child_bkp(part_num, part_name)
                                                 VALUES(pnum_t, pnam_t);
                                            COMMIT;
                                       EXIT WHEN s%NOTFOUND;
                                       END LOOP;
                                  COMMIT;
                                  CLOSE s;
                                  end;          
         EXIT WHEN r%NOTFOUND;
         END LOOP;
         COMMIT;
         CLOSE r;
         END

  • Same EMP NUM in multiple cursors

    My plsql program is designed in such way that there are multiple cursors & each cursor needs input as EMPLOYEE NUMBER.
    This EMPLOYEE NUMBER should be same across all the cursors.
    Code is as below.
    Any kind of help here is appreciated. Thank you in advance.
    -- AGTSP
    SET SERVEROUTPUT ON
    alter session set nls_date_format='YYYY-MM-DD';
    DECLARE
        MY_FILE_DIR varchar2(40) := '/usr/tmp2';
        l_output        utl_file.file_type;
        v_file_handle varchar2(30) default 'Legacy_Job_Data.csv';
        buf varchar2(10230);
        v_ps_id varchar2(10);
        v_job_descr varchar2(40);
      v_belonging_name VARCHAR2(100);
      v_sg VARCHAR2(4);
      v_sg_jc VARCHAR2(6);
      v_EFFECTIVE_START_DATE DATE;
      SG VARCHAR2(10);
      v_count number;
    -- CJL DATA COLLECTION STARTS
    -- CURSOR STARTS
        CURSOR C_MAIN IS        
      select
                        EMP.EMPLOYEE_NUMBER AS EMPLOYEE_NUMBER
      , JOB.BELONGING_NAME
      , JOB.CHANGE_REASON_NAME
      , JOB.EFFECTIVE_START_DATE
      , JOB.EFFECTIVE_END_DATE
                    from
                        apps.zshr_employee_v EMP
                        , apps.ZSHR_ASSIGNMENT_V JOB
                    where
                        EMP.EMPLOYEE_NUMBER = JOB.EMPLOYEE_NUMBER
                    and TO_CHAR( EMP.EFFECTIVE_END_DATE , 'YYYY-MM-DD')='4712-12-31'                and JOB.QUALIFICATION_CODE <>'0151'
      ORDER BY EFFECTIVE_START_DATE DESC
    CURSOR C_SCM IS        
      SELECT
                        EMP.EMPLOYEE_NUMBER AS EMPLOYEE_NUMBER
      , JOB.BELONGING_NAME
      , JOB.CHANGE_REASON_NAME
      , JOB.EFFECTIVE_START_DATE
      , JOB.EFFECTIVE_END_DATE
                    from
                        apps.zshr_employee_v EMP
                        , apps.ZSHR_ASSIGNMENT_V JOB
                    where
                        EMP.EMPLOYEE_NUMBER = JOB.EMPLOYEE_NUMBER
                   and TO_CHAR( EMP.EFFECTIVE_END_DATE , 'YYYY-MM-DD') ='4712-12-31' and TO_CHAR( JOB.EFFECTIVE_END_DATE , 'YYYY-MM-DD') <'2008-08-01'
      and TO_CHAR( JOB.EFFECTIVE_START_DATE , 'YYYY-MM-DD') >= '1987-07-01'
      and JOB.QUALIFICATION_CODE <>'0151'
      and rownum=1
      ORDER BY EFFECTIVE_START_DATE ASC
    CURSOR C_CM IS        
      SELECT
                        EMP.EMPLOYEE_NUMBER AS EMPLOYEE_NUMBER
      , JOB.BELONGING_NAME
      , JOB.CHANGE_REASON_NAME
      , JOB.EFFECTIVE_START_DATE
      , JOB.EFFECTIVE_END_DATE
            from
                        apps.zshr_employee_v EMP
                        , apps.ZSHR_ASSIGNMENT_V JOB
                    where
                        EMP.EMPLOYEE_NUMBER = JOB.EMPLOYEE_NUMBER
                   and TO_CHAR( EMP.EFFECTIVE_END_DATE , 'YYYY-MM-DD') ='4712-12-31' and TO_CHAR( JOB.EFFECTIVE_START_DATE , 'YYYY-MM-DD') < '1987-07-01'
      and rownum =1
      ORDER BY EFFECTIVE_START_DATE ASC
    -- MAIN BODY BEGINS
    BEGIN
    -- FILE INITIALIZATION
        l_output := utl_file.fopen(MY_FILE_DIR,v_file_handle, 'w', 32767);
    -- WRITING THE FILE HEADER STARTS
        buf := 'EMPLID'
                    || ',EMPL_RCD'
                    || ',EFFDT'
                    || ',EFFSEQ'
                    || ',CX_EE_ID_NBR'
                    || ',CX_SECT_NM'
                    || ',LOCATION'
                    || ',CX_WRK_LOC_DESCR'
                    || ',JOBCODE'
                    || ',JOB_DESCR'
                    || ',GRADE'
                    || ',COMPRATE '
                    || ',CURRENCY_CODE'
                    || ',COMP_FREQUENCY'
        utl_file.put_line(l_output,buf);
    FOR C_EMP_rec in C_MAIN LOOP
    -- CJL LEGACY JOB DATA COLLECTION
    --PS ID EXTRACTION STARTS
      BEGIN
      select PS_ID INTO v_ps_id from apps.TB03569A where
            EBS_ID=C_EMP_rec.EMPLOYEE_NUMBER;
      EXCEPTION
      WHEN no_data_found THEN
      v_ps_id := 'NO DATA';
      END;
    --PS ID EXTRACTION END
      IF  C_EMP_rec.EFFECTIVE_START_DATE >= '2008/8/1' THEN
        buf := v_ps_id                               /* EMPLID */
               || ',' || 0                             /* EMPL_RCD */
               || ',' || C_EMP_rec.EFFECTIVE_START_DATE         /* EFFDT*/
               || ',' || 0                             /* EFFSEQ*/
               || ',' || C_EMP_rec.EMPLOYEE_NUMBER             /* CX_EE_ID_NBR */
                 || ',' || C_EMP_rec.BELONGING_NAME     /* CX_SECT_NM */
                 || ',' || ''                 /* LOCATION */
               || ',' || 'CX_WRK_LOC_DESCR'               /* CX_WRK_LOC_DESCR */
                 || ',' || C_EMP_rec.SG_JOB_CODE /* JOBCODE */
                 || ',' || v_job_descr               /* JOB_DESCR */
                 || ',' || C_EMP_rec.SG         /* GRADE */
               || ',' || ''       /* COMPRATE */
                 || ',' || 'JPY'               /* CURRENCY CODE */
                 || ',' || '' /* COMP FREQUENCY */
                 || ',' || C_EMP_rec.EMP_SG_T_O_FLG           /* SG T Oth. Flag */
      utl_file.put_line(l_output,buf);
      END IF;
    END LOOP;
    FOR C_SCM_rec in C_SCM LOOP
    --PS ID EXTRACTION STARTS
      BEGIN
      select PS_ID INTO v_ps_id from apps.TB03569A where
            EBS_ID=C_SCM_rec.EMPLOYEE_NUMBER;
      EXCEPTION
      WHEN no_data_found THEN
      v_ps_id := 'NO DATA';
      END;
    --PS ID EXTRACTION END
    buf := v_ps_id                               /* EMPLID */
               || ',' || 0                             /* EMPL_RCD */
               || ',' || C_SCM_rec.EFFECTIVE_START_DATE         /* EFFDT*/
               || ',' || 0                             /* EFFSEQ*/
               || ',' || C_SCM_rec.EMPLOYEE_NUMBER             /* CX_EE_ID_NBR */
                 || ',' || C_SCM_rec.BELONGING_NAME     /* CX_SECT_NM */
                 || ',' || ''                 /* LOCATION */
               || ',' || 'CX_WRK_LOC_DESCR'               /* CX_WRK_LOC_DESCR */
                 || ',' || C_SCM_rec.SG_JOB_CODE /* JOBCODE */
                 || ',' || 'v_job_descr'               /* JOB_DESCR */
                 || ',' || C_SCM_rec.SG         /* GRADE */
               || ',' || ''       /* COMPRATE */
                 || ',' || 'JPY'               /* CURRENCY CODE */
                 || ',' || '' /* COMP FREQUENCY */
                 || ',' || C_SCM_rec.EMP_SG_T_O_FLG           /* SG T Oth. Flag */
      utl_file.put_line(l_output,buf);
    -- SCM DATA COLLECTION STARTS
    END LOOP;
    -- SCM DATA COLLECTION ENDS
    FOR C_CM_rec in C_CM LOOP
    --PS ID EXTRACTION STARTS
      BEGIN
      select PS_ID INTO v_ps_id from apps.TB03569A where
            EBS_ID=C_CM_rec.EMPLOYEE_NUMBER;
      EXCEPTION
      WHEN no_data_found THEN
      v_ps_id := 'NO DATA';
      END;
    --PS ID EXTRACTION END
      BEGIN
      select count(*) INTO v_count from
      SELECT 
      distinct
      EMP.EMPLOYEE_NUMBER
      , JOB.ASSIGNMENT_NUMBER
      , JOB.ASSIGNMENT_ID
      from
      apps.zshr_employee_v EMP
      , apps.ZSHR_ASSIGNMENT_V JOB
      where
      EMP.EMPLOYEE_NUMBER=JOB.EMPLOYEE_NUMBER
      and EMP.EMPLOYEE_NUMBER=C_CM_rec.EMPLOYEE_NUMBER
      EXCEPTION
      WHEN no_data_found THEN
      v_count := 0;
      END;
      IF v_count > 1 THEN
      v_job_descr := 'MHI';
      ELSE
      v_job_descr := 'CM';
      END IF;
      buf := v_ps_id                           /* EMPLID */
               || ',' || 0                             /* EMPL_RCD */
               || ',' || C_CM_rec.EFFECTIVE_START_DATE         /* EFFDT*/
               || ',' || 0                             /* EFFSEQ*/
               || ',' || C_CM_rec.EMPLOYEE_NUMBER             /* CX_EE_ID_NBR */
                 || ',' || C_CM_rec.BELONGING_NAME     /* CX_SECT_NM */
                 || ',' || ''                 /* LOCATION */
               || ',' || 'CX_WRK_LOC_DESCR'               /* CX_WRK_LOC_DESCR */
                 || ',' || C_CM_rec.SG_JOB_CODE /* JOBCODE */
                 || ',' || v_job_descr               /* JOB_DESCR */
                 || ',' || C_CM_rec.SG         /* GRADE */
               || ',' || ''       /* COMPRATE */
                 || ',' || 'JPY'               /* CURRENCY CODE */
                 || ',' || '' /* COMP FREQUENCY */
                 || ',' || C_CM_rec.EMP_SG_T_O_FLG           /* SG T Oth. Flag */
      utl_file.put_line(l_output,buf);
    -- SCM DATA COLLECTION STARTS
    END LOOP;
        utl_file.fclose(l_output);
    END;

    Well, I'm not sure what you're issue is as you haven't told us.
    Typically cursors within cursors or multiple cursors are a bad idea, and you should look to try and combine SQL statements into one statement where possible.
    I do however, notice that you've specifying an operating system path for your directory (/usr/tmp2).  You should not use o/s paths with Oracle, you should use Oracle directory objects e.g.
    The UTL_FILE_DIR parameter has been deprecated by oracle in favour of direcory objects because of it's security problems.
    The correct thing to do is to create a directory object e.g.:
    CREATE OR REPLACE DIRECTORY mydir AS 'c:\myfiles';
    Note: This does not create the directory on the file system. You have to do that yourself and ensure that oracle has permission to read/write to that file system directory.
    Then, grant permission to the users who require access e.g....
    GRANT READ,WRITE ON DIRECTORY mydir TO myuser;
    Then use that directory object inside your FOPEN statement e.g.
    fh := UTL_FILE.FOPEN('MYDIR', 'myfile.txt', 'r');
    Note: You MUST specify the directory object name in quotes and in UPPER case for this to work as it is a string that is referring to a database object name which will have been stored in uppercase by default.

  • Image Placement when moving from all images to Quick collection

    It would be nice if your position in the main catalog would remain intact when you move from the main group of imgages to the Quick Collection. Presently, you scroll down through thousands of images in the main collection and find an image that you feel might be similar to one you've already added. You go to check the Quick Collection to review your selection and when you go back to continue searching the main collection, the cursor takes you back to the very top of the page of the main collection. You then have to scroll through thousands of images you've already looked at. Is there currently a way around this anyone?
    An even better option would be the ability to open the Quick collection or any other Collection and view the images in side by side windows with the main collection. Aperture allows viewing in this manner. this would be a nice addition to Lightroom.

    Absolutely agree. My request is here:
    http://www.adobeforums.com/cgi-bin/webx/.3bc3473c/0

  • Mouse cursors in flash cs4

    Hi,
    Im working on a big gallery page and i included some zoom and pan features.
    After the user click on one of the zoom buttons i want the cursor to change into a hand so the user will now that he can
    pan the image and when the user click and drag i want the cursor to change to like a closed hand that will tell the user that as
    long as the mouse is clicked the image will be dragable.
    My question is if theres a collection of cursor status in flash that i can use or that i need to find the icons import them to flash
    and then change the code ?

    Thank you for your help! (sorry,I`m bad in English...)
    In fact, it works.
    but,I made a mistake,the reason I want to give a list a horizontalScrollBar is:I want to show all content in a list that is not wide enough,
    you see,first row can show all content in this list,but in the other rows,the content is too wide to show,I want to give the list a horizontalScrollBar to show all content by draging the horizontalScrollBar to right.
    now,set property:
    list.horizontalScrollPolicy="on", list.maxHorizontalScrollPosition=30;(the result is the image above),when I drag the horizontalScrollBar to right:
    ah ha ,the row can`t show all content too,the horizontalScrollBar is related to the width of all the list, is not related to the width of the content in every row.
    now I kown why the horizontalScrollBar is always disable.
    but in design,to show a lot of content,we can`t draw  a list too wide, it`s not beatiful,so I want to use a horizontalScrollBar to show all content in every row.
    and the list is not too wide
    ah ah,  like the list in Flex4
    In fact,ah,I have not studied Flex 4,so,I have to make it by using Flash CS4 Component
    How can I do? Please
    (so sorry for my bad English,I do my best in it)

  • Bulk collect into associative array

    Please advise examples of a bulkk collecting a cursor into associative array amd working on the basis of one column as key.
    Here need to calculate based onnfollowing data and key as Col1 until all records for that key are worked upon.
    Col1 col2 col3 Flag
    AA A11 A13 1
    AA A12 A13 1
    BB B11 B11 1
    BB B11 B11 2
    CC C11 C11 1

    ?:|
    You might want to rephrase your question...
    http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
    Examples:
    http://www.java2s.com/Code/Oracle/PL-SQL/Howtodoabulkcollectintoanassociativearray.htm
    http://www.oracle-developer.net/display.php?id=201
    http://www.oracle.com/pls/db102/search?word=bulk+collect
    http://www.oracle.com/pls/db102/search?word=associative+array

  • Apex_collection.update_member.  What am I doing wrong.

    I am able to create my collection, then select from it. Unfortunately, I am not able to get it to update. I have been able to do this for other collections, so I am stumped...and believe it is something simple I am doing wrong....any thoughts? thank you.
    PROCESS: before header: create trip collection
    declare
    cursor fav is select trip_fav_seq
    from trip_favorites
    where cf_permit_id = :F200_PERMIT_ID and
    activate_flag = 'Y';
    xfav number;
    begin
    apex_collection.create_or_truncate_collection (p_collection_name => 'TRIP_C');
    open fav;
    fetch fav into xfav;
    if fav%found then
    apex_collection.add_member(p_collection_name => 'TRIP_C',
    p_c032 => :F200_fav_state , -- state
    p_c033 => :F200_fav_port, -- port
    p_c034 => :F200_FAV_VESSEL_ID, -- vessel id
    p_c035 => null, -- trip_start_date
    p_c036 => null, -- trip_start_time
    p_c037 => null, -- trip_end_date
    p_c038 => null, -- trip_end_time
    p_c039 => 'C', -- trip_type
    p_c040 => 'N', -- multiple_fishermen
    p_c041 => :F200_PERMIT_ID, -- cf_permit_id
    p_c042 => 0, -- days_at_sea
    p_c043 => 0, -- nbr_of_crew
    p_c044 => null, -- supplier_trip_id
    p_c045 => 1, -- trip_nbr
    p_c046 => null, -- partner_vtr
    p_c047 => :F200_PARTICIPANT_ID, -- submitted_by
    p_c048 => null, -- etrip_nbr
    p_c049 => :F200_PARTICIPANT_ID, -- ue,
    p_c050 => sysdate); -- de
    else
    apex_collection.add_member(p_collection_name => 'TRIP_C',
    p_c032 => null, -- state
    p_c033 => null, -- port
    p_c034 => null, -- vessel id
    p_c035 => null, -- trip_start_date
    p_c036 => null, -- trip_start_time
    p_c037 => null, -- trip_end_date
    p_c038 => null, -- trip_end_time
    p_c039 => 'C', -- trip_type
    p_c040 => 'N', -- multiple_fishermen
    p_c041 => :F200_PERMIT_ID, -- cf_permit_id
    p_c042 => 0, -- days_at_sea
    p_c043 => 0, -- nbr_of_crew
    p_c044 => null, -- supplier_trip_id
    p_c045 => 1, -- trip_nbr
    p_c046 => null, -- partner_vtr
    p_c047 => :F200_PARTICIPANT_ID, -- submitted_by
    p_c048 => null, -- etrip_nbr
    p_c049 => :F200_PARTICIPANT_ID, -- ue,
    p_c050 => sysdate); -- de
    end if;
    close fav;
    exception
    when no_data_found then
    null;
    end;
    QUERY:
    select apex_item.checkbox (30,seq_id,
    'onclick="highlight_row(this,' || seq_id ||')"',
    NULL,
    'f30_' || LPAD (seq_id, 4, '0')
    ) delete_checkbox,
    apex_item.hidden (31,seq_id)||
    apex_item.select_list_from_query(32,c032,'select partner_name d, state_code r
    from partners
    where state_code is not null
    order by partner_name',
    'style="width:100px;background-color:#FBEC5D; "'
    ||'onchange="f_set_casc_sel_list_item_port(this,f33_'||LPAD (seq_id, 4,'0')||')"',
    'YES',
    '0',
    '- Select State -',
    'f32_' || LPAD (seq_id,4, '0'),
    NULL,
    'NO'
    ) STATE,
    apex_item.select_list_from_query(33,c033,'select fips_place_name, port
    from valid_ports
    where fips_state = 0 order by fips_place_name',
    'style="width:150px"',
    'YES',
    '0',
    '- Select PORT -',
    'f33_' || LPAD (seq_id, 4, '0'),
    NULL,
    'NO' ) PORT,
    apex_item.POPUP_FROM_LOV(34,c034,'VESSELS',NULL,NULL,NULL,NULL,NULL,
    'style="width:100px;background-color:#FBEC5D; "') vessel_id,
    apex_item.text(35,c035) trip_start_date,
    apex_item.text(36,c036,5) trip_start_time,
    apex_item.text(37,c037) trip_end_date,
    apex_item.text(38,c038,5) trip_end_time,
    apex_item.SELECT_LIST_FROM_LOV(39,c039,'TRIP_TYPE','style="width:100px;background-color:#FBEC5D; "') trip_type,
    apex_item.SELECT_LIST_FROM_LOV(40,c040,'YES_NO',4) multiple_fishermen,
    apex_item.hidden(41,c041) cf_permit_id,
    apex_item.text(42,c042,3) days_at_sea,
    apex_item.text(43,c043,4) nbr_of_crew,
    apex_item.hidden(44,c044) supplier_trip_id,
    apex_item.hidden(45,c045) trip_nbr,
    apex_item.text(46,c046) partner_vtr,
    apex_item.hidden(47,c047) submitted_by,
    apex_item.text(48,c048,10) etrip_nbr,
    apex_item.hidden(49,c049) ue,
    apex_item.hidden(50,c050) de
    from apex_collections where collection_name = 'TRIP_C'
    PROCESS: AFTER SUBMIT : update_trip_collection
    declare
    xtrip number;
    begin
    select trips_seq.nextval into xtrip from dual;
    for x in 1..apex_application.g_f30.COUNT
    loop
    :P300_test:= 'in loop '||x;
    -- if it's an existing record
    IF apex_application.g_f30 (x) IS NOT NULL -- contains SEQ_ID
    THEN
    apex_collection.update_member (p_collection_name=> 'TRIP_C',
    p_seq => apex_application.g_f30(x),
    p_c031 => apex_application.g_f31(x),
    p_c032 => apex_application.g_f32(x),
    p_c033 => apex_application.g_f33(x),
    p_c034 => apex_application.g_f34(x),
    p_c035 => apex_application.g_f35(x),
    p_c036 => apex_application.g_f36(x),
    p_c037 => apex_application.g_f37(x),
    p_c038 => apex_application.g_f38(x),
    p_c039 => apex_application.g_f39(x),
    p_c040 => apex_application.g_f40(x),
    p_c041 => apex_application.g_f41(x),
    p_c042 => apex_application.g_f42(x),
    p_c043 => apex_application.g_f43(x),
    p_c044 => apex_application.g_f44(x),
    p_c045 => apex_application.g_f45(x),
    p_c046 => apex_application.g_f46(x),
    p_c047 => apex_application.g_f47(x),
    p_c048 => xtrip,
    p_c049 => apex_application.g_f49(x),
    p_c050 => apex_application.g_f50(x));
    else
    apex_collection.add_member (p_collection_name=> 'TRIP_C',
    p_c031 => apex_application.g_f31(x),
    p_c032 => apex_application.g_f32(x),
    p_c033 => apex_application.g_f33(x),
    p_c034 => apex_application.g_f34(x),
    p_c035 => apex_application.g_f35(x),
    p_c036 => apex_application.g_f36(x),
    p_c037 => apex_application.g_f37(x),
    p_c038 => apex_application.g_f38(x),
    p_c039 => apex_application.g_f39(x),
    p_c040 => apex_application.g_f40(x),
    p_c041 => apex_application.g_f41(x),
    p_c042 => apex_application.g_f42(x),
    p_c043 => apex_application.g_f43(x),
    p_c044 => apex_application.g_f44(x),
    p_c045 => apex_application.g_f45(x),
    p_c046 => apex_application.g_f46(x),
    p_c047 => apex_application.g_f47(x),
    p_c048 => xtrip,
    p_c049 => apex_application.g_f49(x),
    p_c050 => apex_application.g_f50(x));
    end if;
    end loop;
    end;

    and for the record, I have also tried: (error is 1403 no data found)
    declare
    xtrip number;
    c pls_integer := 0;
    begin
    --select trips_seq.nextval into xtrip from dual;
    for c1 in (select seq_id from apex_collections where collection_name = 'TRIP_C' order by seq_id)
    loop
    c := c+1;
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>1,p_attr_value=>wwv_flow.g_f32(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>2,p_attr_value=>wwv_flow.g_f33(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>3,p_attr_value=>wwv_flow.g_f34(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>4,p_attr_value=>wwv_flow.g_f35(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>5,p_attr_value=>wwv_flow.g_f36(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>6,p_attr_value=>wwv_flow.g_f37(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>7,p_attr_value=>wwv_flow.g_f38(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>8,p_attr_value=>wwv_flow.g_f39(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>9,p_attr_value=>wwv_flow.g_f40(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>10,p_attr_value=>wwv_flow.g_f41(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>11,p_attr_value=>wwv_flow.g_f42(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>12,p_attr_value=>wwv_flow.g_f43(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>13,p_attr_value=>wwv_flow.g_f44(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>14,p_attr_value=>wwv_flow.g_f45(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>15,p_attr_value=>wwv_flow.g_f46(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>16,p_attr_value=>wwv_flow.g_f47(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>17,p_attr_value=>wwv_flow.g_f48(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>18,p_attr_value=>wwv_flow.g_f49(c));
    apex_collection.update_member_attribute (p_collection_name=> 'TRIP_C',
    p_seq=> c1.seq_id,p_attr_number =>19,p_attr_value=>wwv_flow.g_f50(c));
    end loop;
    end;

  • Insert data from source table to destination table dependning up on a criteria.once inserted delete from source table.

    HI,
    I have a source table with millions of records .I need to insert some of the data (depending on a condition) to a repository table.
    Once they are inserted they can be deleted from the source table.
    The deletion is taking a lot of time .
    I need to reduce the time to delete the records.
    ex:-  1 million records in 8 seconds.
    Had already used bulk collect and cursors but cannot succeed.
    Please suggest how to increase the performance.
    Thanks & Regards

    APPROACH 1:-
    CREATE OR REPLACE PROCEDURE SP_BC
    AS
    DETAILS_REC SOURCETBL%ROWTYPE;
    COUNTER NUMBER:=1;
    RCOUNT NUMBER:= 1;
    START_TIME PLS_INTEGER;
    END_TIME PLS_INTEGER;
    CURSOR C1 IS
    SELECT * FROM SOURCETBL WHERE DOJ<SYDATE;
    BEGIN
    START_TIME := DBMS_UTILITY.GET_TIME;
        DBMS_OUTPUT.PUT_LINE(START_TIME/100);
        OPEN C1;
        LOOP
        FETCH C1 INTO DETAILS_ROW;
        EXIT WHEN  C1%NOTFOUND;
               BEGIN
                EXIT WHEN COUNTER >10000;
                INSERT INTO DESTINATIONTBL VALUES DETAILS_REC;
                IF SQL%FOUND THEN
                    DELETE FROM SOURCETABLE WHERE ID= DETAILS_REC.ID;
                  COUNTER:=COUNTER+1;
            END IF; 
        COMMIT;
            END;
         COUNTER:=1;
        END LOOP;
        COMMIT;
    END;
    APPROACH 2:-
        CREATE OR REPLACE PROCEDURE SP_BC1
    IS
    TYPE T_DET IS TABLE OF SOURCETBL%ROWTYPE;
    T_REC T_DET;
    BEGIN   
        SELECT *  BULK COLLECT INTO T_REC FROM SOURCETBL
         WHERE NAME=@NAME;
        FOR I IN  T_REC .FIRST ..T_REC .LAST
           LOOP
             INSERT INTO DESTINATIONTBL VALUES T_REC (I);
          IF SQL%FOUND THEN
          DELETE FROM SOURCETBL WHERE ID =
           WHERE ID = T_REC (I).ID;  
           END IF; 
           EXIT WHEN T_REC=0;
        END LOOP;
        COMMIT;
    END;
    APPROACH 3:-
    CREATE OR REPLACE PROCEDURE SP_BC2
    AS
    TYPE REC_TYPE IS TABLE OF SOURCETBL%ROWTYPE ;
    DETAILS_ROW REC_TYPE;
    CURSOR C1 IS
    SELECT * FROM
         SOURCETBL WHERE END<SYSDATE;
        BEGIN
        OPEN C1;
        LOOP
        FETCH C1 BULK COLLECT INTO DETAILS_ROW LIMIT 999;
        FORALL I IN 1..DETAILS_ROW.COUNT
                  /* A BATCH OF 999 RECORDS WILL BE CONSIDERED FOR DATA MOVEMENT*/
    INSERT INTO DESTINATIONTBL VALUES DETAILS_ROW(I);
    --            IF SQL%FOUND  THEN
    --                DELETE from SOURCETBL WHERE ID IN DETAILS_ROW(I).ID;
    --           END IF;
            EXIT WHEN  C1%NOTFOUND; 
        COMMIT;   
        END LOOP;
        COMMIT;
    3rd approach seems better but i have an issue with referring the fileds of a record type.

Maybe you are looking for