How to use bulk insert in utl_file

i am creating text file of employee list i go huge data i want to use bulk insert with utl_file is it possible if so, how pls help me.

If what you are asking, in some unknown version of Oracle, is whether using FORALL will increase the speed for writing a file to your hard disk the answer is no.
BULK COLLECT, however, might help.

Similar Messages

  • How to use BULK INSERT for a data from a cursor?

    Oracle 10G enterprise edition.
    I tried to Bulk insert datas returning from a cursor, its returning error.
    PLS-00302: component 'LAST' must be declared
    I need some help to use the Bulk INSERT here.Can any one help me to specify what error i have made?
    CREATE OR REPLACE PROCEDURE HOT_ADMIN.get_search_keyword_stats_prc
    IS
    CURSOR c_get_scenarios
    IS
    SELECT a.*,ROWNUM rnum
    FROM (
    SELECT TRUNC(r.search_date) sdate,
    r.search_hits hits,
    r.search_type stype,
    r.search_qualification qual,
    r.search_location loc,
    r.search_town stown,
    r.search_postcode pcode,
    r.search_college college,
    r.search_colname colname,
    r.search_text text,
    r.affiliate_id affiliate,
    r.search_study_mode smode,
    r.location_hint hint,
    r.search_posttown ptown,
    COUNT(1) cnt
    FROM w_search_headers r
    WHERE search_text IS NOT NULL
    AND NVL(search_type,' ') <> 'C'
    AND TRUNC(search_date)= TO_DATE(TO_CHAR(SYSDATE-1,'DD-MON-RRRR'))
    GROUP BY TRUNC(r.search_date),
    r.search_hits,
    r.search_type,
    r.search_qualification,
    r.search_location,
    r.search_town,
    r.search_postcode,
    r.search_college,
    r.search_colname,
    r.search_text,
    r.affiliate_id,
    r.search_study_mode,
    r.location_hint,
    r.search_posttown
    ORDER BY cnt desc
    ) a
    WHERE ROWNUM <=1000;
    lc_get_data c_get_scenarios%ROWTYPE;
    BEGIN
    OPEN c_get_scenarios;
    FETCH c_get_scenarios into lc_get_data;
    CLOSE c_get_scenarios;
    FORALL i IN 1..lc_get_data.last
    INSERT INTO W_SEARCH_SCENARIO_STATS VALUES ( i.sdate,
    i.hits,
    i.stype,
    i.qual,
    i.loc,
    i.stown,
    i.pcode,
    i.college,
    i.colname,
    i.text,
    i.affiliate,
    i.smode,
    i.hint,
    i.ptown,
    i.cnt
    COMMIT;
    END;

    This isn't what you asked, but I've generally found it helpful to list the columns in an INSERT statement before the values. It is of course optional, but useful for reference when looking at the statement later

  • Is there a way to dynamically figure out the FIRSTROW & LASTROW using Bulk Insert?

    I noticed most of my files follow a certain convention, so I can use Bulk Insert with this:
    FIRSTROW = 2, LASTROW = 224
    However a few files have many more records.  I'd like SQL Server to dynamically figure out the first and last rows with data, but I don't know if that's possible.  Can someone confirm?
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Nope, you would need read the files from some program. Could be a CLR stored procedure if you want to do it from SQL Server. But from BULK INSERT alone, no.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • If your database in Full Recovery mode, can you use Bulk Insert Task to load data

    If your database in Full Recovery mode, can you use Bulk Insert Task to load data

    If your database in Full Recovery mode, can you use Bulk Insert Task to load data
    Yes you can ofourse but dont be in idea that logging will be mininal. Loggign will be as per recovery model full. Every thing will be logged. If you are going to use bulk insert task you can consider switching recovery model to Bulk logged but you will not
    have option to do point in time recovery.
    PS: please dont create duplicate threads
    If you read first Note section in below link it clearly states that yes logging will be full and you can use
    http://technet.microsoft.com/en-us/library/ms191244(v=sql.105).aspx
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

  • How to use BULK COLLECT, FORALL and TREAT

    There is a need to read match and update data from and into a custom table. The table would have about 3 millions rows and holds key numbers. BAsed on a field value of this custom table, relevant data needs to be fetched from joins of other tables and updated in the custom table. I plan to use BULK COLLECT and FORALL.
    All examples I have seen, do an insert into a table. How do I go about reading all values of a given field and fetching other relevant data and then updating the custom table with data fetched.
    Defined an object with specifics like this
    CREATE OR REPLACE TYPE imei_ot AS OBJECT (
    recid NUMBER,
    imei VARCHAR2(30),
    STORE VARCHAR2(100),
    status VARCHAR2(1),
    TIMESTAMP DATE,
    order_number VARCHAR2(30),
    order_type VARCHAR2(30),
    sku VARCHAR2(30),
    order_date DATE,
    attribute1 VARCHAR2(240),
    market VARCHAR2(240),
    processed_flag VARCHAR2(1),
    last_update_date DATE
    Now within a package procedure I have defined like this.
    type imei_ott is table of imei_ot;
    imei_ntt imei_ott;
    begin
    SELECT imei_ot (recid,
    imei,
    STORE,
    status,
    TIMESTAMP,
    order_number,
    order_type,
    sku,
    order_date,
    attribute1,
    market,
    processed_flag,
    last_update_date
    BULK COLLECT INTO imei_ntt
    FROM (SELECT stg.recid, stg.imei, cip.store_location, 'S',
    co.rtl_txn_timestamp, co.rtl_order_number, 'CUST',
    msi.segment1 || '.' || msi.segment3,
    TRUNC (co.txn_timestamp), col.part_number, 'ZZ',
    stg.processed_flag, SYSDATE
    FROM custom_orders co,
    custom_order_lines col,
    custom_stg stg,
    mtl_system_items_b msi
    WHERE co.header_id = col.header_id
    AND msi.inventory_item_id = col.inventory_item_id
    AND msi.organization_id =
    (SELECT organization_id
    FROM hr_all_organization_units_tl
    WHERE NAME = 'Item Master'
    AND source_lang = USERENV ('LANG'))
    AND stg.imei = col.serial_number
    AND stg.processed_flag = 'U');
    /* Update staging table in one go for COR order data */
    FORALL indx IN 1 .. imei_ntt.COUNT
    UPDATE custom_stg
    SET STORE = TREAT (imei_ntt (indx) AS imei_ot).STORE,
    status = TREAT (imei_ntt (indx) AS imei_ot).status,
    TIMESTAMP = TREAT (imei_ntt (indx) AS imei_ot).TIMESTAMP,
    order_number = TREAT (imei_ntt (indx) AS imei_ot).order_number,
    order_type = TREAT (imei_ntt (indx) AS imei_ot).order_type,
    sku = TREAT (imei_ntt (indx) AS imei_ot).sku,
    order_date = TREAT (imei_ntt (indx) AS imei_ot).order_date,
    attribute1 = TREAT (imei_ntt (indx) AS imei_ot).attribute1,
    market = TREAT (imei_ntt (indx) AS imei_ot).market,
    processed_flag =
    TREAT (imei_ntt (indx) AS imei_ot).processed_flag,
    last_update_date =
    TREAT (imei_ntt (indx) AS imei_ot).last_update_date
    WHERE recid = TREAT (imei_ntt (indx) AS imei_ot).recid
    AND imei = TREAT (imei_ntt (indx) AS imei_ot).imei;
    DBMS_OUTPUT.put_line ( TO_CHAR (SQL%ROWCOUNT)
    || ' rows updated using Bulk Collect / For All.'
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    DBMS_OUTPUT.put_line ('No Data: ' || SQLERRM);
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Other Error: ' || SQLERRM);
    END;
    Now for the unfortunate part. When I compile the pkg, I face an error
    PL/SQL: ORA-00904: "LAST_UPDATE_DATE": invalid identifier
    I am not sure where I am wrong. Object type has the last update date field and the custom table also has the same field.
    Could someone please throw some light and suggestion?
    Thanks
    uds

    I suspect your error comes from the »bulk collect into« and not from the »forall loop«.
    From a first glance you need to alias sysdate with last_update_date and some of the other select items need to be aliased as well :
    But a simplified version would be
    select imei_ot (stg.recid,
                    stg.imei,
                    cip.store_location,
                    'S',
                    co.rtl_txn_timestamp,
                    co.rtl_order_number,
                    'CUST',
                    msi.segment1 || '.' || msi.segment3,
                    trunc (co.txn_timestamp),
                    col.part_number,
                    'ZZ',
                    stg.processed_flag,
                    sysdate
    bulk collect into imei_ntt
      from custom_orders co,
           custom_order_lines col,
           custom_stg stg,
           mtl_system_items_b msi
    where co.header_id = col.header_id
       and msi.inventory_item_id = col.inventory_item_id
       and msi.organization_id =
                  (select organization_id
                     from hr_all_organization_units_tl
                    where name = 'Item Master' and source_lang = userenv ('LANG'))
       and stg.imei = col.serial_number
       and stg.processed_flag = 'U';
    ...

  • How to use Bulk Collect and Forall

    Hi all,
    We are on Oracle 10g. I have a requirement to read from table A and then for each record in table A, find matching rows in table B and then write the identified information in table B to the target table (table C). In the past, I had used two ‘cursor for loops’ to achieve that. To make the new procedure, more efficient, I would like to learn to use ‘bulk collect’ and ‘forall’.
    Here is what I have so far:
    DECLARE
    TYPE employee_array IS TABLE OF EMPLOYEES%ROWTYPE;
    employee_data  employee_array;
    TYPE job_history_array IS TABLE OF JOB_HISTORY%ROWTYPE;
    Job_history_data   job_history_array;
    BatchSize CONSTANT POSITIVE := 5;
    -- Read from File A
    CURSOR c_get_employees IS
             SELECT  Employee_id,
                       first_name,
                       last_name,
                       hire_date,
                       job_id
              FROM EMPLOYEES;
    -- Read from File B based on employee ID in File A
    CURSOR c_get_job_history (p_employee_id number) IS
             select start_date,
                      end_date,
                      job_id,
                      department_id
             FROM JOB_HISTORY
             WHERE employee_id = p_employee_id;
    BEGIN
        OPEN c_get_employees;
        LOOP
            FETCH c_get_employees BULK COLLECT INTO employee_data.employee_id.LAST,
                                                                              employee_data.first_name.LAST,
                                                                              employee_data.last_name.LAST,
                                                                              employee_data.hire_date.LAST,
                                                                              employee_data.job_id.LAST
             LIMIT BatchSize;
            FORALL i in 1.. employee_data.COUNT
                    Open c_get_job_history (employee_data(i).employee_id);
                    FETCH c_get_job_history BULKCOLLECT INTO job_history_array LIMIT BatchSize;
                             FORALL k in 1.. Job_history_data.COUNT LOOP
                                            -- insert into FILE C
                                              INSERT INTO MY_TEST(employee_id, first_name, last_name, hire_date, job_id)
                                                                values (job_history_array(k).employee_id, job_history_array(k).first_name,
                                                                          job_history_array(k).last_name, job_history_array(k).hire_date,
                                                                          job_history_array(k).job_id);
                                             EXIT WHEN job_ history_data.count < BatchSize                        
                             END LOOP;                          
                             CLOSE c_get_job_history;                          
                     EXIT WHEN employee_data.COUNT < BatchSize;
           END LOOP;
            COMMIT;
            CLOSE c_get_employees;
    END;
                     When I run this script, I get
    [Error] Execution (47: 17): ORA-06550: line 47, column 17:
    PLS-00103: Encountered the symbol "OPEN" when expecting one of the following:
       . ( * @ % & - + / at mod remainder rem select update with
       <an exponent (**)> delete insert || execute multiset save
       merge
    ORA-06550: line 48, column 17:
    PLS-00103: Encountered the symbol "FETCH" when expecting one of the following:
       begin function package pragma procedure subtype type use
       <an identifier> <a double-quoted delimited-identifier> form
       current cursorWhat is the best way to code this? Once, I learn how to do this, I apply the knowledge to the real application in which file A would have around 200 rows and file B would have hundreds of thousands of rows.
    Thank you for your guidance,
    Seyed

    Hello BlueShadow,
    Following your advice, I modified a stored procedure that initially was using two cursor for loops to read from tables A and B to write to table C to use instead something like your suggestion listed below:
    INSERT INTO tableC
    SELECT …
    FROM tableA JOIN tableB on (join condition).I tried this change on a procedure writing to tableC with keys disabled. I will try this against the real table that has primary key and indexes and report the result later.
    Thank you very much,
    Seyed

  • Using Bulk insert or SQL Loader in VB6

    Hi,
    I am quite new to the Oracle world and also forums. But I am looking for some directions in how i get a dataset of 10000 records into a table the quickest way. I have the recordset in an ADO Recordset (or a textfile if that is easier) and I want to insert them in an empty Oracle table. The problem is - I don't know how to.
    Situation
    The Oracle DB is on another computer I have nothing special installed on the computer running the VB6 application.
    Can anyone please provide code example or guidelines...
    Regards,
    Christian

    This may not be "bulk insert" by your definition, but it can transfer data as you want.
    A simple VB code for demo purpose:
    Dim con As New ADODB.Connection
    Dim con2 As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim rst2 As New ADODB.Recordset
    Dim rst3 As New ADODB.Recordset
    con.ConnectionString = "Provider=OraOLEDB.Oracle.1;User ID=scott;Password=tiger;Data Source=db_one;"
    con.Open
    rst.Open "select * from dept", con, adOpenDynamic, adLockOptimistic
    'save to a file using ADTG format. You may choose other format.
    rst.Save "c:\myfile.txt", adPersistADTG
    'dept2 is an empty table with the same table definition as dept. You can create it using SQL*Plus.
    'add rows by reading from the saved file.
    con2.ConnectionString = "Provider=OraOLEDB.Oracle.1;User ID=xyz;Password=xyz;Data Source=db_two;"
    con2.Open
    'open the saved file
    rst2.Open "c:\myfile.txt"
    'rst3 is an empty recordset because dept2 is empty at this time.
    rst3.Open "select * from dept2", con2, adOpenDynamic, adLockOptimistic
    'adding rows into dept2.
    Do Until rst2.EOF
    rst3.AddNew Array("deptno", "dname", "loc"), Array(rst2.Fields("deptno"), rst2.Fields("dname"), rst2.Fields("loc"))
    rst2.MoveNext
    Loop
    rst.Close
    rst2.Close
    rst3.Close
    con.Close
    con2.Close
    Sinclair

  • How to change Bulk Insert statement from MS SQL to Oracle

    Hi All,
    Good day, I would like to bulk insert the content of a file into Oracle db. May I know how to change the below MS SQL syntax to Oracle syntax?
    Statement statement = objConnection.createStatement();
    statement.execute("BULK INSERT [TBL_MERCHANT] FROM '" MERCHANT_FILE_DIR "' WITH ( FIELDTERMINATOR = '~~', ROWTERMINATOR = '##' )");
    Thanks in advance.
    cs.

    Oracle SQL Loader utility allows you to insert data from flat file to database tables.
    Go to SQL Loader links on following url to learn more on this utility
    http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/server.920/a96652/toc.htm
    Chandar

  • How to use BULK COLLECT in Oracle Forms 11g

    Forms is showing error that "Feature is not support in Client Side Program" when i am trying to impliment Bulk collect in Forms 11g.
    i need to load full data from DB to my form becuase using cursor is very slow....
    Is there any method/Work around to achieve this ....

    declare
    type arr is table of emp%rowtype ;
    lv_arr arr;
    begin
    select * bulk collect in to lv_arr from emp;
    /*written code here to process the data and write in to file*/
    end;Unless you are inserting/updating the data you are holding in the array into a database table I don't think there is much peformance gain in using bulk-collect in conjunction with writing a file. Bulk processing will increase performance by minimizing context switches from the SQL to the PL/SQL engine, nothing more, nothing less.
    In any case bulk processing is not available in forms, if you really need to make use of it you need to do it in a stored procedure.
    cheers

  • How to use BULK COLLECT in oracle forms

    hi gurus,
    I am using oracle forms
    Forms [32 Bit] Version 10.1.2.0.2 (Production)
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionI wanna use bulk collect from database table lets say <employees>
    while working on database level with collections and records it's working very well for me, but when I try to use that technique on oracle forms it hits me error
    error 591 this feature is not supported in client side programmingI know I can use cursors to loop through the records of oracle tables ,
    but I'm convenient while using collections and arrays
    for example
    Set Serveroutput On
    Declare
          Type Rec_T Is Record (     
           Empid Number ,
           Empname Varchar2(100)
          Type V_R Is Table Of Rec_T Index By Binary_Integer;     
          V_Array V_R;
    Begin
       Select Employee_Id , First_Name
       Bulk Collect
       Into V_Array
          From Employees; 
       For Indx In V_Array.First..V_Array.Last Loop
       Dbms_Output.Put_Line('employees id '||V_Array(Indx).Empid ||'and the name is '||V_Array(Indx).Empname);
       End Loop;      
         End;I wanna use this same way on oracle forms , for certain purposes , please guide me how can I use ...
    thanks...

    For information, you can use and populate a collection within the Forms application without using the BULK COLLECT
    Francoisactually I want to work with arrays , index tables ,
    like
             record_type (variable , variable2);
             type type_name <record_type>  index by binary_integer
            type_variable type_name;
            and in main body of program
            select something
            bulk collect into type_variable
            from any_table;
           loop
                type_variable(indx).variable , type_variable(indx).variable2;
           end loop;
           this is very useful for my logic on which I am working
              like
              type_variable(indx).variable || type_variable(indx-1);
             if it's possible with cursors then how can I use cursor that can fullfill my this logic@Francois
    if it's possible then how can i populate without using bulk collect?
    thanks
    and for others replies: if I can use stored procedures please give me any example..
    thanks

  • How to debug bulk insert?

    I have this code which doesn't cause any error, and actually gives message 'query executed successfully', but it doesn't load any data.
    bulk insert [dbo].[SPGT]
    from '\\sys.local\london-sql\FTP\20140210_SPGT.SPL'
    WITH (
    KEEPNULLS,
    FIRSTROW=5,
    FIELDTERMINATOR='\t',
    ROWTERMINATOR='\n'
    How can I debug the issue, or see what the script is REALLY doing?  It's not doing what I think it's doing.
    All permissions, rights, etc are setup correctly.  I just run the code successfully with a .txt file.  Maybe it has something to do with the extension...
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Yes, here is the final solution (for the benefit of others who find this anytime in the future). 
    CREATE
    TABLE [dbo].[ICM]
    Date  DATETIME,
    Type  VARCHAR(MAX),
    Change      VARCHAR(MAX),
    SP_ID VARCHAR(MAX),
    Sedol VARCHAR(MAX),
    Cusip VARCHAR(MAX),
    Issue_Name  VARCHAR(MAX),
    Cty   VARCHAR(MAX),
    PE    VARCHAR(MAX),
    Cap_Range   VARCHAR(MAX),
    GICS  VARCHAR(MAX),
    Curr  VARCHAR(MAX),
    Local_Price DECIMAL(19,8),
    Index_Total_Shares      DECIMAL(19,8),
    IWF   DECIMAL(19,8),
    Index_Curr  VARCHAR(MAX),
    Float_MCAP  DECIMAL(19,8),
    Total_MCAP  DECIMAL(19,8),
    Daily_Price_Rtn   DECIMAL(19,8),
    Daily_Total_Rtn   DECIMAL(19,8),
    FX_Rate     DECIMAL(19,8),
    Growth_Weight     DECIMAL(19,8),
    Value_Weight      DECIMAL(19,8),
    Bloomberg_ID      VARCHAR(MAX),
    RIC   VARCHAR(MAX),
    Exchange_Ticker   VARCHAR(MAX),
    ISIN  VARCHAR(MAX),
    SSB_ID      VARCHAR(MAX),
    REIT_Flag   VARCHAR(MAX),
    Weight     
    DECIMAL(19,8),
    Shares      DECIMAL(19,8)
     bulk
    insert dbo.ICM
     from
    'C:\Documents and Settings\london\Desktop\ICM.txt'
     WITH
     FIRSTROW
    = 2,
     FIELDTERMINATOR
    = ',',
     ROWTERMINATOR
    = '\n'
     GO
    This was a bit confusing at first, because I've never done it before, and also, I was getting all kinds of errors, which turned out to be numbers in string fields and strings in number fields.  Basically, the data that was given to me was totally screwed
    up.  That compounded the problem exponentially.  I finally got the correct data, and I'm all set now.
    Thanks everyone!
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • How to use BULK COLLECT in ref cursor?

    hi,
    can we use bulk collect in ref cursor ? if yes then please give small example ..
    thanks

    Try this:
    create or replace type person_ot as object (name varchar2(10)) not final;
    create or replace type student_ot under person_ot (s_num number) not final;
    create type person_tt as table of person_ot;
    create table persons of person_ot;
    declare
    lv_person_list person_tt;
    lv_sql varchar2(1000);
    ref_cur sys_refcursor;
    begin
    lv_sql:= 'select new student_ot(''fred'', 100) from dual
    union all
    select new student_ot(''sally'', 200) from dual';
    open ref_cur for lv_sql;
    fetch ref_cur bulk collect into lv_person_list;
    close ref_cur;
    for i in lv_person_list.first..lv_person_list.last loop
    dbms_output.put_line(lv_person_list(i).name );
    end loop;
    forall i in lv_person_list.first..lv_person_list.last
    insert into persons values lv_person_list(i);
    end;
    /

  • File access problem while using BULK INSERT

    I'm creating a script to automatically convert a large mess of data.  Here's a test query I was using to bring a file into the database:
    INSERT [ImportTestTable]
    SELECT a.*
    FROM
    OPENROWSET(
    BULK 'D:\TestFile.csv',
    FORMATFILE = 'D:\TestStyle.fmt',
    FIRSTROW = 2
    ) AS a;
    SELECT * FROM ImportTestTable
    I've used queries like this on other networks and machines before, but when I run that query on the particular machine I'm working with now, I get the following error:
    Msg 4861, Level 16, State 1, Line 13
    Cannot bulk load because the file "D:\TestFile.csv" could not be opened. Operating system error code 21
    (The device is not ready.).
    Here's some relevant facts I can think of that might help:
    I am running the query from SQL Server Management Studio on a remote machine running Windows 7 Ultimate.  I am connected to this server using SQL authentication.  I believe we are on the same domain / network.  I am not the DBA.  I do
    have the permission "Administer Bulk Operations" explicitly granted to me by the DBA.  The user I am currently logged in as in windows is capable of opening, editing, and saving the file in windows explorer.  The format file is a NON-XML
    format file.
    Any pointers as to where to look for more detailed information would be greatly appreciated!

    I know this is a little old by now, but this is what I used just this week:
    bulk insert [dbo].[Test_Table]
    from 'C:\Documents and Settings\rshuell\Desktop\Test_File.txt'
    WITH (
    FIELDTERMINATOR=',',
    ROWTERMINATOR = '\n',
    KEEPNULLS,
    FIRSTROW=2
    That worked fine for me.
    Of course, we Naomi stated, the file has to be ON THE SERVER.  Or, if you're using an FTP site, for instance, the path would have to point to the FTP site.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • How to use bulk collect into clause

    hi all,
    i have requirement like this i want to change the query by passing the different table names in oracle database 10gr2.
    like if i use first i pass the scott.emp table name select * from scott.emp;
    then i want pass scott.dept table name select * from scott.dept;
    using select * option in the select list.
    how can i execute it.
    give me any solution.
    please reply....

    Hi,
    i recently also ran into some serious trouble to make dynamic sql work.
    It was about parallel pipelined function with strongly typed cursor (for "partition ... by hash(...)").
    But in addition requiring dynamic SQL for the input to this cursor.
    I couldn't make it work with execute immediate or something else.
    So i used another way - I translated dynamic SQL into dynamically created static SQL:
    1. create a base SQL data object type with abstract interface for code (e.g. some Execute() member function).
    2. dynamically create a derived SQL data object type with concrete implementation of Execute() holding your "dynamic SQL" "in a static way"
    3. delegate to Execute().
    Let me quote my example from comp.databases.oracle.server, thread "dynamically created cursor doesn't work for parallel pipelined functions"
    - pls. see below (it's an old one - with likely some odd stuff inside).
    It might sound some kind of strange for DB programmer.
    (I come from C++. Though this is not an excuse smile)
    Maybe i just missed another possible option to handle the problem.
    And it's a definitely verbose.
    But i think it's at least a (last) option.
    Actually i would be interested to hear, what others think about it.
    best regards,
    Frank
    --------------- snip -------------------------
    drop table parallel_test;
    drop type MyDoit;
    drop type BaseDoit;
    drop type ton;
    create type ton as table of number;
    CREATE TABLE parallel_test (
    id NUMBER(10),
    description VARCHAR2(50)
    BEGIN
    FOR i IN 1 .. 100000 LOOP
    INSERT INTO parallel_test (id, description)
    VALUES (i, 'Description or ' || i);
    END LOOP;
    COMMIT;
    END;
    create or replace type BaseDoit as object (
    id number,
    static function make(p_id in number)
    return BaseDoit,
    member procedure doit(
    p_sids in out nocopy ton,
    p_counts in out nocopy ton)
    ) not final;
    create or replace type body BaseDoit as
    static function make(p_id in number)
    return BaseDoit
    is
    begin
    return new BaseDoit(p_id);
    end;
    member procedure doit(
    p_sids in out nocopy ton,
    p_counts in out nocopy ton)
    is
    begin
    dbms_output.put_line('BaseDoit.doit(' || id || ') invoked...');
    end;
    end;
    -- Define a strongly typed REF CURSOR type.
    CREATE OR REPLACE PACKAGE parallel_ptf_api AS
    TYPE t_parallel_test_row IS RECORD (
    id1 NUMBER(10),
    desc1 VARCHAR2(50),
    id2 NUMBER(10),
    desc2 VARCHAR2(50),
    sid NUMBER
    TYPE t_parallel_test_tab IS TABLE OF t_parallel_test_row;
    TYPE t_parallel_test_ref_cursor IS REF CURSOR RETURN
    t_parallel_test_row;
    FUNCTION test_ptf (p_cursor IN t_parallel_test_ref_cursor)
    RETURN t_parallel_test_tab PIPELINED
    PARALLEL_ENABLE(PARTITION p_cursor BY any);
    END parallel_ptf_api;
    SHOW ERRORS
    CREATE OR REPLACE PACKAGE BODY parallel_ptf_api AS
    FUNCTION test_ptf (p_cursor IN t_parallel_test_ref_cursor)
    RETURN t_parallel_test_tab PIPELINED
    PARALLEL_ENABLE(PARTITION p_cursor BY any)
    IS
    l_row t_parallel_test_row;
    BEGIN
    LOOP
    FETCH p_cursor
    INTO l_row;
    EXIT WHEN p_cursor%NOTFOUND;
    select userenv('SID') into l_row.sid from dual;
    PIPE ROW (l_row);
    END LOOP;
    RETURN;
    END test_ptf;
    END parallel_ptf_api;
    SHOW ERRORS
    PROMPT
    PROMPT Serial Execution
    PROMPT ================
    SELECT sid, count(*)
    FROM TABLE(parallel_ptf_api.test_ptf(CURSOR(SELECT t1.id,
    t1.description, t2.id, t2.description, null
    FROM parallel_test t1,
    parallel_test t2
    where t1.id = t2.id
    ) t2
    GROUP BY sid;
    PROMPT
    PROMPT Parallel Execution
    PROMPT ==================
    SELECT sid, count(*)
    FROM TABLE(parallel_ptf_api.test_ptf(CURSOR(SELECT /*+
    parallel(t1,5) */ t1.id, t1.description, t2.id, t2.description, null
    FROM parallel_test t1,
    parallel_test t2
    where t1.id = t2.id
    ) t2
    GROUP BY sid;
    PROMPT
    PROMPT Parallel Execution 2
    PROMPT ==================
    set serveroutput on;
    declare
    v_sids ton := ton();
    v_counts ton := ton();
    -- v_cur parallel_ptf_api.t_parallel_test_ref_cursor;
    v_cur sys_refcursor;
    procedure OpenCursor(p_refCursor out sys_refcursor)
    is
    begin
    open p_refCursor for 'SELECT /*+ parallel(t1,5) */ t1.id,
    t1.description, t2.id, t2.description, null
    FROM parallel_test t1,
    parallel_test t2
    where t1.id = t2.id';
    end;
    begin
    OpenCursor(v_cur);
    SELECT sid, count(*) bulk collect into v_sids, v_counts
    FROM TABLE(parallel_ptf_api.test_ptf(v_cur)) t2
    GROUP BY sid;
    for i in v_sids.FIRST.. v_sids.LAST loop
    dbms_output.put_line (v_sids(i) || ', ' || v_counts(i));
    end loop;
    end;
    PROMPT
    PROMPT Parallel Execution 3
    PROMPT ==================
    set serveroutput on;
    declare
    instance BaseDoit;
    v_sids ton := ton();
    v_counts ton := ton();
    procedure CreateMyDoit
    is
    cmd varchar2(4096 char);
    begin
    cmd := 'create or replace type MyDoit under BaseDoit ( ' ||
    ' static function make(p_id in number) ' ||
    ' return MyDoit, ' ||
    ' overriding member procedure doit( ' ||
    ' p_sids in out nocopy ton, ' ||
    ' p_counts in out nocopy ton) ' ||
    execute immediate cmd;
    cmd := 'create or replace type body MyDoit as ' ||
    ' static function make(p_id in number) ' ||
    ' return MyDoit ' ||
    ' is ' ||
    ' begin ' ||
    ' return new MyDoit(p_id); ' ||
    ' end; ' ||
    ' ' ||
    ' overriding member procedure doit( ' ||
    ' p_sids in out nocopy ton, ' ||
    ' p_counts in out nocopy ton) ' ||
    ' is ' ||
    ' begin ' ||
    ' dbms_output.put_line(''MyDoit.doit('' || id || '')
    invoked...''); ' ||
    ' SELECT sid, count(*) bulk collect into p_sids, p_counts ' ||
    ' FROM TABLE(parallel_ptf_api.test_ptf(CURSOR( ' ||
    ' SELECT /*+ parallel(t1,5) */ t1.id, t1.description,
    t2.id, t2.description, null ' ||
    ' FROM parallel_test t1, parallel_test t2 ' ||
    ' where t1.id = t2.id ' ||
    ' ))) ' ||
    ' GROUP BY sid; ' ||
    ' end; ' ||
    ' end; ';
    execute immediate cmd;
    end;
    begin
    CreateMyDoit;
    execute immediate 'select MyDoit.Make(11) from dual' into instance;
    instance.doit(v_sids, v_counts);
    if v_sids.COUNT > 0 then
    for i in v_sids.FIRST.. v_sids.LAST loop
    dbms_output.put_line (v_sids(i) || ', ' || v_counts(i));
    end loop;
    end if;
    end;
    --------------- snap -------------------------

  • How to use bulk in multiple cursors !!

    Hello All,
    I am having a following program that perfectly runs but its taking very huge time to complete it.
    Can any one suggest how i can improve the performace of this code ..
    thanks in advance - appreciate your help .
    Here's the program.
    ==============
    procedure Proc_Fmly_VehicleTA_Cnt is
    CURSOR c_cur_fmly IS SELECT FAMID, NUM_AUTO, NUM_TVAN, VEHQ, VEHQL FROM FMLY;
    CURSOR c_cur_eovb_auto IS SELECT FAMID, VEHICIB ,VEHICYB FROM EOVB WHERE VEHICYB = gv_eovb_vehicyb_automobiles ;
    CURSOR c_cur_eovb_trucks IS SELECT FAMID, VEHICIB ,VEHICYB FROM EOVB WHERE VEHICYB = gv_eovb_vehicyb_trucks ;
    v_total_automobiles number := 0 ;
    v_total_trucks number := 0 ;
    v_procedure errorlog.procedure_name%TYPE default 'Proc_Fmly_VehicleTA_Cnt';
    v_location errorlog.location%TYPE;
    BEGIN
    v_location := 4 ;
    -- global variables gv_eovb_vehicyb_automobiles = 100 gv_eovb_vehicyb_trucks = 110
    -- <<Computing the owned vehicles - automobiles >>
    -- INNER BLOCK
    BEGIN
    FOR i IN c_cur_fmly LOOP
    FOR j IN c_cur_eovb_auto LOOP
    IF ( i.FAMID = j.FAMID ) THEN
    v_total_automobiles := v_total_automobiles + chk_notnull_blank( j.vehicib);
    END IF;
    END LOOP ;
    UPDATE FMLY SET NUM_AUTO = v_total_automobiles WHERE famid = i.famid ;
    v_total_automobiles := 0;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    v_err_code := SQLCODE;
    v_err_msg := substr(SQLERRM, 1, 200);
    INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
    error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package => 'PKG_FCI_APP',p_procedure => 'Proc_Fmly_VehicleTA_Cnt' , p_location => v_location);
    END;
    -- <<Computing the owned vehicles - trucks >>
    -- INNER BLOCK
    BEGIN
    FOR i IN c_cur_fmly LOOP
    FOR j IN c_cur_eovb_trucks LOOP
    IF ( i.FAMID = j.FAMID ) THEN
    v_total_trucks := v_total_trucks + chk_notnull_blank( j.vehicib);
    END IF;
    END LOOP ;
    UPDATE FMLY SET NUM_TVAN = v_total_trucks WHERE famid = i.famid ;
    v_total_trucks := 0;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    v_err_code := SQLCODE;
    v_err_msg := substr(SQLERRM, 1, 200);
    INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
    error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package => 'PKG_FCI_APP',p_procedure => 'Proc_Fmly_Vehicle_Cnt' , p_location => v_location);
    END;
    -- END OUTER BLOCK
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    v_err_code := SQLCODE;
    v_err_msg := substr(SQLERRM, 1, 200);
    INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
    error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package => 'PKG_FCI_APP',p_procedure => 'Proc_Fmly_VehicleTA_Cnt ', p_location => v_location);
    END Proc_Fmly_VehicleTA_Cnt;
    -- ignore error_logging procedure ; its a part of package.
    thanks/kumar
    Edited by: kumar73 on Sep 17, 2010 9:36 AM
    Edited by: kumar73 on Sep 17, 2010 9:37 AM

    btw your exception handler has a couple of problems (I've formatted it for you):
    EXCEPTION
       WHEN OTHERS THEN
          RAISE_APPLICATION_ERROR
          ( -20001, 'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM );
          v_err_code := SQLCODE;
          v_err_msg  := SUBSTR(SQLERRM, 1, 200);
          INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
          error_logging
          ( p_error_code => substr(sqlerrm,1,9)
          , p_error_message => substr(sqlerrm,12)
          , p_package => 'PKG_FCI_APP'
          , p_procedure => 'Proc_Fmly_VehicleTA_Cnt'
          , p_location => v_location ); When RAISE_APPLICATION_ERROR raises the exception, the procedure will terminate and the error logging steps below it won't get called.
    Also if you just want to re-raise an exception without adding any information or your own message etc, then you should use RAISE, not RAISE_APPLICATION_ERROR. If you're going to use RAISE_APPLICATION_ERROR it should be something like:
    RAISE_APPLICATION_ERROR
    ( -20001
    , 'Could not set automobile count to ' || v_total_automobiles || ' for family ' || i.famid
    , TRUE );Notice the last parameter, TRUE, which tells it to keep the existing error stack (i.e. whatever Oracle error made it fail), which will then appear underneath your custom error message. You should never concatenate SQLERRM into a RAISE_APPLICATION_ERROR message. (And SQLCODE is just the error number that is already part of SQLERRM so there is no point including that anyway.)
    Those changes give you something like:
    EXCEPTION
       WHEN OTHERS THEN
          INSERT INTO audit_table (error_number, error_message)
          VALUES (SQLCODE, SUBSTR(SQLERRM,1,200));  -- btw why SUBSTR? Why not log the entire message?
          error_logging
          ( p_error_code => substr(sqlerrm,1,9)
          , p_error_message => substr(sqlerrm,12)
          , p_package => 'PKG_FCI_APP'
          , p_procedure => 'Proc_Fmly_VehicleTA_Cnt'
          , p_location => v_location );
          RAISE_APPLICATION_ERROR
          ( -20001
          , 'Could not set automobile count to ' || v_total_automobiles || ' for family ' || i.famid
          , TRUE );

Maybe you are looking for

  • Library access

    Had to restore OS because of virus - error message: the file "iTunes Library.itl" cannot be read because it was created by a newer version of iTunes. Any way to restore? Thanks.

  • Resource Bundle var unknown in task flow

    Hello everyone, I'm using a resource bundle in my web-app. This is the entry in the faces-config.xml file: <resource-bundle>       <base-name>oracle.bundles.CustomUIBundle</base-name>       <var>bundle</var> </resource-bundle> When I use the EL expre

  • Running a Report

    hi, we have converted our Forms3.0 to Forms6i, some of these run reports from a trigger. the old command was acadhist := 'runrep ReportA paramform=yes reg_num=' | | TO_CHAR (:stud_m.reg_no ) ; host (acadhist ) ; which worked fine. in Forms 6i i am tr

  • Whitelist for dynamic destination SM59

    Hi All, In SM59 screen, i see an red alert symbol No RFC call back check (rfc/callback_security_method undefined). Also an entry Whitelist for dynamic destination What are these entries? Is this required? Can these entries(Whitelist) be removed from

  • I would like someone to tell me how to use the dstp address parameter(url) in the datasocket connections.What to write in there, destination/source url.

    What do i do if i right to a datasocket..Do i have to make a special file on my server, How do i create a datasocket server.?? Do i use the same "address" to read a datasocket?