Simple way to insert data from one table

Hi,
I need to know a simple way on how to transfer the data from one table to another....
First table xx_inv_tab1 has three columns col1, col2, col3 and where as second table xx_inv_tab2 has five columns col1, col2, col3, col4, col5.
Here col2, col3, col4 are the same columns as in table1 xx_inv_tab1...
Now I want to transfer first table data in to second table .... first column of second table holds a sequence, followed by the first table three columns data and followed with col4 and col5 which will hold NULL values....
In my scenario, I have 70 - 75 columns in my first table which I want to move to second table which three new columns (one is sequence and other two has null values)...
Any ideas if we make it in a simplest way rather saying insert into xx_inv_tab2 (col1, col2, col3 ............................................. col75) values (seq, col1, col2..........................col75, null, null)
Help Appreciated..
Thanks

Easy
untested
insert into xx_inv_tab2 t2 (col1,col2,col3,col4)
select yourSequence.nextval, t1.col1, t1.col2, t1.col3
from xx_inv_tab1 t1
;Note that col5 does not need to be used, since you want to fill it with NULL.
USe excel or sql developer to write you a list of column names, if you are to lazy to write all 75 columns by yourself.
What might also work:
untested
insert into xx_inv_tab2 t2
select yourSequence.nextval, t1.*, null
from xx_inv_tab1 t1
;Edited by: Sven W. on Aug 31, 2012 4:41 PM

