Two inserts using FORALL in oracle version 10.1.0.5.0 - 64bi.

Hi all,
I am trying to insert values into one table based on the another table insert statement returning values.
but i am unable to achieve this requirement using below code.
DB Version :
BANNER                                                        
Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - 64bi
PL/SQL Release 10.1.0.5.0 - Production                          
CORE     10.1.0.5.0     Production                                        
TNS for HPUX: Version 10.1.0.5.0 - Production                   
NLSRTL Version 10.1.0.5.0 - Production
sample code:
CREATE TABLE EMP1 (EMPNO NUMBER(4));  
   CREATE TABLE EMP2 (EMPNO NUMBER(4));  
   DECLARE
TYPE te_emp is table of  emp.empno%type;
t_empno te_emp;
l_empno NUMBER;
begin
select emp.empno bulk collect into t_empno from emp;
forALL  i in 1..t_empno.COUNT 
    execute immediate
     'BEGIN
     insert into emp(empno) values(:1) RETURNING EMPNO into '||l_empno||';
     insert into emp(empno) values('||l_empno||');
     END;' using t_empno(i);
end;  Please help me to achieve the requirement as mentioned above.
Edited by: Rama Krishna.CH on Nov 7, 2012 6:39 PM

SY,
Thank you very much sir.But our DB's not interest to creating objects for this requirement. so I can achieve this requirement using below code.
  DECLARE
TYPE td_empno is table of  number(4);
t_empno td_empno;
TYPE td_sal is table of  number;
t_sal td_sal;
l_empno NUMBER;
begin
select empno,sal  bulk collect into t_empno,t_sal from emp;
forALL  i in 1..t_empno.COUNT 
execute immediate
'BEGIN
insert into emp(empno,sal) values(:1,:2) RETURNING EMPNO into :3;
insert into emp(empno,ename) values(:3,:4);
END;' using t_empno(i),t_sal(i),in out l_empno,'rama';
end; Is there any other way achieve this requirement with out declaring multiple pl/sql tables and type objects like below example.
Using record data type.
DECLARE
TYPE rd_emp IS RECORD ( empno emp.empno%type
                       ,sal emp.sal%type
                       ,comm emp.comm%type);
TYPE td_emp is table of  rd_emp;
t_emp td_emp;
l_empno NUMBER;
begin
select empno,sal,comm bulk collect into t_emp from emp;
forALL  i in 1..t_emp.COUNT 
    execute immediate
      'DECLARE
       ere rd_emp;
      BEGIN
      ere := :1;
      ere := :2;
     insert into emp(empno,sal) values(ere.empno,ere.sal) RETURNING EMPNO into :2;
     insert into emp(empno) values(:2);
     END;' using t_emp(i),t_emp(i),in out l_empno;
end;
  Sorry for not providing exact information at first time.

