Copying data from one table to another, but not duplicate

Good afternoon!
I am new to Oracle SQL, I have a difficulty.
I have a script that copies or add another table with data from another table.
If the table already has 01 "Registry 01" when you make a copy of the data in table 02, can not duplicate the "Registry 01" again.
As the table already exists since the beginning of the year before last and duplicate information, I can not apply the UNIQUE constraint because of the error. I have to make this change from now.
How to perform this validation so that no duplicate data?
DECLARE
w_cont NUMBER;
CURSOR c_simpro IS
SELECT sc.cd_simpro,
sc.ds_produto,
sp.qt_embalagem,
MAX(sp.dt_vigencia)
FROM simpro_cadastro sc,
simpro_preco sp
WHERE sc.cd_simpro = sp.cd_simpro
GROUP BY sc.cd_simpro,
sc.ds_produto,
sp.qt_embalagem;
BEGIN
FOR r_simpro IN c_simpro LOOP
w_cont := 0;
SELECT COUNT(1)
INTO w_cont
FROM pls_material pm
WHERE pm.cd_material_ops = r_simpro.cd_simpro;
IF w_cont = 0 THEN
INSERT INTO pls_material(nr_sequencia,
dt_atualizacao,
nm_usuario,
dt_atualizacao_nrec,
nm_usuario_nrec,
ie_tipo_despesa,
cd_estabelecimento,
nr_seq_estrut_mat,
cd_simpro,
ds_material,
ie_situacao,
ds_material_sem_acento,
dt_inclusao,
cd_material_ops_orig,
cd_unidade_medida,
cd_material_ops,
qt_conversao_simpro)
VALUES(pls_material_seq.nextval,
SYSDATE,
'ES-SIMPRO',
SYSDATE,
'ES-SIMPRO',
3,
1,
3,
r_simpro.cd_simpro,
r_simpro.ds_PRODUTO,
'A',
r_simpro.ds_PRODUTO,
SYSDATE,
r_simpro.cd_simpro,
'un',
TRIM(to_char(r_simpro.cd_simpro,'0000099999')),
r_simpro.qt_embalagem);
COMMIT;
END IF;
IF w_cont > 0 THEN
UPDATE pls_material p
SET p.qt_conversao_simpro = r_simpro.qt_embalagem,
p.dt_atualizacao = SYSDATE
WHERE p.cd_simpro = r_simpro.cd_simpro;
COMMIT;
END IF;
END LOOP;
END;
Edited by: 983464 on 22/01/2013 10:30