Similar Messages

  • Inserting data from one table into another table using PL/SQL

    HI,
    I am trying to insert values from one table into another using PL procedure, the values I want to retrieve from the table riverside1 are charac_id and charac_type and insert these values into another table called riverside2 , the stored procedure zorgs_gorfs(x,y) accepts two parameters which are 2 charac_id's of d characters in riverside1 then using insert statements inserts these characters from riverside1 into riverside2.
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (x);
    INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (y);
          END zorgs_gorfs;
    /This works but the problem im having is that when I also try to insert the charac_type as well as the charac_id it doesnt work below is the code:
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);
          END zorgs_gorfs;
    /can someone kindly sort me out

    modify this sql
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);as
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id in ( x,y));But my suggestion would be consider revising your approach. It does not look that good.
    Thanks,
    karthick.

  • Inserting data from one table to another in different format

    Hello,
    I would like to know what I am doing wrong with the following code when I write a data from one another to another table in a different format. I am now learning PL/SQL and am using this as
    a test problem.
    I have a table called students which has the following columns:
    SQL> desc student
    Name Null? Type
    ----------- ----------------STUDENT_ID NUMBER(10)
    COURSE VARCHAR2(10)
    CREDITS NUMBER(10)
    I have created another table called new_student which has the following structure:
    SQL> desc new_student
    Name Null? Type
    ----------------------------------------- -------- ------------- STUDENT_ID NUMBER(10)
    COURSE VARCHAR2(30)
    CREDITS VARCHAR2(10)
    The data in the student table is:
    SQL> select * from student;
    STUDENT_ID COURSE CREDITS
    1 Science 4
    1 History 3
    2 Science 4
    2 History 3
    2 Math 4
    3 Sociology 3
    3 Psycology 3
    I want to store the STUDENT table data in NEW_STUDENT table as:
    STUDENT ID COURSES CREDITS
    1 Science/History 4/3
    2 Science/History/Math 4/3/4
    3 Sociology/Psycology 3/3
    This is my code:
    DECLARE
    -- Get all the student IDs
    CURSOR studentlist_cursor IS select distinct student_id from student ORDER BY student_id;
    -- Get the information for each student ID
    CURSOR courses_cursor(nstudentid number) is select course, credits from student where student_id=nstudentid;
    nIndex     INTEGER;
    pltcourses     DBMS_SQL.VARCHAR2_TABLE;
    pltcredits     DBMS_SQL.NUMBER_TABLE;
    newcourses varchar2(50);
    newcredits varchar2(10);
    BEGIN
    FOR student_rec IN studentlist_cursor
    LOOP
    nIndex:=0;
    -- Loop through each student ID from student_rec to get the
    --courses and creditsstudent ID
    FOR courses_rec in courses_cursor(student_rec.student_id)
         LOOP
         nIndex:=nIndex+1;
         pltcourses(nIndex):=courses_rec.course;
    -- Store the course data for each student ID in newcourses
    -- while doing so check if it is null or put a '/' between each course
    loop
    if newcourses is null then
    newcourses:=pltcourses(nIndex);
    else
    newcourses:=newcourses||'/'||pltcourses(nIndex);
    end if;
    end loop;
         pltcredits(nIndex):=courses_rec.credits;
    --Store credits data in variable newcredits
    --If the newcredits is not null then put a '/' between each credits
    loop
    if newcredits is null then
    newcredits:=pltcredits(nIndex);
    else
    newcredits:=newcredits||'/'||pltcredits(nIndex);
    end if;
    end loop;
    -- Insert student id, newcourses, newcredits into NEW_STUDENT
    INSERT INTO NEW_STUDENT
    (student_id ,
    course,
    credits
    ) VALUES
    (student_rec.student_id,
    newcourses,
    newcredits
    COMMIT;
    -- come out of the student id record and go to the next student --id record
    END LOOP;
    -- come out of the loop
    END LOOP;
    END;
    While doing so I get an error message:
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at line 23.
    The error is at the line:
    newcourses:=newcourses||'/'||pltcourses(nIndex);
    Can anyone help me by pointing out where the mistake is?
    Thank you for reading this long mail.
    Thank you.
    Rama.

    Hi dude
    there is lot of error in ur pl/sql.
    and u have created table new_student with columns
    student_id number(10),
    courses varchar2(30),
    credits number(10).
    first u need to modify ur table.
    student_id number(10),
    courses varchar2(30),
    credits varchar2(10).
    Now i am writing whole pl/sql block for u. it will work fine.
    DECLARE
    CURSOR studentlist_cursor IS select distinct student_id from student ORDER BY student_id;
    CURSOR courses_cursor(nstudentid number) is select course, credits from student
    where student_id = nstudentid;
    nIndex INTEGER;
    pltcourses DBMS_SQL.VARCHAR2_TABLE;
    pltcredits DBMS_SQL.NUMBER_TABLE;
    newcourses varchar2(50);
    newcredits varchar2(10);
    BEGIN
    FOR student_rec IN studentlist_cursor
    LOOP
    nIndex:=0;
    newcourses := null;
    newcredits := null;
    FOR courses_rec in courses_cursor(student_rec.student_id)
    LOOP
    nIndex:=nIndex+1;
    pltcourses(nIndex):=courses_rec.course;
    if newcourses is null then
    newcourses:=pltcourses(nIndex);
    else
    newcourses:=newcourses||'/'||pltcourses(nIndex);
    end if;
    pltcredits(nIndex):=courses_rec.credits;
    if newcredits is null then
    newcredits:=pltcredits(nIndex);
    else
    newcredits:=newcredits||'/'||pltcredits(nIndex);
    end if;
    end loop;
    INSERT INTO NEW_STUDENT
    (student_id,
    course) VALUES
    (student_rec.student_id,
    newcourses);
    END LOOP;
    END;
    and please revert back
    Regards
    Anil

  • Inserting Data from one table to another.

    I running a procedure that loops through a cursor which is about 80,000 records(tableA) and I am trying to insert into another table(tableX) based on the data from tableA. I have error trapped the hell out of this and made sure I am covering any holes. When looping through the cursor, it insert only about 28,000 records and then exits the loop. I have debugged this problem 100 different ways and for the life of me I can not figure why it just craps out at about this many records. I actually located where the looping stops and took the next 5 records from tableA, and inserted them manually and they went through normally, which tells me that there should have been no reason why the executable statements exited the loop. I checked my space and I have more than enough. I have debugged the code many different ways, but still no luck. It always exits the procedure after inserting about 28,000 records. When I was debugging the code, I noticed that it would exit because one of my select into...statements was returning a NO_DATA_FOUND error, but I trapped that error, and assigned a value to that variable if it was null.
    I am really getting frustrated with this. Can anyone offer some suggestions or advice as to what I can do to acheive my goal?

    post the cursor , loop , definition.
    while you fire the cursor, on table A for
    insert in table X, what happens on A and X ?
    it tries to make a commit every 100/1000 time,
    until close the cursor.
    table definition X, is similar to A ?
    alert_$SID.log what says ?
    pasquale rago

  • Inserting data from one table to another table....

    Hi DB Gurus,
    I have two table like table A in instance X and table B in instance Y. I want to insert data into table A from table B.If data in table B already exist in table A then that should not insert .if data In table B is not present in table A then that data should insert into table A.
    please help me to how insert this kind of data.I am trying to insert data by using "insert into" statement.Is it correct way or not. please let me know...
    Thanks in advance
    Best regards
    kumar

    Hey There,
    "I have two table like table A in instance X and table B in instance Y"
    Are these 2 instances sitting in the same db/rac.
    if so
    insert into x.a
    select * from y.b
    If the 2 instances are in different databases/racs then i think you can add a linked db into your script.- not 100% about that though.
    Dob

  • Insert data from one table to another.

    I have two tables - T1 & T2.
    T1 has columns A1,A2,A3,A4 (A1 & A2 are the primary keys)
    T2 has columns B1,B2,B3,B4 (B1 & B2 are the primary keys)
    I need to insert records from T1 to T2 with the conditions,
    - A1,A2,A3 will have the same record for the multiple records of A4.
    This is what I tried and got the error:-
    SQL> INSERT INTO nego_prop_supp (nps_supp_cd, nps_enq_no, nps_supp_resp, nps_cs_rank)
    2 SELECT DISTINCT tos_supp_code, tos_enq_no, tos_bid_seal_condn, csr_set_rank
    3 FROM tender_opening_supp, cs_rate
    4 WHERE tos_enq_no = '7211233E' AND
    5 tos_supp_code = csr_scd AND
    6 (tos_nature_of_bid = 'P' or tos_nature_of_bid = 'N') AND
    7 csr_set_rank IS NOT NULL;
    INSERT INTO nego_prop_supp (nps_supp_cd, nps_enq_no, nps_supp_resp, nps_cs_rank)
    ERROR at line 1:
    ORA-00001: unique constraint (DPURC.NEGO_PROP_SUPP_PK) violated
    You could understand that T1 consists (data from 'tender_opening_supp' & cs_rate), while T2 is nego_prop_supp.
    Pls. get me the soution for thi problem!!

    then this query
    SELECT DISTINCT tos_supp_code, tos_enq_no, tos_bid_seal_condn, csr_set_rank
    3 FROM tender_opening_supp, cs_rate
    4 WHERE tos_enq_no = '7211233E' AND
    5 tos_supp_code = csr_scd AND
    6 (tos_nature_of_bid = 'P' or tos_nature_of_bid = 'N') AND
    7 csr_set_rank IS NOT NULL
    8 and not exists (select nps_supp_cd from nego_prop_supp,tender_opening_supp where tos_supp_code
    = nps_supp_cd) ;
    have more than one tos_supp_code (the same any times) with any different value from tos_enq_no, tos_bid_seal_condn, csr_set_rank
    then anything is wrong or your key(on nego_prop_supp ) or the query retrieve rows that you not want
    the join is ok?
    why this join retrieve more than one value with the key of the other table? Do you need to filter any more? are you missing a filter?

  • Insert old missing data from one table to another(databaase trigger)

    Hello,
    i want to do two things
    1)I want to insert old missing data from one table to another through a database trigger but it can't be executed that way i don't know what should i do in case of replacing old data in table_1 into table_2
    2)what should i use :NEW. OR :OLD. instead.
    3) what should i do if i have records exising between the two dates
    i want to surpress the existing records.
    the following code is what i have but no effect occured.
    CREATE OR REPLACE TRIGGER ATTENDANCEE_FOLLOWS
    AFTER INSERT ON ACCESSLOG
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    V_COUNT       NUMBER(2);
    V_TIME_OUT    DATE;
    V_DATE_IN     DATE;
    V_DATE_OUT    DATE;
    V_TIME_IN     DATE;
    V_ATT_FLAG    VARCHAR2(3);
    V_EMP_ID      NUMBER(11);
    CURSOR EMP_FOLLOWS IS
    SELECT   EMPLOYEEID , LOGDATE , LOGTIME , INOUT
    FROM     ACCESSLOG
    WHERE    LOGDATE
    BETWEEN  TO_DATE('18/12/2008','dd/mm/rrrr') 
    AND      TO_DATE('19/12/2008','dd/mm/rrrr');
    BEGIN
    FOR EMP IN EMP_FOLLOWS LOOP
    SELECT COUNT(*)
    INTO  V_COUNT
    FROM  EMP_ATTENDANCEE
    WHERE EMP_ID    =  EMP.EMPLOYEEID
    AND    DATE_IN   =  EMP.LOGDATE
    AND    ATT_FLAG = 'I';
    IF V_COUNT = 0  THEN
    INSERT INTO EMP_ATTENDANCEE (EMP_ID, DATE_IN ,DATE_OUT
                                ,TIME_IN ,TIME_OUT,ATT_FLAG)
         VALUES (TO_NUMBER(TO_CHAR(:NEW.employeeid,99999)),
                 TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'),       -- DATE_IN
                 NULL,
                 TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'),      -- TIME_IN
                 NULL ,'I');
    ELSIF   V_COUNT > 0 THEN
    UPDATE  EMP_ATTENDANCEE
        SET DATE_OUT       =  TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'), -- DATE_OUT,
            TIME_OUT       =   TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'), -- TIME_OUT
            ATT_FLAG       =   'O'
            WHERE EMP_ID   =   TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
            AND   DATE_IN <=  (SELECT MAX (DATE_IN )
                               FROM EMP_ATTENDANCEE
                               WHERE EMP_ID = TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
                               AND   DATE_OUT IS NULL
                               AND   TIME_OUT IS NULL )
    AND   DATE_OUT  IS NULL
    AND   TIME_OUT IS NULL  ;
    END IF;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN RAISE;
    END ATTENDANCEE_FOLLOWS ;
                            Regards,
    Abdetu..

    INSERT INTO SALES_MASTER
       ( NO
       , Name
       , PINCODE )
       SELECT SALESMANNO
            , SALESMANNAME
            , PINCODE
         FROM SALESMAN_MASTER;Regards,
    Christian Balz

  • How do I make data from one Table flow into a separate Table

    How do I make data from one Table flow into a separate Table in iworks numbers?

    Great stuff Yvan,
    KOENIG Yvan wrote:
    Here you may see the way to transfer the contents of a column of Table A in a column of Table B
    I used two kinds of formulas.
    In the cell A2 of Table B
    the formula is :
    =Table A :: $B2
    It may be :
    =Table A :: $B
    Apply Fill Down
    Copy paste it in cell A1 which is in a header row.
    This formula does its duty but it’s not robust enough and will not survive to a Sort.
    This is why in B2, I inserted a more robust formula :
    =OFFSET(Table A :: $A$1,ROW()-1,2)
    You will find details about the functions used in Numbers User Guide delivered with every copy of iWork ‘08
    Yvan KOENIG (VALLAURIS, France) samedi 6 août 2011 17:45:22
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !
    The first suggestion was the simple answer I needed,
    Thank you

  • Adding Data From One Table to Another

    Now, this doesn't strike me as a particularly complex problem, but I've either strayed outside the domain of Numbers or I'm just not looking at the problem from the right angle. In any case, I'm sure you guys can offer some insight.
    What I'm trying to do is, essentially, move data from one table to another. One table is a calendar, a simple two column 'date/task to be completed' affair, the other is a schedule of jogging workouts, i.e, times, distances. Basically, I'm trying to create a formula that copies data from the second table onto the first but only for odd days of the week, excepting Sundays (and assuming Monday as the start of the week). Now, this isn't the hard part, I can do that. The problem comes when I replicate the formula down the calendar. Even on the days when the 'if' statement identifies it as an 'even day', the cell reference to the appropriate workout on the second table is incremented, so when it comes to the next 'odd day', it has skipped a workout.
    I can't seem to see any way of getting it to specifically copy the NEXT line in the second table, and not the corresponding line.
    This began as a distraction to try and organise my running so I could see at a glance what I had to do that day and track my progress, but now it's turned into an obsession. SURELY there's a solution?
    Cheers.

    Hi Sealatron,
    Welcome to Apple Discussions and the Numbers '09 forum.
    Several possible ways to move the data occur to me, but the devil's in the details of how the data is currently arranged.
    Is it
    • a list of three workouts, one for each of Monday, Wednesday and Friday, then the same three repeated the following week?
    • an open-ended list that does not repeat?
    • something else?
    Regards,
    Barry

  • Copying data from one table to another table thru java

    Hi
    I have to copy data from table emp in Database A to table emp in Database B. My input would be table name and number of rows to be fetched. these rows i need to insert in table B.
    The problem over here is I won't be having any info. of table emp i.e the number of columns it has and their type.
    So is their any way i can copy the data from one table to other without having the info abt the number of cols and their type.
    TIA

    Cross post - http://forum.java.sun.com/thread.jspa?threadID=5169293&messageID=9649839#9649839

  • Create Trigger to insert records from one table to another

    I created the below trigger to move data from one table to another after records have been inserted from another table to that table. What I need done is that each time records have been inserted into TEST_TBL, one of these actions codes should be implimented: U-update, N-insert, D-delete and inserted into TEST_TBL1. But each time I run the script, I get bunch of errors. Please see the script below: - Your help will be appreciated.
    create or replace
    trigger POWER_tr
    after update or insert or delete ON test_tbl
    for each row
    begin
    if updating then
    insert into test_tbl1
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
    VALUES
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'U', sysdate);
    ELSif INSERTING then
    insert insert into test_tbl1
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
    VALUES
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'N', sysdate);
    ELSIF deleting then
    insert into test_tbl1
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
    VALUES
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'D', sysdate);
    END IF;
    END POWER_tr;
    Thank you,
    Albert Zaza
    Edited by: azaza on Mar 1, 2009 4:14 PM

    Hello
    At the end of trigger show errors / and post what errors are you getting exactly?
    Here is a simple example for your reference, this will save old values in history table; you can replace it with new values if that's what do you want.
    CREATE OR REPLACE TRIGGER TRG_DU
       AFTER DELETE OR UPDATE
       ON EMPLOYEE    REFERENCING NEW AS New OLD AS Old
       FOR EACH ROW
    DECLARE
    BEGIN
       IF UPDATING
       THEN
          INSERT INTO employee_hist
            VALUES   ('UPDATE',
                      :OLD.empid,
                      :OLD.name,
                      :OLD.deptid);
       ELSIF DELETING
       THEN
          INSERT INTO employee_hist
            VALUES   ('UPDATE',
                      :OLD.empid,
                      :OLD.name,
                      :OLD.deptid);
       END IF;
    EXCEPTION
       WHEN OTHERS
       THEN
          -- Consider logging the error and then re-raise
          RAISE;
    END TRG_DU;
    /Regards
    Edited by: OrionNet on Mar 1, 2009 7:27 PM

  • Copying large amount of data from one table to another getting slower

    I have a process that copies data from one table (big_tbl) into a very big archive table (vb_archive_tbl - 30 mil recs - partitioned table). If there are less than 1 million records in the big_tbl the copy to the vb_archive_table is fast (-10 min), but more importantly - it's consistant. However, if the number of records is greater than 1 million records in the big_tbl copying the data into the vb_archive_tbl is very slow (+30 min - 4 hours), and very inconsistant. Every few days the time it takes to copy the same amount of data grows signicantly.
    Here's an example of the code I'm using, which uses BULK COLLECT and FORALL INSERST to copy the data.
    I occasionally change 'LIMIT 5000' to see performance differences.
    DECLARE
    TYPE t_rec_type IS RECORD (fact_id NUMBER(12,0),
    store_id VARCHAR2(10),
    product_id VARCHAR2(20));
    TYPE CFF_TYPE IS TABLE OF t_rec_type
    INDEX BY BINARY_INTEGER;
    T_CFF CFF_TYPE;
    CURSOR c_cff IS SELECT *
    FROM big_tbl;
    BEGIN
    OPEN c_cff;
    LOOP
    FETCH c_cff BULK COLLECT INTO T_CFF LIMIT 5000;
    FORALL i IN T_CFF.first..T_CFF.last
    INSERT INTO vb_archive_tbl
    VALUES T_CFF(i);
    COMMIT;
    EXIT WHEN c_cff%NOTFOUND;
    END LOOP;
    CLOSE c_cff;
    END;
    Thanks you very much for any advice
    Edited by: reid on Sep 11, 2008 5:23 PM

    Assuming that there is nothing else in the code that forces you to use PL/SQL for processing, I'll second Tubby's comment that this would be better done in SQL. Depending on the logic and partitioning approach for the archive table, you may be better off doing a direct-path load into a staging table and then doing a partition exchange to load the staging table into the partitioned table. Ideally, you could just move big_tbl into the vb_archive_tbl with a single partition exchange operation.
    That said, if there is a need for PL/SQL, have you traced the session to see what is causing the slowness? Is the query plan different? If the number of rows in the table is really a trigger, I would tend to suspect that the number of rows is causing the optimizer to choose a different plan (with your sample code, the plan is obvious, but perhaps you omitted some where clauses to simplify things down) which may be rather poor.
    Justin

  • Moving time-dependant data from one table to another (archiving)

    Hello all
    I would like to know if there's an easier solution or a "best practice" to move data from one table to another. The context of this issue can be found within "archiving".
    More concretely: we have an application that uses several tables to log information to.
    These tables are growing like crazy, and we would like to keep only "relevant" data in those tables, so I was thinking about moving data from these tables that have been in there for, say 2 months, to "archiving" tables.
    I figured there must be some kind of "best practice" to get this done.
    I have already written a procedure that loops the table that has the time indicator and inserts the records from the normal tables into the archive tables (and afterwards delete this data), but it seems to be taking ages to get it done.
    Thanks in advance!
    Message was edited by:
    timschraepen

    There is nothing to do with PL/SQL.
    You can refer below links:
    http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96524/c12parti.htm
    http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10739/partiti.htm#i1006727

  • Move data from one table to another table

    Hi all,
    I  had a custom table called sales_data in that table there are  columns like JAn,FEB,upto DEC including other columns so in each month there is some data total data is  23000 count but each month has has specific data like JAn-2500,FEB-2000 like that it has total 23000 records
    My Requirement  is i have to move data from one table to another table that too if i will pass jan only jan data should move like that feb,march,.....
    in my table there is no month column i had get it from another table called gl_periods and by using cursor and case function i have written the code
    well while when i am inserting data am passing year,month as parameters but 23000 data is moving it should get like that.
    Please suggest me.its urgent
    Thank You

    Hi hamid,
                   Please go through the below procedure.
    CREATE OR REPLACE PROCEDURE APPS.copy_sales_to_forecast(p_fiscal_year varchar2,p_month number)
    IS
    CURSOR C1 IS select period_year,period_num,start_date,end_date from apps.gl_periods
                 where period_set_name='Accounting'
                 and   period_year=p_fiscal_year
                 and   period_num<=p_month;
    type type1 is table of xxc_forecast_data%rowtype;
    t1 type1;
    BEGIN
    FOR CREC IN C1 LOOP
    BEGIN
    DELETE FROM xxc_forecast2
    where fiscal_year = crec.period_year
      and attribute1='Copied From Sales to Forecast Table of Month '||crec.period_num;
    END;
    SELECT
      product_category           ,
      product_sub_category       ,
      product_line               ,
      product_style              ,
      item_number                ,
      item_description           ,
      customer_name              ,
      customer_number            ,
      sales_channel              ,
      null      ,
      CASE
        WHEN crec.period_num=1 THEN sales_amount_month1
        ELSE 0
      END Transaction_quantity_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_cost_month1
        ELSE 0
      END item_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_mtl_cost_month1
        ELSE 0
      END item_material_cogs_period1 ,
      CASE
        WHEN crec.period_num=1 THEN sales_mtl_ovhd_cost_month1
        ELSE 0
      END item_mtl_ovhd_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_res_cost_month1
        ELSE 0
      END item_resource_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_op_cost_month1
        ELSE 0
      END item_op_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_ovhd_month1
        ELSE 0
      END item_ovhd_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_units_month1
        ELSE 0
      END extended_amount_us_period1,
      CASE
        WHEN crec.period_num=2 THEN sales_amount_month2
        ELSE 0
      END Transaction_quantity_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_mtl_cost_month2
        ELSE 0
      END item_material_cogs_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_mtl_ovhd_cost_month2
        ELSE 0
      END item_mtl_ovhd_cogs_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_res_cost_month2
        ELSE 0
      END item_resource_cogs_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_op_cost_month2
        ELSE 0
      END item_op_cogs_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_ovhd_month2
        ELSE 0
      END item_ovhd_cogs_period2,
       CASE
        WHEN crec.period_num=2 THEN sales_units_month2
        ELSE 0
      END extended_amount_us_period2,
      CASE
        WHEN crec.period_num=3 THEN sales_amount_month3
        ELSE 0
      END Transaction_quantity_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_mtl_cost_month3
        ELSE 0
      END item_material_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_mtl_ovhd_cost_month3
        ELSE 0
      END item_mtl_ovhd_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_res_cost_month3
        ELSE 0
      END item_resource_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_op_cost_month3
        ELSE 0
      END item_op_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_ovhd_month3
        ELSE 0
      END item_ovhd_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_units_month3
        ELSE 0
      END extended_amount_us_period3,
      CASE
        WHEN crec.period_num=4 THEN sales_amount_month4
        ELSE 0
      END Transaction_quantity_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_mtl_cost_month4
        ELSE 0
      END item_material_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_mtl_ovhd_cost_month4
        ELSE 0
      END item_mtl_ovhd_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_res_cost_month4
        ELSE 0
      END item_resource_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_op_cost_month4
        ELSE 0
      END item_op_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_ovhd_month4
        ELSE 0
      END item_ovhd_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_units_month4
        ELSE 0
      END extended_amount_us_period4,
      CASE
        WHEN crec.period_num=5 THEN sales_amount_month5
        ELSE 0
      END Transaction_quantity_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_mtl_cost_month5
        ELSE 0
      END item_material_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_mtl_ovhd_cost_month5
        ELSE 0
      END item_mtl_ovhd_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_res_cost_month5
        ELSE 0
      END item_resource_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_op_cost_month5
        ELSE 0
      END item_op_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_ovhd_month5
        ELSE 0
      END item_ovhd_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_units_month5
        ELSE 0
      END extended_amount_us_period5,
      CASE
        WHEN crec.period_num=6 THEN sales_amount_month6
        ELSE 0
      END Transaction_quantity_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_mtl_cost_month6
        ELSE 0
      END item_material_cogs_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_mtl_ovhd_cost_month6
        ELSE 0
      END item_mtl_ovhd_cogs_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_res_cost_month6
        ELSE 0
      END item_resource_cogs_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_op_cost_month6
        ELSE 0
      END item_op_cogs_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_ovhd_month6
        ELSE 0
      END item_ovhd_cogs_period6,
       CASE
        WHEN crec.period_num=6 THEN sales_units_month6
        ELSE 0
      END extended_amount_us_period6,
      CASE
        WHEN crec.period_num=7 THEN sales_amount_month7
        ELSE 0
      END Transaction_quantity_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_mtl_cost_month7
        ELSE 0
      END item_material_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_mtl_ovhd_cost_month7
        ELSE 0
      END item_mtl_ovhd_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_res_cost_month7
        ELSE 0
      END item_resource_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_op_cost_month7
        ELSE 0
      END item_op_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_ovhd_month7
        ELSE 0
      END item_ovhd_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_units_month7
        ELSE 0
      END extended_amount_us_period7,
      CASE
        WHEN crec.period_num=8 THEN sales_amount_month8
        ELSE 0
      END Transaction_quantity_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_mtl_cost_month8
        ELSE 0
      END item_material_cogs_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_mtl_ovhd_cost_month8
        ELSE 0
      END item_mtl_ovhd_cogs_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_res_cost_month8
        ELSE 0
      END item_resource_cogs_period7,
      CASE
        WHEN crec.period_num=8 THEN sales_op_cost_month8
        ELSE 0
      END item_op_cogs_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_ovhd_month8
        ELSE 0
      END item_ovhd_cogs_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_units_month8
        ELSE 0
      END extended_amount_us_period8,
      CASE
        WHEN crec.period_num=9 THEN sales_amount_month9
        ELSE 0
      END Transaction_quantity_period9,
      CASE
        WHEN crec.period_num=9 THEN sales_mtl_cost_month9
        ELSE 0
      END item_material_cogs_period9,
      CASE
        WHEN crec.period_num=9 THEN sales_mtl_ovhd_cost_month9
        ELSE 0
      END item_mtl_ovhd_cogs_period9,
      CASE
        WHEN crec.period_num=9 THEN sales_res_cost_month9
        ELSE 0
      END item_resource_cogs_period7,
      CASE
        WHEN crec.period_num=9 THEN sales_op_cost_month9
        ELSE 0
      END item_op_cogs_period9,
      CASE
        WHEN crec.period_num=9 THEN sales_ovhd_month9
        ELSE 0
      END item_ovhd_cogs_period9,
       CASE
        WHEN crec.period_num=9 THEN sales_units_month9
        ELSE 0
      END extended_amount_us_period9,
      CASE
        WHEN crec.period_num=10 THEN sales_amount_month10
        ELSE 0
      END Transaction_quantity_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_mtl_cost_month10
        ELSE 0
      END item_material_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_mtl_ovhd_cost_month10
        ELSE 0
      END item_mtl_ovhd_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_res_cost_month10
        ELSE 0
      END item_resource_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_op_cost_month10
        ELSE 0
      END item_op_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_ovhd_month10
        ELSE 0
      END item_ovhd_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_units_month10
        ELSE 0
      END extended_amount_us_period10,
      CASE
        WHEN crec.period_num=11 THEN sales_amount_month11
        ELSE 0
      END Transaction_quantity_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_mtl_cost_month11
        ELSE 0
      END item_material_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_mtl_ovhd_cost_month11
        ELSE 0
      END item_mtl_ovhd_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_res_cost_month11
        ELSE 0
      END item_resource_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_op_cost_month11
        ELSE 0
      END item_op_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_ovhd_month11
        ELSE 0
      END item_ovhd_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_units_month11
        ELSE 0
      END extended_amount_us_period11,
      CASE
        WHEN crec.period_num=12 THEN sales_amount_month12
        ELSE 0
      END Transaction_quantity_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_mtl_cost_month12
        ELSE 0
      END item_material_cogs_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_mtl_ovhd_cost_month12
        ELSE 0
      END item_mtl_ovhd_cogs_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_res_cost_month12
        ELSE 0
      END item_resource_cogs_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_op_cost_month12
        ELSE 0
      END item_op_cogs_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_ovhd_month12
        ELSE 0
      END item_ovhd_cogs_period12,
        CASE
        WHEN crec.period_num=12 THEN sales_units_month12
        ELSE 0
      END extended_amount_us_period12,
      CASE
        WHEN crec.period_num=2 THEN sales_cost_month2
        ELSE 0
      END item_cogs_period2,
       CASE
        WHEN crec.period_num=3 THEN sales_cost_month3
        ELSE 0
      END item_cogs_period3,
       CASE
        WHEN crec.period_num=4 THEN sales_cost_month4
        ELSE 0
      END item_cogs_period4,
       CASE
        WHEN crec.period_num=5 THEN sales_cost_month5
        ELSE 0
      END item_cogs_period5,
      CASE
        WHEN crec.period_num=6 THEN sales_cost_month6
        ELSE 0
      END item_cogs_period6,
      CASE
        WHEN crec.period_num=7 THEN sales_cost_month7
        ELSE 0
      END item_cogs_period7,
       CASE
        WHEN crec.period_num=8 THEN sales_cost_month8
        ELSE 0
      END item_cogs_period8,
      CASE
        WHEN crec.period_num=9 THEN sales_cost_month9
        ELSE 0
      END item_cogs_period9,
       CASE
        WHEN crec.period_num=10 THEN sales_cost_month10
        ELSE 0
      END item_cogs_period10,
       CASE
        WHEN crec.period_num=11 THEN sales_cost_month11
        ELSE 0
      END item_cogs_period11,
      CASE
        WHEN crec.period_num=12 THEN sales_cost_month12
        ELSE 0
      END item_cogs_period12,
      a.fiscal_year   ,
      a.budget_entity  ,
      a.organization_code,
      a.customer_id  ,
      a.inventory_item_id ,
      NULL,
      NULL,
      a.created_by ,
      a.last_updated_by ,
      a.creation_date ,
      a.last_update_date ,
      'Copied From Sales to Forecast Table of Month '||crec.period_num,
      a.attribute2,
      a.attribute3 ,
      a.attribute4 ,
      a.attribute5 ,
      a.attribute6 ,
      a.attribute7 ,
      a.attribute8 ,
      a.attribute9 ,
      a.attribute10,
      a.attribute11,
      a.attribute12,
      a.attribute13,
      a.attribute14,
      a.attribute15
      bulk collect into t1
      FROM  xxc_sales_data a 
      where  a.fiscal_year          = crec.period_year
    having CASE
                 WHEN crec.period_num=1  THEN sum(sales_amount_month1)
                 WHEN crec.period_num=2  THEN sum(sales_amount_month2)
                 WHEN crec.period_num=3  THEN sum(sales_amount_month3)
                 WHEN crec.period_num=4  THEN sum(sales_amount_month4)
                 WHEN crec.period_num=5  THEN sum(sales_amount_month5)
                 WHEN crec.period_num=6  THEN sum(sales_amount_month6)
                 WHEN crec.period_num=7  THEN sum(sales_amount_month7)
                 WHEN crec.period_num=8  THEN sum(sales_amount_month8)
                 WHEN crec.period_num=9  THEN sum(sales_amount_month9)
                 WHEN crec.period_num=10 THEN sum(sales_amount_month10)
                 WHEN crec.period_num=11 THEN sum(sales_amount_month11)
                 WHEN crec.period_num=12 THEN sum(sales_amount_month12)
                END !=0;
      FORALL i IN t1.first .. t1.last
      INSERT INTO xxc_forecast2 VALUES t1(i);
    --commit;
    END LOOP;
    END;
    Thank You

  • Append data from one table to another.

    Hi,
    I want to insert/append some or all the data from one table to another table.
    For eg: Data from table table1 to be appended to table2 with the same constraints, indexes etc. The columns are same for both the tables.
    I am using 10g version 2.
    Please specify which method would be good for this process.
    Thanks
    Jafar

    INSERT INTO TABLE1 SELECT * FROM TABLE2;The above command would insert data into table2 and it also contain the old data.Is that right,
    Thanks
    Jafar