Similar Messages

  • Bulk collect insert using forall

    Hi all,
    in the following statement:
    declare
    cursor C is select id,PEOPLE_ID from CN_ITEMS;
    type T_A is table of cn_items%rowtype;
    V_A T_A;
    begin
    open c;
    LOOP
    fetch c bulk collect into v_a;
    forall  I in V_A.first..V_A.last 
        insert into CN_TAXES(id,CREATION_DATE,TAX_PRICE,ITEM_ID,PEOPLE_ID)
                     values (CN_TAX_S.NEXTVAL, sysdate,10.5,v_a.id(i),v_a.people_id(i));
      exit when c%notfound;
    end loop;
    end;
    /i receive error:
    ORA-06550: line 13, column 2:
    PLS-00394: wrong number of values in the INTO list of a FETCH statement
    ORA-06550: line 13, column 2:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 20, column 61:
    PLS-00302: component 'ID' must be declared
    ORA-06550: line 20, column 71:
    PLS-00302: component 'PEOPLE_ID' must be declared
    ORA-06550: line 20, column 71:
    PLS-00302: component 'PEOPLE_ID' must be declared
    ORA-06550: line 20, column 67:
    PL/SQL: ORA-00904: "V_A"."PEOPLE_ID": invalid identifier
    ORA-06550: line 19, column 5:
    PL/SQL: SQL Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:Any ideas how to use in this situation FORALL? If i select all values from one table and then i use FORALL to insert them in another table with same columns is ok, but here i just want to use values from fetching to insert them in 2 columns of other table...
    Version : 11g
    Thanks in advance,
    Bahchevanov.

    >
    Any ideas how to use in this situation FORALL? If i select all values from one table and then i use FORALL to insert them in another table with same columns is ok
    >
    You have answered your own question. The solution is exactly what you just said above
    >
    select all values from one table and then i use FORALL to insert them in another table with same columns
    >
    The first error you were getting
    PLS-00394: wrong number of values in the INTO list of a FETCH statementis because of this code
    cursor C is select id,PEOPLE_ID from CN_ITEMS;
    type T_A is table of cn_items%rowtype;Your T_A variable is based on the CN_ITEMS table but since you are using a cursor you should base it on the cursor
    cursor C is select id,PEOPLE_ID from CN_ITEMS;
    type T_A is table of C%rowtype;You are also selecting ID but never using it. And you have an OUTER loop but did not use a LIMIT clause. A straight BULK COLLECT will collect everything at once so there is no purpose for the outer loop. But you should always use a limit clause rather than any implicit one.
    So if you must use a bulk collect solution (even though your specifics should be using pure SQL) then to fix your problem change that code to this
    cursor C is select CN_TAX_S.NEXTVAL, sysdate, 10.5,PEOPLE_ID from CN_ITEMS;
    type T_A is table of C%rowtype;In other words just construct a row that will match your target table. Then you can use the FORALL to insert the entire row at once (note the LIMIT clause)
    LOOP
    fetch c bulk collect into v_a LIMIT 1000;
    forall  I in V_A.first..V_A.last 
        insert into CN_TAXES(id,CREATION_DATE,TAX_PRICE,ITEM_ID,PEOPLE_ID)
                     values (V_A(I));
      exit when c%notfound;
    end loop;

  • How insert multiple rows in oracle version 8.1

    Hi All,
    I have table date_rng in which i have cloumns date_mnth and date_yr and like to insert multiple rows such (01,2011),
    (02,2011),(03,2011) etc using single insert statement.And i am using oracle 8.1 version so i do not have option of insert all into .please help me..
    Thanks
    Srini

    YOu can use this format
    insert into <table> select <column_value> from dual union all select <column_value> from dual union all ....

  • DBConnect with two different oracle versions

    Hullo folks,
    I've been looking for threads concerning the use of SAP BI's DBConnect tool with multiple external oracle databases.
    My client is currently using BI 3.5 and we have successfully used DBConnect to extract information from an external Oracle 9.2.0.5.0 database (btw BW uses the same oracle version).
    Currently my customer requests to extract information from a new external non-sap application. This application will be using an oracle database as well, but it will use the latest oracle version, 10.
    I know that in the past it wasn't possible to use DBConnect with different oracle versions as the differences were to big. I wonder whether this is also the case with the oracle 9 and 10 versions. Would it be possible to use both versions and extract the data with DBConnect? Or are the changes too big and SAP BW can only pick one of these versions? Perhaps there's a workaround? I don't know, and I'm hoping some of you know something.
    Thanks in advance.

    Thanks for your answer,
    though this doesn't answer my question. Yes, I know I'll have to create a different sourcesystem for the new oracle database.
    However, I can only use one ini file for Oracle in DBConnect. In the past it wasn't possible to have active connections with different versions of oracle databases (you can only have one file for oracle installed in DBConnect).
    The question is, whether it's possible to have a connection with two source systems where one uses Oracle 10 and the other Oracle 9... and if it's possible which file should be used in DBConnect...
    Remi

  • FORALL inserts using database link

    Hi,
    is there any way work around by which we can implement bulk inserts using FORALL across database link ?
    regards
    nic

    How about using a view as a layer to hide the db-link?
    Don't know if that will work.
    Also possible:
    Instead of "INSERT INTO targetTable@dbLink as SELECT * FROM sourceTable"
    do "INSERT INTO myTable AS SELECT * FROM sourcetable@dbLink" on the other database.

  • Operates on two table using procedure

    i want to handle two table using procedure in oracle 10g. i have created a procedure like this
    CREATE OR REPLACE PROCEDURE sold_car1(
    sid soldcar.sold_id%TYPE,
    cid soldcar.id%TYPE,
    cuid soldcar.customer_id%TYPE,
    eid soldcar.emp_id%TYPE,
    d soldcar.dat%TYPE
    ) IS
    BEGIN
    INSERT INTO soldcar VALUES(sid,cid,cuid,eid,to_date(d,'yyyy/mm/dd'));
    DELETE FROM pcar where id=cid;*
    COMMIT;
    END sold_car1;
    SHOW ERRORS
    i have found some errors. how can i do this.

    hi
    the errors are something like this ''the procedure is created with some errors''.
    actually i want to pass 4 parameters in the procedure that will insert in one table and among the 4 parameters by using one parameter i want to delete one row of another table.
    INSERT INTO soldcar VALUES(sid,cid,cuid,eid,to_date(d,'yyyy/mm/dd')); //soldcar is first table
    DELETE * FROM pcar where id=cid; //pcar is second table

  • Query on using Variables in Oracle Query

    Hi
    i am new to Oracle, i have tried extracting data from the Oracle Database using the following Query which includes 1 variable SYSDATE_UTS, however when i try to execute the Query i get an error. Please let me know what am i doing wrong and how can i correct it.
    Error Message
    ORA-06550: line 4, column 1:
    PLS-00428: an INTO clause is expected in this SELECT statement
    Oracle Query
    DECLARE SYSDATE_UTS NUMBER := (sysdate-to_date('19700101','yyyymmdd'))*86400;
    BEGIN
    SELECT
    INCIDENT_NUMBER,
    to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME,
    ,GROUP_TRANSFERS
    ,LAST_MODIFIED_BY
    ,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
    ,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
    ,CASE
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
    ELSE 'UNKNOWN'
    END AS AGE_GROUP
    FROM IncidentDataBase
    and STATUS not in (4,5,6)
    and rownum <10;
    END;

    Hi Frank
    i am using the following Oracle Version
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE     10.2.0.5.0     Production
    TNS for Linux: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    and Quest Toad for Oracle to write and execute the queries:
    Toad for Oracle Xpert
    Version 10.1.1.8
    The code i am using is:
    variable SYSDATE_UTS NUMBER;
    exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
    SELECT
    INCIDENT_NUMBER,
    to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME
    ,GROUP_TRANSFERS
    ,LAST_MODIFIED_BY
    ,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
    ,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
    ,CASE
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
    ELSE 'UNKNOWN'
    END AS AGE_GROUP
    FROM IncidentDataBase
    WHERE STATUS not in (4,5,6)
    and rownum <10;
    Notes:
    1. When i put the cursor before "variable" (starting of the query) and execute the script i get an Error: ORA-00900: invalid SQL statement.
    2. When i put the cursor just before "SELECT" i get a pop up.
    a. it is a Toad window which displays the available variables (in this case :SYSDATE_UTS).
    b. gives me a dropdown option to select the type (by default VARCHAR2 is selected).
    c. there is a value field where i need to enter the value for the Variable.
    d. the SQL statement shown in this dilog box does not include the 1st 2 lines
    variable SYSDATE_UTS NUMBER;
    exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
    Q: is there something wrong in the syntax i am using?
    Sven W. - I have been using your method all these days, which works just fine. i wanted to know how i could use a variable instead.
    Business Requirement - My whole intent is to calculate the Age of an incident (Difference between "Reported Date" and current date) and to assign Age Groups (0-1 Days, 2-4 Days,....,20+ Days).
    Edited by: 921713 on Mar 19, 2012 12:23 PM

  • Index rebuild in oracle version 8i

    Hi All
    Is there any other way we know which indexes we can rebuild in a database which is using RBO in oracle version 8
    we dont want to analyze those indexes
    Thanks

    Why it is a condition that you don't want to go for analyze of the indexes?The answer to the question is almost "never".It really needs to be quantified that the rebuild will be of some benefit.On what benchmark you want to go for rebuild ofthe index?
    You may like to read this blog about the same topic and many more on indexes,
    http://richardfoote.wordpress.com
    Aman....

  • What is differenct between normal insert and forall insert.

    Hi,
    i am little bit confused about following 2 types of inserts.
    insert into TableA
    select * from TableB
    and
    insert using forAll statment.
    which one is faster and why.

    Pankaj M wrote:
    insert into TableA
    select * from TableB
    and
    insert using forAll statment.
    which one is faster and why.The first, insert ... select.
    Because you just insert and don't need to fetch the results anywhere and allocate memory and less code executes in less time.

  • Two oracle versions on one client

    Hello
    I installed Oracle7 and Oracle8 Client together on the same machine.
    So far it works well. But when I want to open one of my ODBC Drivers, I4m getting the following error:
    ODBCADM caused a general protection fault in KRNL386.exe at 0001:243F.
    Is it possible, that this is because of the two Oracle versions?
    Or does anybody have another idea?
    Thanks, Anja

    Hi,
    Like Kamal said, no problem. You can have 2 tnsnames.ora, one in 8i (where you declare 8i databases), and one in 10g (where you declare 10g databases).
    To connect to 8i, set ORACLE_HOME to 8i directory and use 8i sqlplus.
    To connect to 10g, set ORACLE_HOME to 10g directory and use 10g sqlplus.
    Nicolas.

  • Transfer data from two oracle version to one sql server 2005

    Hi,
    I have two database servers on different machines. They are
    1) Oracle 8.1.7.4
    2) Oracle 7.3.1.4
    I have to create agents which can transfer tables from these two databases to one machine having sql server 2005 database.
    Please tell me what are the options. What drivers i need to install on machine having sql server 2005 so that i can transfer data from both oracle versions.
    Thanks
    Rajneesh.

    Your Oracle databases are so old you might want to look around and see if you can find dinosaur bones near by.
    Given the differences in data types between Oracle and SQL Server I'd suggest you start off by dumping the data into delimited ASCII files and then loading it using whichever SQL Server tool you wish.

  • Error while using P2V in Oracle VM 2.2 version

    Error while using P2V in Oracle VM 2.2 version
    I tried using this option by using the steps given on one link but it didnt worked...
    Error:
    code 404, message No permission to list directory.
    I ve tried giving full permissions on for /OVS on Server but invain.
    Can U pls help me...
    Thanks in advance.
    Edited by: user10310678 on Sep 16, 2009 3:32 AM

    user10310678 wrote:
    I am using beta version. Oracle VM Manager 2.2.0If you have a beta version of 2.2, then you should be an Oracle employee. Please ask this question on an internal mailing list. If you are not an Oracle employee, please ask the employee that gave you this beta. As this is a beta, some functionality may not be operational yet, so I can't answer why this particular feature seems not to work.

  • What is the best way of insertion using structured or binary type in oracle

    what is the best way of insertion using structured or binary type in oracle xml db 11g database

    SQL*Loader.

  • Issue of inserting greek characters into Oracle database using ICAN505

    Hi All,
    We are currently facing an issue of inserting greek characters into Oracle database using ICAN505.
    We receive a file containing greek characters.The values from the file should be inserted into the database.We are reading the file using file OTD with default encoding.
    The file can contain english characters too other than greek characters.
    The database NLS_CHARACTERSET is AL32UTF8.
    When I insert using an insert statement directly ,the values get inserted properly into the DB table.
    Inserting the same values using code results in improper characters getting inserted into the table in the database.
    Please help....
    Thanks in advance !!

    Globalization forum?
    Globalization Support
    It works for SQL Developer, which does not depend on NLS_LANG, so I suspect a problem with your NLS settings.

  • Can we use hints in oracle 11g version ?

    can we use hints in oracle 11g version ? is it working ??

    Why do you ask these questions? Have you looked at the SQL Reference Guide and Performance Tuning Guide for your Oracle version - both which covers using hints?
    Have you see a statement that is not supported? Or does not work?
    Or are you simply doing idle speculation and expecting forum members to spend their free time in answering a basic question where the answer is ridiculously simply to find?