Hi,
in addition to what Marwin has already said, I suggest you to post CREATE TABLE and INSERT statements (as mentioned in the FAQ).
The error you are getting from MERGE command is because you need a way to uniquely identify within the table. So it's is important to know also if your table has a primary key/unique index so the keys could to be used in the MERGE command.
Additionally when you put some code or output please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
Regards.
Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • T code to Copy Data from one table to another table

    Hi,
    I want copy all data of one table to its copy table. Anyone knows transaction code to copy data from one table to another table.
    Regards,
    Jigar Thakkar.

    Hi
    Create a small program.
    Extract data from T1 - database table and put it in one internal table - itab1.
    loop the itab1 data .............
        insert itab1 into tab2.   (tab2 - second database table)
    endloop.
    try this....
    hope it works....

  • How to copy data from one table to another (in other database)

    Hi. I would like to copy all rows from one table to another (and not use BC4J). Tables can be in various databases. I have already 2 connections and I am able to browse source table using
    ResultSet rset = stmt.executeQuery("select ...");
    But I would not like to create special insert statement for every row . There will be problems with date formats etc and it will be slow. Can I use retrieved ResultSet somehow ? Maybe with method insertRow, but how, if ResultSet is based on select statement and want to insert into target table? Please point me in the right direction. Thanks.

    No tools please, it must be common solution. We suceeded in converting our BC4J aplication to PostgreSQL, the MSSQL will be next. So we want to write simple aplication, which could transfer data from our tables between these 3 servers.

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

  • 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

  • Copy data from one table to another

    Hello everyone,
    I have a student table with fields sno, sname. I created another table student1 with same fields sno, sname and with one new field class.
    Now i want to copy data from sno, sname of student table to sno, sname of student1 table when the class field in styudent1 has no data i.e., its null.
    Could any one let me know how to do this?
    Thanks,
    Prathima

    i want to copy data from sno, sname of student table to sno, sname
    of student1 table when the class field in styudent1 has no dataSo what is the join condition? What column in STUDENT1 tells us what row in STUDENT to copy?
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • Copying data from one table to another

    Hello!
    I have a table (TABLE1) and I want to copy part of TABLE1's data to an another table (TABLE2).This proccess is made by an application in PROC Language with ORACLE 8.1 in UNIX environment.
    1) I've tried to make the copy with a cursor:
    void search() {
    char alias[ALIASTAM];
    struct tpNoticia noticia;
    printf("Introduzca el nombre del autor: ");
    scanf("%s",alias);
    EXEC SQL DECLARE AUX CURSOR FOR
    SELECT idNoticia,titulo,texto,TO_CHAR(publicacion,'HH24:MI:SS DD-MM-YYYY'),
                        URLimagen,numVisitas,sumaVal,totalVal,esBorrador,alias,nombreT
    FROM TABLE1
         WHERE alias=:alias;
    EXEC SQL OPEN AUX;
    EXEC SQL WHENEVER NOT FOUND DO break;
    for (;;) {
    EXEC SQL FETCH AUX INTO :noticia;
    printf("%d %s \n", noticia.idNoticia,noticia.titulo);
    EXEC SQL INSERT INTO TABLE2 (idNoticia,titulo,texto,publicacion,URLimagen,numVisitas,sumaVal,totalVal,esBorrador,alias,nombreT)
    VALUES (:(noticia.idNoticia),:(noticia.titulo),:(noticia.texto), TO_DATE('00:00:00 01-01-1900','HH24:MI:SS DD-MM-YYYY'),:(noticia.URLimagen),:(noticia.numVisitas),
         :(noticia.sumaVal),:(noticia.totalVal),:(noticia.esBorrador),:(noticia.alias),:(noticia.nombreT));
    EXEC SQL CLOSE AUX;     
    IN THIS CURSOR printf SHOWS CORRECTLY THE DATA BUT IT ISN'T INSERTED INTO TABLE 2;
    2) I've tried to define TABLE2 from TABLE1:
    EXEC SQL CREATE TABLE TABLE2 AS
    SELECT * FROM TABLE1 WHERE alias=:alias
    BUT MY COMPILER SAYS: PCC-S-02206, Host variables are not permitted within a DDL statement
    ANY IDEA???
    Thanks

    If you want to create the table dynamically, then you have to use dynamic Sql. Didn't you like my above suggestion ? If you want I can post a small example of a similar stored procedure.
    See also http://www.mcs.csuhayward.edu/support/oracle/doc/8.1.7/appdev.817/a76942/pc_07pls.htm#2778

  • Can you check for data in one table or another but not both in one query?

    I have a situation where I need to link two tables together but the data may be in another (archive) table or different records are in both but I want the latest record from either table:
    ACCOUNT
    AccountID     Name   
    123               John Doe
    124               Jane Donaldson           
    125               Harold Douglas    
    MARKETER_ACCOUNT
    Key     AccountID     Marketer    StartDate     EndDate
    1001     123               10526          8/3/2008     9/27/2009
    1017     123               10987          9/28/2009     12/31/4712    (high date ~ which means currently with this marketer)
    1023     124               10541          12/03/2010     12/31/4712
    ARCHIVE
    Key     AccountID     Marketer    StartDate     EndDate
    1015     124               10526          8/3/2008     12/02/2010
    1033     125               10987         01/01/2011     01/31/2012  
    So my query needs to return the following:
    123     John Doe                        10526     8/3/2008     9/27/2009
    124     Jane Donaldson             10541     12/03/2010     12/31/4712     (this is the later of the two records for this account between archive and marketer_account tables)
    125     Harold Douglas               10987          01/01/2011     01/31/2012     (he is only in archive, so get this record)
    I'm unsure how to proceed in one query.  Note that I am reading in possibly multiple accounts at a time and returning a collection back to .net
    open CURSOR_ACCT
              select AccountID
              from
                     ACCOUNT A,
                     MARKETER_ACCOUNT M,
                     ARCHIVE R
               where A.AccountID = nvl((select max(M.EndDate) from Marketer_account M2
                                                    where M2.AccountID = A.AccountID),
                                                      (select max(R.EndDate) from Archive R2
                                                    where R2.AccountID = A.AccountID)
                   and upper(A.Name) like parameter || '%'
    <can you do a NVL like this?   probably not...   I want to be able to get the MAX record for that account off the MarketerACcount table OR the max record for that account off the Archive table, but not both>
    (parameter could be "DO", so I return all names starting with DO...)

    if I understand your description I would assume that for John Dow we would expect the second row from marketer_account  ("high date ~ which means currently with this marketer"). Here is a solution with analytic functions:
    drop table account;
    drop table marketer_account;
    drop table marketer_account_archive;
    create table account (
        id number
      , name varchar2(20)
    insert into account values (123, 'John Doe');
    insert into account values (124, 'Jane Donaldson');
    insert into account values (125, 'Harold Douglas');
    create table marketer_account (
        key number
      , AccountId number
      , MktKey number
      , FromDt date
      , ToDate date
    insert into marketer_account values (1001, 123, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('27.09.2009', 'dd.mm.yyyy'));
    insert into marketer_account values (1017, 123, 10987, to_date('28.09.2009', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
    insert into marketer_account values (1023, 124, 10541, to_date('03.12.2010', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
    create table marketer_account_archive (
        key number
      , AccountId number
      , MktKey number
      , FromDt date
      , ToDate date
    insert into marketer_account_archive values (1015, 124, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('02.12.2010', 'dd.mm.yyyy'));
    insert into marketer_account_archive values (1033, 125, 10987, to_date('01.01.2011', 'dd.mm.yyyy'), to_date('31.01.2012', 'dd.mm.yyyy'));
    select key, AccountId, MktKey, FromDt, ToDate
         , max(FromDt) over(partition by AccountId) max_FromDt
      from marketer_account
    union all
    select key, AccountId, MktKey, FromDt, ToDate
         , max(FromDt) over(partition by AccountId) max_FromDt
      from marketer_account_archive;
    with
    basedata as (
    select key, AccountId, MktKey, FromDt, ToDate
      from marketer_account
    union all
    select key, AccountId, MktKey, FromDt, ToDate
      from marketer_account_archive
    basedata_with_max_intervals as (
    select key, AccountId, MktKey, FromDt, ToDate
         , row_number() over(partition by AccountId order by FromDt desc) FromDt_Rank
      from basedata
    filtered_basedata as (
    select key, AccountId, MktKey, FromDt, ToDate from basedata_with_max_intervals where FromDt_Rank = 1
    select a.id
         , a.name
         , b.MktKey
         , b.FromDt
         , b.ToDate
      from account a
      join filtered_basedata b
        on (a.id = b.AccountId)
    ID NAME                     MKTKEY FROMDT     TODATE
    123 John Doe                  10987 28.09.2009 31.12.4712
    124 Jane Donaldson            10541 03.12.2010 31.12.4712
    125 Harold Douglas            10987 01.01.2011 31.01.2012
    If your tables are big it could be necessary to do the filtering (according to your condition) in an early step (the first CTE).
    Regards
    Martin

  • Can I use Migration Assistant to Copy files from one mac to another, but not delete the original files off of the original Mac?

    I just purchased a new Macbook Pro Retina, and I have an old Macbook Pro w/o Retina and wish to use migration assistant. I still want to use the older Macbook Pro and keep all the files on it, but copy them and also put them on my new Macbook. What I'm trying to say is, can I use migration assistant to move files to a new Mac, while keeping the files on the old computer?

    You can omit some broad categories, but you can't pick and choose individual items.
    See Using Setup Assistant on Mountain Lion or Lion (preferred method), or the similar Using Migration Assistant on Mountain Lion or Lion for the gory details.

  • 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

  • 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

  • What are the diffrent ways to copy data from one application to another?

    Hi,
    Can you guys tell me what are the different ways to copy data from one application to another application??
    I know we can do it through script logic using DESTINATION_APP.
    Is there any other way to copy data from one application to another application?
    Please help me
    Thanks,
    Charly

    You can also call a custom DTSX package in SSIS via the datamanager.
    there are at least 5 ways of transfering data in BPC between apps.
    1. Through the front end (excel etc) via evdre/evsnds
    2. Through Script logic using *Dest App
    3. Using BPC's standard export dtsx package via DM
    4. Using SSIS using BPC's custom SSIS tasks
    5. Through Script logic using stored procs.
    i am sure people will come up with more.
    remember if you use ssis and move data into any table but the wb, you need to process the cube afterwards.

  • 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

  • Trigger to copy records from one table to another;  ORA-04091:

    Hello,
    I'm trying to create a trigger that will move data from one table to another.
    I have two tables (Trial1, Trial2) Both of them contains the same attributes (code, c_index)
    I want to move each new record inserted in (code in Trial1) to (code in Trial2)
    This is my trigger:
    Create or replace trigger trg_move_to_trial2
    After insert on Trial1
    for each row
    begin
    insert into Trial2 (code)
    select :new.code from Trial1;
    end;It compiled, but when I insert new (code) record into (Trial1) it display this error:
    Error report:
    SQL Error: ORA-04091: table STU101.TRIAL1 is mutating, trigger/function may not see it
    ORA-06512: at "STU101.TRG_MOVE_TO_TRIAL2", line 3
    ORA-04088: error during execution of trigger 'STU101.TRG_MOVE_TO_TRIAL2'
    04091. 00000 - "table %s.%s is mutating, trigger/function may not see it"
    *Cause:    A trigger (or a user defined plsql function that is referenced in
    this statement) attempted to look at (or modify) a table that was
    in the middle of being modified by the statement which fired it.
    *Action:   Rewrite the trigger (or function) so it does not read that table.I know what does this error mean, but I don't how to fix the error.
    I tried to change the (After insert on Trial1) to be (Before insert on Trial1); that worked, but not in the right way. When I insert new value into (code in Trial1) and refreshed Trial2 table, as much as records I have in Trial 2 they will be duplicated. E.g.
    Trial2
    code
    111
    222
    333when I insert in Trial1
    Trial1
    code
    444
    Trial2 will be:
    code
    111
    222
    333
    444
    444
    444Can you please tell me how to solve this issue?
    Regards,
    Edited by: 1002059 on Apr 23, 2013 5:36 PM

    You should not select from Trial1 - you have the data already. Just insert that value.
    Create or replace trigger trg_move_to_trial2
    After insert on Trial1
    for each row
    begin
    insert into Trial2 (code)
    values (:new.code);
    end; regards,
    David

Maybe you are looking for

  • What is BADI.How to create a BADI?

    Hi all, Can some one explain me about , What is an BADI.Where it is used . How to create a BADI. Iam in Initial stage, I want to know how to create a BADI. Please help me regarding this. Thanks, Lee.

  • Is it possible to install a single component from the install dvd?

    My install went very well, however the only problem is that the colorsync utility will  not launch. I would rather not do a complete reinstall of the entire system... ( particularly because of my shrinking HD). Can I do this? Thanks in advance, Carl

  • Intermittent "Unsupported image format" message with either CR2 or DNG

    I am seeing "Unsupported image format" messages once files created by a Canon EOS 1Ds Mark iii (+stored in Canon's CR2 file format or when the same file is converted to Adobe's DNG file format+) have been imported into Aperture. Some files will impor

  • Multiple Web Site one IP

    Is there a way with 1 IP address to host more then 1 web site in apache. IE you have your main server at main.server.com and then a test site at test.server.com? Each has there own root folder or web folder? Thanks

  • Changing color of background

    Hi, I am using Adobe Photoshop CS5 (64 bit) and I would like to know how to change the background color of my .tiff file.  It is a black and white picture, and I just would like to change the white portion to a different color, such as green, yellow,