Maybe you are looking for

  • Having data problems with ios6, seems to be a unique problem?

    My little brother recently bought an iphone 4s and imediately upgraded to ios6. Since the phone has been in use (less than 30 days) the phone company (bell a canadian company) claims he has used up 17 Gigs of data but the iphone counter says he has o

  • "itunes encountered a problem and needed to close" - help plz

    I've been using itunes for a while but when my sister got a new ipod she wanted the upgraded program so i downloaded the new program on top. It worked until we rebooted the computer and since then it would come up with an error. Afterwards, I uninsta

  • Ipad no sound - hardware issue or not?

    I dropped my ipad before and the screen was cracked. I would assume the sound was damaged by the drop. However, I still have a hope that it might be the software glitches. Two signs support my thoughts: 1. the headphone works. When I plug in, I can h

  • Please solve battery problem iOS 5.0.1 we are about to sell iPhone, iPad, iPod and replace them with others

    I have iPad, iPhone and iPod. I have updated all of them with iOS 5.0.1. After this wrong direction, all of them are facing a battery problem. Please solve solve solve it. This is a bad things from apple. We are about to stop trusting them. We have s

  • 2D application scroll problem

    Hi, maybe someone can help me with a problem I currently have: I programmed a 2D application which uses the "G" Library of Geosoft (http://geosoft.no/graphics/index.html). This library is built on top of the Java 2D API. My application draws about 10