Maybe you are looking for

  • Email Sales Order Confirmation to "Created By" -

    Hi Experts I have a requirement where we need to email the Order confirmation output to the person who has created the sales order. So lets say i am creating a sales order and my user id is 9999. (SY-UNAME). Now as we have implemented HR module and o

  • Should I waith for Leopard?

    Thanks in advance, I need advices. I am planning to get a 250 GB 2.5" HD (if you know of a larger one internal let me know) for my MacBookPro core duo 2. I will install: Parallel(or one of the others to run windows on my mac),windows xp pro with offi

  • Table for control indicator in inspection characteristics(QP03)

    Hi can any one tell me in which table " Control Indicator " data is stored? in QP03 there is a control indicator tab for MICs in that i want Long term inspection details for ALL MICs can any one tell me the control indicator table? Regards Smitha

  • Error when trying to purchase PhoneGap

    The Screen says, "error" after "Confirm" button is pressed when trying to purchase PhoneGap.  No further information is provided regarding what exactly the error is.  My bank account is being debited $1 each time I make an attempt to purchase PhoneGa

  • Not enough space on HD to install Leopard

    My Leopard install hung up on the blue screen of death. I repaired the disk using Disk Utility, but now don't have enough space on the HD to archive and install. I have backup copies of iPhoto and Documents, so could erase those files on the HD, but