Writing a BULK Update for a Update statement

I want write(convert) this Query in PL/sql code using Bulk Collect and Update since this query is taking more time to execute. How I can achive this ?
Please Help me.
UPDATE my_master aa
SET (pay_date, last_mod_by, last_mod_date, verified_status) =
(SELECT TO_DATE ('03/09/2007', 'dd/mm/yyyy'), 'S1',
TO_DATE ('22/02/2008', 'dd/mm/yyyy'), 'Y'
FROM dtl_1 a, dtl_2 b
WHERE a.br_id = b.nr_id
AND aa.acct_num = a.acct_num
AND TO_DATE (TO_CHAR (aa.dat1, 'mm/yyyy'),
'mm/yyyy'
) <
TO_DATE (TO_CHAR (a.dat1, 'mm/yyyy'),
'mm/yyyy'
WHERE (acct_num) =
(SELECT a.acct_num
          FROM dtl_1 a, dtl_2 b
WHERE a.br_id = b.nr_id
aa.acct_num = a.acct_num
AND TO_DATE (TO_CHAR (aa.dat1, 'mm/yyyy'),
'mm/yyyy'
) <
TO_DATE (TO_CHAR (a.dat1, 'mm/yyyy'),
'mm/yyyy'
AND dat1 <
(SELECT a.dat1
FROM dtl_1 a, dtl_2 b
WHERE a.br_id = b.nr_id
aa.acct_num = a.acct_num
AND TO_DATE (TO_CHAR (aa.dat1, 'mm/yyyy'),
'mm/yyyy'
) <
TO_DATE (TO_CHAR (a.dat1, 'mm/yyyy'),
'mm/yyyy'
))

"More" is a relative term. More than what? Perhaps you just mean it is taking a long time and you think it should be possible to make it faster.
First, if I tidy up the query and simplify the date expressions so it's easier to read, I get this, which should give the same results (but not be any faster):
UPDATE my_master aa
SET    ( pay_date, last_mod_by, last_mod_date, verified_status ) =
       ( SELECT DATE '2007-09-03', 'S1', DATE '2008-02-22', 'Y'
         FROM   dtl_1 a
              , dtl_2 b
         WHERE  a.acct_num = aa.acct_num
         AND    TRUNC(aa.dat1,'mm') < TRUNC(a.dat1,'mm')
         AND    b.nr_id = a.br_id )
WHERE  acct_num =
       ( SELECT a.acct_num
         FROM   dtl_1 a
              , dtl_2 b
         WHERE  a.acct_num = aa.acct_num
         AND    TRUNC(a.dat1,'mm') > TRUNC(aa.dat1,'mm')
         AND    b.nr_id = a.br_id )
AND    dat1 <
       ( SELECT a.dat1
         FROM   dtl_1 a
              , dtl_2 b
         WHERE  a.acct_num = aa.acct_num
         AND    TRUNC(a.dat1,'mm') > TRUNC(aa.dat1,'mm')
         AND    b.nr_id = a.br_id );If so, I'm a bit confused by the second subquery. Don't you already compare dat1 in the first subquery? I can't test this but isn't it the same as:
UPDATE my_master aa
SET    ( pay_date, last_mod_by, last_mod_date, verified_status ) =
       ( SELECT DATE '2007-09-03', 'S1', DATE '2008-02-22', 'Y'
         FROM   dtl_1 a
              , dtl_2 b
         WHERE  a.acct_num = aa.acct_num
         AND    TRUNC(aa.dat1,'mm') < TRUNC(a.dat1,'mm')
         AND    b.nr_id = a.br_id )
WHERE  EXISTS
       ( SELECT NULL
         FROM   dtl_1 a
              , dtl_2 b
         WHERE  a.acct_num = aa.acct_num
         AND    TRUNC(a.dat1,'mm') > TRUNC(aa.dat1,'mm')
         AND a.dat1 > aa.dat1
         AND    b.nr_id = a.br_id );Although if a.dat1 is in a later month than aa.dat1 then the second check is redundant anyway.
Message was edited by:
William Robertson

Similar Messages

  • Is there a bulk update statement in 11g?

    Hi everyone,
    This is a pretty simple request but I cannot seem to find any documentation for it (at least on the 11g DB version).
    I have a simple update statement:
    UPDATE W_AP_XACT_FS SET DATASOURCE_NUM_ID = 5;
    COMMIT;It probably seems strange why I would want to do that, but suffice it to say that I have no control over what value gets loaded into that column, however, I do need to correct it.
    Either way, I want to make the above statement as efficient as possible.
    What's the fastest way to perform a quick static update like that? Is there such a thing as a bulk update statement?
    Thanks for the help!
    -Joe

    I need something that works 100% of the time and doesn't hang & create a DB lock.It has to lock the records it's updating until you commit. You could commit more frequently via a procedural approach but that is generally considered a bad idea because it's slower, takes more resources and risks 'snapshot too old' errors. 'Hanging' can mean a number of things, so I'm not sure which scenario you need to avoid here apart from the update taking a long time. Maybe it's just processing a lot of rows, in which case you might be able to throw some more resources at it with parallel DML. Or maybe it's blocked by another session, in which case you can find out a lot from v$session, v$lock, dba_blockers etc.
    UPDATE W_AP_XACT_FS SET DATASOURCE_NUM_ID = 5;Could there ever be any rows prior to the update that already have DATASOURCE_NUM_ID = 5? If so, adding
    WHERE datasource_num_id != 5;(if datasource_num_id is mandatory) or something like
    WHERE datasource_num_id != 5
    OR    datasource_num_id IS NULL;(if it's nullable) would reduce the number of rows needing to be processed.
    Edited by: William Robertson on Aug 1, 2010 8:07 PM

  • Problem in bulk update on partitioned table

    Hi,
    As per my old discussions on my huge table t_utr with 220 million rows,
    I'm running a bulk update statement on the table which may update 10 to 10 million rows in a single update statement.
    The problem is that when the statement has to update more number of rows, the update statement take more time.
    Here I want to know, when a update statement has to update more rows, will it impact the performance?
    Regards
    Deepak

    > I'm running a bulk update statement on the table
    which may update 10 to 10 million rows in a single
    update statement.
    Bulk updates does not make SQL statements execute any faster.
    > The problem is that when the statement has to update
    more number of rows, the update statement take more
    time.
    It is not a problem, but a fact.
    > Here I want to know, when a update statement has to
    update more rows, will it impact the performance?
    You have a car capable of traveling 120km/h. You drive from point A to point B. These are 10 km apart. It takes 5 minutes.
    Obviously when you travel from A to Z that are a 1000 km apart, it is going to take a lot longer than just 5 minutes.
    Will updating more rows impact performance? No. Because you cannot compare the time it takes to travel from point A to B with the time it takes to travel from point A to Z. It does not make sense wanting to compare the two. Or thinking that a 1000km journey will be as fast to travel than a 10km journey.
    Updating 10 rows cannot be compared to updating 10 million rows. Expecting a 10 million row update to be equivalent in "performance" to a 10 row update is ludicrous.
    The correct question to ask is how to optimise a 10 million row update. The optimisation methods for a large update is obviously very different than those of a small update. E.g. 5 I/Os per row updated is insignificant when updating 10 rows. But is very significant when updating 10 million rows.

  • How to tune the Update statement for 20 million rows

    Hi,
    I want to update 20 million rows of a table. I wrote the PL/SQL code like this:
    DECLARE
    v1
    v2
    cursor C1 is
    select ....
    BEGIN
    Open C1;
    loop
    fetch C1 bulk collect into v1,v2 LIMIT 1000
    exit when C1%NOTFOUND;
    forall i in v1.first..v1.last
    update /*+INDEX(tab indx)*/....
    end loop;
    commit;
    close C1;
    END;
    The above code took 24 mins to update 100k records, so for around 20 million records it will take 4800 mins (80 hrs).
    How can I tune the code further ? Will a simple Update statement, instead of PL/SQL make the update faster ?
    Will adding few more hints help ?
    Thanks for your suggestions.
    Regards,
    Yogini Joshi

    Hello
    You have implemented this update in the slowest possible way. Cursor FOR loops should be absolute last resort. If you post the SQL in your cursor there is a very good chance we can re-code it to be a single update statement with a subquery which will be the fastest possible way to run this. Please remember to use the {noformat}{noformat} tags before and after your code so the formatting is preserved.
    David                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Find affected rows when using OCIBindArrayOfStruct for UPDATE statement

    If I run a bulk UPDATE query using OCIBindArrayOfStruct, is there a way I can tell which+ rows successfully updated?
    I have a file of records of which 75% of PKs are already in the table and will be updated, the other 25% aren't and should be inserted later. I want to attempt an UPDATE statement on each entry in the file, using OCIBindArrayOfStruct to execute in bulk, and then check which entries in my bulk array successfully updated. If an array entry isn't successfully updated then I will assume it should be inserted and will store it for a Direct Path load later.
    Many thanks for any advice you can give as I've been trawling through the docs trying to find a solution for ages now.
    Edited by: Alasdair on 15-Oct-2010 02:13

    To get count from DB using dynamic SQL, you might need form to call a DB function that can run a query and return a number.
    ie
    CREATE OR REPLACE FUNCTION get_count(pTable VARCHAR2, pWhere VARCHAR2) RETURN NUMBER IS
       vCount VARCHAR2(2000);
    BEGIN
       EXECUTE IMMEDIATE
          'SELECT COUNT(1) FROM '||pTable||' WHERE '||pWhere
       INTO vCount;
       RETURN vCount;
    END;Then in your form you do:
       vUpDCnt := get_count(pTable=>'some_table',pWhere=>'...');Hope this helps.

  • Bulk SQL Update Statements

    I need to perform bulk updates on my tables using SQL. The tables are really very big and most of updates occur on couple of million records. As such the process is time consuming and very slow. Is there anything I could do to fine tune these update statements? Please advise. Some of the same SQL statements I use are as follows
    update test set gid=1 where gid is null and pid between 0 and 1;
    update test set gid=2 where gid is null and pid between 1 and 5;
    update test set gid=3 where gid is null and pid between 5 and 10;
    update test set gid=4 where gid is null and pid between 10 and 15;
    update test set gid=5 where gid is null and pid between 15 and 70;
    update test set gid=6 where gid is null and pid between 70 and 100;
    update test set gid=7 where gid is null and pid between 100 and 150;
    update test set gid=8 where gid is null and pid between 150 and 200;
    update test set gid=9 where gid is null and pid between 200 and 300;
    Message was edited by:
    user567669

    Indeed, check out the predicate:
    SQL> explain plan for
      2  select *
      3  from emp
      4  where sal between 1000 and 2000;
    Explained.
    SQL> @utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     5 |   185 |     3   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| EMP  |     5 |   185 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - filter("SAL"<=2000 AND "SAL">=1000)

  • Need help to write a query for Update statement with  join

    Hi there,
    The following update statement gives me error as the given table in set statement is invalid. But its the right table .
    Is the statement correct? Please help .
    update (
           select distinct(vpproadside.VEHICLE_CRED_OVERRIDE.vin)            
             from vpproadside.VEHICLE_CRED_OVERRIDE
             join vpproadside.vpp_vehicle
               on vpproadside.vpp_vehicle.vin = vpproadside.VEHICLE_CRED_OVERRIDE.vin
            where VPP_CARRIER_SEQ_NUMBER = 90
              and EXPIRY_DATE = '17-MAR-10'
       set vpproadside.VEHICLE_CRED_OVERRIDE.EXPIRY_DATE = '15-SEP-10';Edited by: Indhu Ram on Mar 12, 2010 1:00 PM
    Edited by: Indhu Ram on Mar 12, 2010 1:22 PM
    Edited by: Indhu Ram on Mar 12, 2010 2:35 PM
    Edited by: Indhu Ram on Mar 15, 2010 8:04 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:06 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:28 AM

    Ask Tom has very good discussion about this, if UPDATE does not work for PK issue, you can use MERGE
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:760068400346785797

  • Dynamic UPDATE statement with parameters for column names.

    Hello,
    On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
    On the other hand, in this Re: execute immediate with dynamic column name update and many other
    posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.
    dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
    WHERE ST IN
    (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
    '||P_ST||' = CO.ST AND
    CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
    CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
    EXECUTE IMMEDIATE dynSQL ;
    Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.
    The compiling works fine and I use Oracle 11g.
    http://psoug.org/definition/EXECUTE_IMMEDIATE.htm

    OK I extracted from all of your posts so far that I have to use "bind-variables with :"
    From all the other tuorials and forums posts, I assume using the pipe is correct so I added those as well into the script:
    set serveroutput on format wraped;
    DECLARE
    dynSQL VARCHAR2(5000);
    P_ENT_E_G_NAME VARCHAR2 (100) :='test1'; P_ENT_E_G_WE VARCHAR2 (100) :='01.02.2012'; P_ENT_B_G_NAME VARCHAR2 (100) :='01.01.2012';
    P_ST                VARCHAR2 (100) :='32132';
    BEGIN
    dynSQL:= 'UPDATE CO_STAT2 CO SET CO.'||:P_ENT_B_G_NAME||' = '||:P_ENT_E_G_WE||'
                  WHERE ST IN (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
                  '||:P_ST||'                           = CO.ST                  AND
                  CO.'||:P_ENT_E_G_NAME||'     > '||:P_ENT_E_G_WE||' AND
                  CO.'||:P_ENT_B_G_NAME||'    
    < '||:P_ENT_E_G_WE||')';
    --this is somehow missing after the last < '||:P_ENT_E_G_WE||')';
    dbms_output.enable;
    dbms_output.put(dynSQL);
    --EXECUTE IMMEDIATE dynSQL;    
    END;Problem:I think I figured it out, the dates that I parse into the query need additional '

  • Update statement for object table.

    Hi,
    I have created one type as
    Create type test as object(
    ins_by varchar2(30),
    ins_on date,
    upd_by varchar2( 30),
    upd_on date);
    and then created an object table as
    create table imst(
    i_code number(5),
    i_desc varchar2(35),
    i_op test);
    now i am able to insert record in this table as
    insert into imst values(1,'Hawkins cooker',test(user,sysdate,'',''));
    Above works fine.
    But I would also like to update the record with i_op.upd_by,i_op.upd_on with some other values.
    Can any body help me specifying how to write a plain update statement for the same.
    Regards.
    Soumen

    Check it out:
    SQL> Create type myTest as object(
      2  ins_by varchar2(30),
      3  ins_on date,
      4  upd_by varchar2( 30),
      5  upd_on date);
      6  /
    Type created.
    SQL> create table imst(
      2  i_code number(5),
      3  i_desc varchar2(35),
      4  i_op myTest);
    Table created.
    SQL> insert into imst values(1,'Hawkins cooker', mytest(user,sysdate,'',''));
    1 row created.
    SQL> select * from imst;
        I_CODE I_DESC
    I_OP(INS_BY, INS_ON, UPD_BY, UPD_ON)
             1 Hawkins cooker
    MYTEST('APC_LOAD', '12-JUL-04', NULL, NULL)
    SQL> update imst i set i.i_op.upd_by = USER, i.i_op.upd_on = add_months(sysdate, 1);
    1 row updated.
    SQL> select * from imst;
        I_CODE I_DESC
    I_OP(INS_BY, INS_ON, UPD_BY, UPD_ON)
             1 Hawkins cooker
    MYTEST('APC_LOAD', '12-JUL-04', 'APC_LOAD', '12-AUG-04')
    SQL> Smoke me a kipper I'll be back before breakfast.
    Cheers, APC

  • Writing an update statement in oracle forms 9i

    Hi ,
    I have a problem situation in which
    I am fetching values from a cursor and a recod group into two data block items text box and combo box respectively .
    Both the data is fetched from different tables .
    Now based on the selection from combo box I have to update the selected value in another table by writing an update statemet .
    I have created a button and on the trigger event of when button pressed I wrote a simple update statement but it's not working that way .
    Kindly help me how to write manual update statements in oracle forms 9i
    I can't used the update buil in of forms as I want to update in a table which is not mentioned in the property pallete of data block
    please help

    I just wrote a procedure
    PROCEDURE update_current IS
    BEGIN
    update table abc set xculumn= :block_name.item_name2 where ycolumn = :block_name.item_name1 ;
    commit;
    and I called the procedure from a when button pressed trigger
    it gave an error invalid identifier abc ( which is table name)
    pls help
    I am trying to do it with form_ddl(update_query)
    but here I am facing another problem
    I have update_query = 'update table abc set xculumn= ' || :block_name.item_name2 || 'where ycolumn = '||:block_name.item_name1
    now since xculumn and y column are varchar type so I suppose while preparing the query I have to concatenate single quotes ( ' ) at the start and end
    but i am facing problems in doing so
    please tell me an alternative way or how to concatenate single quotes in the above update_query variable

  • 'Missing select' error for update statement using WITH clause

    Hi,
    I am getting the below error for update statement using WITH clause
    SQL Error: ORA-00928: missing SELECT keyword
      UPDATE A
      set A.col1 = 'val1'
         where
      A.col2 IN (
      WITH D AS
      SELECT col2 FROM
      (SELECT col2, MIN(datecol) col3 FROM DS
      WHERE <conditions>
        GROUP BY PATIENT) D2
      WHERE
      <conditions on A.col4 and D2.col3>

    Hi,
    The format of a query using WITH is:
    WITH  d  AS
        SELECT  ...  -- sub_query
    SELECT  ...   -- main query
    You don't have a main query.  The keyword FROM has to come immediately after the right ')' that ends the last WITH clause sub-query.
    That explains the problem based on what you posted.  I can't tell if the real problem is in the conditions that you didn't post.
    I hope this answers your question.
    If not, post a complete test script that people can run to re-create the problem and test their ideas.  Include a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • UPDATE Statement executing for whole table even when WHERE Clause is presen

    Hi Friends,
    I have a problem in a stored procedure where i have written an update statement with a where clause. At a time only one row should get updated depending upon unique identifier in where clause.
    But whats happening is that Update statement is getting executed for all the rows in the table neglecting the WHERE clause. I am not getting the clue as to why this is happening. Here is the stored Procedure And the update statement is in BOLD :-
    CREATE OR REPLACE PROCEDURE MDMADM.proc_MDM_InsertCntryDetails
    CntryMasterCode IN VARCHAR2,
    CntryName IN VARCHAR2,
    MDMUser IN VARCHAR2,
    Exist IN INTEGER,
    status IN VARCHAR2,
    Inserted_By IN VARCHAR2 DEFAULT NULL,
    Modified_By IN VARCHAR2 DEFAULT NULL,
    Mdm_Code IN NUMBER DEFAULT 0,
    Action IN VARCHAR2 DEFAULT 'add',
    XGenAttNames IN VARCHAR2 DEFAULT NULL,
    XGenAttValues IN VARCHAR2 DEFAULT NULL,
    MirusAttNames IN VARCHAR2 DEFAULT NULL,
    MirusAttValues IN VARCHAR2 DEFAULT NULL,
    GenisysAttNames IN VARCHAR2 DEFAULT NULL,
    GenisysAttValues IN VARCHAR2 DEFAULT NULL,
    XGenModify IN VARCHAR2 DEFAULT NULL,
    MirusModify IN VARCHAR2 DEFAULT NULL,
    GenisysModify IN VARCHAR2 DEFAULT NULL
    IS
    strSQLXGen VARCHAR(1000);
    strSQLMirus VARCHAR(1000);
    strSQLGenisys VARCHAR(1000);
    nMaxMDMCode INTEGER;
    ifExist INTEGER;
    NAME: proc_MDM_InsertCntryDetails
    PURPOSE:
    REVISIONS:
    Ver Date Author Description
    1.0 7/3/2009 1. Created this procedure.
    NOTES:
    Automatically available Auto Replace Keywords:
    Object Name: proc_MDM_InsertCntryDetails
    Sysdate: 7/3/2009
    Date and Time: 7/3/2009, 7:11:20 PM, and 7/3/2009 7:11:20 PM
    Username: (set in TOAD Options, Procedure Editor)
    Table Name: (set in the "New PL/SQL Object" dialog)
    BEGIN
    SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MASTER;
    IF ifExist = 0 THEN
    SELECT 1 INTO nMaxMDMCode FROM DUAL;
    ELSE
    SELECT MAX(MDM_CODE)+1 INTO nMaxMDMCode FROM MDM_COUNTRY_MASTER;
    END IF;
    IF Action='add' THEN
    INSERT INTO MDM_COUNTRY_MASTER(MDM_CODE,MDM_MASTER_CODE,MDM_DESCRIPTION,MDM_USER,MDM_EXIST,MDM_STATUS,MDM_ACTION,DAT_INSERT_DATE,DAT_INSERTED_BY)
         VALUES(nMaxMDMCode,CntryMasterCode,CntryName,MDMUser,Exist,status,Action,SYSDATE,Inserted_By);
    strSQLXGen := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || XGenAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || nMaxMDMCode || ',' || '''' || 'XGen' || '''' || ',1,' || XGenAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLXGen;
    strSQLMirus := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || MirusAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || nMaxMDMCode || ',' || '''' || 'Mirus' || '''' || ',2,' || MirusAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLMirus;
    strSQLGenisys := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || GenisysAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || nMaxMDMCode || ',' || '''' || 'Genisys' || '''' || ',3,' || GenisysAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLGenisys;
    ELSE
    UPDATE MDM_COUNTRY_MASTER
    SET MDM_DESCRIPTION=CntryName,DAT_MODIFIED_BY=Modified_By,DAT_MODIFY_DATE=SYSDATE,
    MDM_USER=MDMUser,MDM_ACTION=Action,MDM_STATUS=status,MDM_EXIST=Exist WHERE MDM_CODE=Mdm_Code;
    SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=1 AND MDM_CODE=Mdm_Code ;
    IF ifExist = 0 THEN
    strSQLXGen := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || XGenAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || Mdm_Code || ',' || '''' || 'XGen' || '''' || ',1,' || XGenAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLXGen ;
    ELSE
    strSQLXGen := 'UPDATE MDM_COUNTRY_MAPPING SET ' || XGenModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=1' ;
    EXECUTE IMMEDIATE strSQLXGen ;
    END IF;
    SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=2 AND MDM_CODE=Mdm_Code ;
    IF ifExist = 0 THEN
    strSQLMirus := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || MirusAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || Mdm_Code || ',' || '''' || 'Mirus' || '''' || ',2,' || MirusAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLMirus ;
    ELSE
    strSQLMirus := 'UPDATE MDM_COUNTRY_MAPPING SET ' || MirusModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=2' ;
    EXECUTE IMMEDIATE strSQLMirus ;
    END IF;
    SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=3 AND MDM_CODE=Mdm_Code;
    IF ifExist = 0 THEN
    strSQLGenisys := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || GenisysAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
    'VALUES(' || Mdm_Code || ',' || '''' || 'Genisys' || '''' || ',3,' || GenisysAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
    EXECUTE IMMEDIATE strSQLGenisys ;
    ELSE
    strSQLGenisys := 'UPDATE MDM_COUNTRY_MAPPING SET ' || GenisysModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=3' ;
    EXECUTE IMMEDIATE strSQLGenisys ;
    END IF;
    END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END proc_MDM_InsertCntryDetails;
    Thanks

    It might be helpful to search this forum and google for PL/SQL (variables, stored procs, etc) naming standards. There are quite a few out there and you can choose one that works for you.
    As an example, a lot of standards adopt naming prefixes, ie v_ for VARCHAR variable, n_ for NUMBER variable, pv_ for paramater VARCHAR, etc.

  • Update statement for multiple records

    i have table a and table b
    common col in both the tables is emp_id
    in table b i have district_id
    which i want to update in table a.... column district_id for all the employees
    how to write update statement for this
    Edited by: user10873676 on Oct 17, 2011 8:00 AM

    Based on your current description, we have something like this...
    SQL> create table a (emp_id number)
      2  /
    Table created.
    SQL>
    SQL> create table b (emp_id number, district_id number)
      2  /
    Table created.
    SQL>
    SQL> insert into a (emp_id)
      2  select rownum from dual connect by rownum <= 10
      3  /
    10 rows created.
    SQL>
    SQL> insert into b (emp_id, district_id)
      2  select rownum, 10-rownum from dual connect by rownum <= 10
      3  /
    10 rows created.
    SQL>
    SQL> update b
      2  set district_id = 1
      3  /
    10 rows updated.
    SQL>
    SQL> select * from a;
        EMP_ID
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.
    SQL> select * from b;
        EMP_ID DISTRICT_ID
             1           1
             2           1
             3           1
             4           1
             5           1
             6           1
             7           1
             8           1
             9           1
            10           1
    10 rows selected.Which I'm sure is NOT what you want as the update on table b has nothing to do with table a, and we have no idea what the district_id should be updated with.

  • Update statement problem for jdbc adapter

    Hi all
    In the jdbc sender adapter, I configured as follows:
    Query statement
    select * from pickdiff where tid is null
    Update statement
    delete from pickdiff where tid is null
    I got following error message:
    Database-level error reported by JDBC driver while executing statement 'delete from pickdiff where tid is null'. The JDBC driver returned the following error message: 'java.sql.SQLException: [SQLServer 2000 Driver for JDBC][SQLServer]Die Unterabfrage gab mehr als einen Wert zurück. Das ist ungültig, wenn die Unterabfrage auf =, !=, <, <= , >, >= folgt oder als Ausdruck verwendet wird.'. For details, contact your database server vendor.
    If I change the Update statement to
    update pickdiff set tid = 'sapxi' where tid is null
    Then everything is ok.
    Doese any one have some idea about this problem?
    Regards
    Hui

    Hi,
    The below statements are from SAP help...
    http://help.sap.com/saphelp_nw04/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/frameset.htm
    The UPDATE statement must alter exactly those data records that have been selected by the SELECT statement. You can ensure this is the case by using an identical WHERE clause. (See Processing Parameters, SQL Statement for Query, and SQL Statement for Update below).
    &#9679;      Processing can only be performed correctly when the isolation level for transaction is set to repeatable_read or serializable.
    SQL statement for query: SELECT * FROM table WHERE processed = 0;
    SQL statement for update: UPDATE table SET processed = 1 WHERE processed = 0;
    processed is the indicator in the database.
    please see if setting the isolation level would help....Also are you getting this error always or is it intermitent ?
    Thanks,
    Renjith

  • Auto update stats disabled for a user Database in Sql server

    While trying to improve the performance of few queries, we found via execution plan that there were lot of Index/Clustered index seeks. Therefore:
    First thing we did, was to check our Re-indexing and update stats job which runs weekly for this user DB ( Around 400 GB in size and is used 24*5). The job was running fine.
    Later when we ran SP_Blitz, we came to know that auto-update-stats is disabled for this user DB. We expected this to be a possible cause and change it from false to TRUE(Auto update stats)
    Also, per SP_blitz there are user-created statistics for this DB. When ran the query to check how many, we saw around 7K user stats out there.
    So my question would be 1) setting the Auto update stats to TRUE would require a reboot or once changed i need to track the performance and 2) Should we consider dropping those user created stats or manually look into them one by one.
    How should we proceed on this, please suggest, thanks!

    There may be good reasons for having auto-stats off, but those cases are not very common. It makes a little more sense to turn if off on table level. An example of the latter is a relatively small table, say < 100000 rows where not many new rows are added,
    but the existing rows are being updated frequently. This will trigger autostats, but probably without much benefit.
    But if you have a system which is very busy during peak times, you may not want autostats take resources during those hours. But if you turn off autostats, you will need to make sure that stats are updated in some other fashion.
    Here is a query that you can use review when your statistics last were updated:
    SELECT o.name, s.name, stats_date(o.object_id, s.stats_id) AS lastupdated
    FROM   sys.objects o
    JOIN   sys.stats s ON s.object_id = o.object_id
    --WHERE  s.user_created = 1
    ORDER BY lastupdated
    7000 user-created statistics sounds a little excessive, but I guess they were added to compensate for the autostats that SQL Server were not permitted to create. I would not recommend dropping these statistics, as SQL Server would spend cycles on recreating
    them.
    You should not have to restart SQL Server for the Auto-update stats setting to take effect; it takes effect immediately.
    Erland Sommarskog, SQL Server MVP, [email protected]

Maybe you are looking for

  • Adobe 9 is terrible!  DO NOT UPGRADE!!!

    I was a happy user of Adobe 6, but was forced to upgrade to Adobe 9 due to issues with Vista and the former Adobe. Talk about a terrible terrible program. Here are some of the fun problems that are bound to happen: The inability to change text color

  • After years of never a problem with lightroom started with lightroom 5 yesterday and today all of a

    After years of never a problem with lightroom, yesterday i started wiith Lightroom 5 and today all of a sudden in development mode everything just stopped working. No matter what I do none of the sliders have any effect on the picture whatsoever. Ple

  • Flicker on DVD

    Everything is great until I make the DVD. I still get a slight flicker on movement. My settings on compressors inspector are as follows. File Format Mpeg-2 Ext M2v Video Format NTSC Rate 29.97 Aspect 16:9 (material is shot HDV 1080I60 16X9) Field Dom

  • HT5188 iTunes/ VPP /Apple Configurator

    I previously used iTunes to redeem and install apps purchased through the VPP for Education and would like to start using Apple Configurator with these iPads. How can I get Apple Configurator to accept the redemption codes already used by iTunes?

  • Regarding B1 event

    The infotypes  2000 to 2999 store time related data. But i found B1 cluster which is time events . what information is stored in B1 event in cluster table PCL1. thanks,