Compare data in one table

Hi all,
I have a problem with comparing two rows in one table.
The situation:
Person_1 have to insert row_1 in table_xy.
After a while person_2 has to insert the same data as row_2 for controlling person_1 in table_xy.
I have created a compare_flag in table_xy to mark person_2.
Now I have created a form_1 on table_xy for person_1 and another form_2 on table_xy for person_2.
In form_1 the column compare_flag is hidden, because nothing has to be insert into the table_xy in this case.
In form_2 the column_flag has to be automatically inserted into the table. How can I manage this?
After this I have two compare the two values, but how can I do this?
Thanks for help,
Detlef

Hi Andy,
unfortunately it doesn't work. I think I'll have to describe my problem in clear way.
There is a table compare_test with
CREATE TABLE "COMPARE_TEST"
(     "COMPARE_ID" NUMBER NOT NULL ENABLE,
     "FISHNAME" VARCHAR2(300),
     "FISH_VALUE1" NUMBER,
     "FISH_VALUE2" NUMBER,
     "FISH_VALUE3" NUMBER,
     "FISH_VALUE4" NUMBER,
     "FISH_VALUE5" NUMBER,
     "COMPARE_FLAG" VARCHAR2(1),
     CONSTRAINT "COMPARE_TEST_PK" PRIMARY KEY ("COMPARE_ID") ENABLE
The column FISHNAME is a foreign key.
A person 1 in the laboratory has to insert his results in the table above. Another person 2 in the office has to check this entires once again, cause person 1 could have made errors during the input.
After the inputs of person 1 and 2 it must be possible to compare this two rows.
Therefore the column compare_flag is to be filled after the input of person 2 with a 'Y'.
It is possible the fact that person 1 and person 2 exchange and person 2 the first entry and person 1 accomplishes the control entry.
First of all, I'm looking for a way to fill the column COMPARE_FLAG automatically with the 'Y' when person 2 fill in the form.
Last but not least I want to compare the two entires about differences.
Thanks,
Detlef

Similar Messages

  • Compare data from a table

    Hello, I am trying to compare data from one and the same table. In short I have:
         NAME     DTM     CHARGE
         Atanas     8/18/2012 9:33:23 AM     100
    Atanas     8/18/2012 9:33:23 AM     101
         Niki     8/18/2012 9:33:43 AM     200
         Niki     8/17/2012 9:34:10 AM     100
    Niki     8/18/2012 9:33:43 AM     201
         Niki     8/17/2012 9:34:10 AM     101
         Atanas     8/17/2012 9:34:29 AM      50
    Atanas     8/17/2012 9:34:29 AM      51
         Joro     8/18/2012 12:10:12 PM 400
         Joro     8/17/2012 12:10:21 PM 300
    Joro     8/18/2012 12:10:12 PM 401
         Joro     8/17/2012 12:10:21 PM 301
    And I want to sum CHARGE for each DTM for each NAME and present the difference in an additional column, the output should be like that:
    NAME     DTM     CHARGE DTM CHARGE DIFFERENCE
         Atanas     8/17/2012 9:33:23 AM     101 8/18/2012 9:33:23 AM 201 - 100
    Niki     8/17/2012 9:33:23 AM     201 8/18/2012 9:33:23 AM 401 - 200
    Joro     8/17/2012 9:33:23 AM     601 8/18/2012 9:33:23 AM 801 200
    the DTM will be always /sysdate - 2/ and /sysdate - 1/,
    Thanks in advance!

    It is not clear what you are trying to do, but it looks like:
    with sample_table as (
                          select 'Atanas' name,to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am') dtm,100 charge from dual union all
                          select 'Atanas',to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
                          select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),200 from dual union all
                          select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),100 from dual union all
                          select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),201 from dual union all
                          select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
                          select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),50 from dual union all
                          select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),51 from dual union all
                          select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),400 from dual union all
                          select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),300 from dual union all
                          select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),401 from dual union all
                          select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),301 from dual
    select  nvl(s1.name,s2.name) name,
            s1.dtm,
            s1.charge,
            s2.dtm,
            s2.charge,
            s2.charge - s1.charge diff
      from      (
                 select  name,
                         dtm,
                         sum(charge) charge
                   from  sample_table
                   where dtm >= trunc(sysdate) - 1
                     and dtm <  trunc(sysdate)
                   group by name,
                            dtm
                ) s1
            full join
                 select  name,
                         dtm,
                         sum(charge) charge
                   from  sample_table
                   where dtm >= trunc(sysdate)
                     and dtm <  trunc(sysdate) + 1
                   group by name,
                            dtm
                ) s2
              on s1.name = s2.name
    NAME   DTM           CHARGE DTM           CHARGE       DIFF
    Atanas 17-AUG-12        101 18-AUG-12        201        100
    Niki   17-AUG-12        201 18-AUG-12        401        200
    Joro   17-AUG-12        601 18-AUG-12        801        200
    SQL> SY.

  • How to compare data between two tables?

    Hi,
    My team is trying to develop a SAP data migration tool (DMT) using ABAP.
    One of the functionalities in the DMT is to validate the data in the staging area against the loaded SAP data.
    The tables in the stagin area are customer tables (i.e. user-defined tables starting with Y, Z).
    How do I compare the data in the staging area against data that are loaded into SAP tables? Are there some built-in SAP functions to do this? Or, are there some better ways of doing this (e.g. instead of comparing against data in the SAP tables, we compare with some INTERNAL tables)?
    Any help would be greatly appreciated, thanks!

    Hi Kian,
    Use <b>SCMP</b> transaction to compare data between two tables and you can not use this for comparing internal tables.
    Thanks,
    Vinay

  • Compare data between two tables of same schema

    Folks,
    I have one very intresting query which i would like to share with you all and looking forward for the solution asap.
    Scenario
    I have two table say TableA and TableB, both having same structre say as below
    TableA
    Col1 Var(10)
    Col2  INT
    TableB
    Col1 Var(10)
    Col2  INT
    I want to compare data between these two tables and store compared data into third table, let me expalin the whole scenario.
    TableA
    ColA          ColB
    INDIA          1
    PAKistan      2
    TableB
    ColA          ColB
    INDIA          1
    PAK             3
    I want result like
    Difference
    ColA          ColB
    True            0
    False           -1
    I want to store this difference in thrid table.
    i.e. when comparing text, i need TRUE when compare 100% else False, Caption is not considered.
         When comparing numeric value, simple sub is requried , TableA-TableB
    Note - I dont want to use any external tool to compare the table data, i required sql query to do the same.
    Thanks
    Amit Srivastava
    Amit
    Please mark as answer if helpful
    http://fascinatingsql.wordpress.com/

    Whereas the abbreviation of countries that exist in Table2 table are the first three letters of the name of the country*, here's a suggestion:
    -- code #1 v2
    INSERT into [Difference] (Col1, Col2, ACol1, BCol1)
    SELECT case when A.Col1 = B.Col1 then 'true' else 'false' end,
    (IsNull(A.Col2, 0) - IsNull(B.Col2, 0)), A.Col1, B.Col1
    from TableA as A full outer join
    TableB as B on (A.Col1 = B.Col1
    or Left(A.Col1, 3) = B.Col1);
    Is the COLLATE database case insensitive? If not, the code #1 above will have to be modified, using the upper () function or using COLLATE case insensitive in A.Col1 and B.Col1 columns.
    But if the abbreviation of the country follow the
    ISO 3166-1 alpha-3 standard, will require a fourth table containing the symbol and name of countries.
    -- code #2 v2
    ;with
    TableB_2 as (
    SELECT case when Len(Col1) = 3
    then (SELECT Country_name from [ISO 3166-1 a3] where Cod = Col1)
    else Col1 end as Col1, Col2
    from TableB
    INSERT into [Difference] (Col1, Col2, ACol1, BCol1)
    SELECT case when A.Col1 = B.Col1 then 'true' else 'false' end,
    (IsNull(A.Col2, 0) - IsNull(B.Col2, 0)), A.Col1, B.Col1
    from TableA as A full outer join
    TableB_2 as B on A.Col1 = B.Col1;
    Structure and data to test:
    use tempdb;
    CREATE TABLE TableA (Col1 varchar(10), Col2 int);
    CREATE TABLE TableB (Col1 varchar(10), Col2 int);
    CREATE TABLE [Difference] (Col1 varchar(10), Col2 int, ACol1 varchar(10), BCol1 varchar(10));
    INSERT into TableA values ('INDIA', 1), ('PAKistan', 2), ('China', 12);
    INSERT into TableB values ('INDIA', 1), ('PAK', 3), ('Bhutan', 3);
    go
    CREATE TABLE [ISO 3166-1 a3] (Cod char(3) primary key, [Country_name] varchar(30));
    INSERT into [ISO 3166-1 a3] values
    ('IND', 'India'), ('PAK', 'Pakistan'), ('CHN', 'China'), ('BGD', 'Bangladesh'),
    ('BTN', 'Bhutan'), ('MMR', 'Myanmar'), ('NPL', 'Nepal');
    go
    (*) If the short form of the country name using the first three letters of the country name,
    false positives can occur. For example,
    Mali and Malta or
    Angola and Anguilla.
    José Diz     Belo Horizonte, MG - Brasil

  • 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 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

  • 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

  • Copy data from one Table to another Table

    How can I copy data from one Oracle Table to another Oracle Table on a different server? Question 2: How can I clear all of the data in one Table with a single SQL script?
    Thanks...

    Question 1:
    I assume you have the privileges. If you don't, ask the DBA to give them to you. Then
    1. Login to database_source (It could be either the source or the target. Let's assume it's the source.)
    2. Create a database link to database_target: CREATE DATABASE LINK link_to_database_target CONNECT TO myuserid IDENTIFIED BY mypassword USING 'database_target'; Note the single quotes.
    3. Copy the table data: INSERT INTO targetowner.mytable@link_to_database_target SELECT * FROM sourceowner.mytable; COMMIT;
    Question 2:
    You have two options, but you may not have privileges for both.
    Option 1:
    DELETE FROM tableowner.tablename; COMMIT;
    Advantage: Since this is a DML (Data Manipulation Language) statement, you have to commit the transaction. Also, the data will be gone but the table size is NOT changed, so it's ready for accepting replacement data. DML statements can simply be executed not only from SQL scripts, but from PL/SQL scripts as well.
    Disadvantage: Slow, because all record deletion is logged, so you can recover from it by issuing a ROLLBACK; instead of the COMMIT; above. The table size is NOT changed, so if you are short of disk space or tablespace space, you have not resolved the issue.
    Option 2:
    TRUNCATE TABLE tableowner.tablename;
    Advantage: Since this is a DDL (Data Definition Language) command, you do NOT have to commit the transaction. (DDL commands automatically commit both before and after their execution.) The table size will be changed back to the initial extent size which is the minimum size a table can have and can only be set when the table is created. If it needs to be changed, the table has to be dropped and recreated with a different initial extent size. The statement execution of this command is not logged, therefore it's much faster then the DELETE.
    Disadvantage: No rollback. Being a DDL, this command cannot be executed straight from PL/SQL. If you need to issue this within PL/SQL, you will have to use dynamic SQL.

  • Moving data from one table to another table in a diferent Database..

    I need to move the data of one table from one database to another table in a different database, is there a way to do this. Do I need the systemn password? or the password of the schema that own the table is enough? the tables are name different, same columns but different name. I know I can do it via sqlldr(creating a file...then runing the ctl file..etc), but I am wonder if it is a different way of doing it?
    Thank you

    Your question is more suitable for the Database-General forum @ General Database Discussions
    (You'll find more DBA's over there, although some of them take a glance over here as well every now and then ;) )
    Do not forget to mention the versions of both databases...

  • 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

  • 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

  • Moving Data from one table to another table

    Hi,
    I've a requirement to move large volumes (few billions) of data from one table to another empty target table. The target has more number of attributes and may not have same attribute name as the source. Please let me know what's the best method using oracle to move data in this case?
    Thanks in Advance,
    Tom

    You should use nologging and parallelism options
    Please refer to Tom's answers:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:164612348068
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6407993912330
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

  • Appending data from one table to another

    Hello
    How to append data from one table t1 to another table t2.
    t1 and t2 have the same structures .
    t2 contains already data so i don't want do delete it and create it as select * from t1.
    If there is a mean to add t1 content without altering t2 content.
    Thanks in advance

    insert into t2
      select * from t1

  • 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