SQL Update statement not executing in Filter

Hi,
I am trying to update Documents table using the query resource in a custom component. The document table is requred to upate for vault file(1 row) and for weblayout file(1 row). The java code is executing in PostConversionFilter, the sql is defined in query resource.
Query Resource is defined in componet like..
MyQResource=UPDATE Documents SET dOriginalName = ?, dFormat = ?, dFileSize = ?, dExtension = ? WHERE (dID = ? AND dIsPrimary = ? AND dIsWebFormat = ?)
This SQL executes for vault file means dIsPrimary = 1 AND dIsWebFormat = 0 however the same is not executing when for weblayout file dIsPrimary = 0 AND dIsWebFormat = 1
I putting here final satement formed, got by systematabase trace as following
For vault file:
UPDATE Documents SET dOriginalName = 'XYZ009174~1.spdf', dFormat = 'application/vnd.sealedmedia.softseal.pdf', dFileSize = 0, dExtension = 'spdf' WHERE (dID = '9559' AND dIsPrimary = 1 AND dIsWebFormat = 0)
For weblayuot file:
UPDATE Documents SET dOriginalName = 'XYZ009174~1.spdf', dFormat = 'application/vnd.sealedmedia.softseal.pdf', dFileSize = 0, dExtension = 'spdf' WHERE (dID = '9559' AND dIsPrimary = 0 AND dIsWebFormat = 1)
There is no error in logs, traces. I am using UCM 11g. in Documents table 1 row is updated for vault file only I am expecting for weblyaout updation also.
Please help what could be the possible cause?
Thanks,
Manoj
Edited by: Manoj Kumar on 15-May-2012 13:03

If I got your question, you state that you see a SQL statement in systemdatabase tracing, but it is not executed in the database? Btw. you should see further details (such as how much time the query took) if you turn on full verbose tracing.
I'd just go and try to execute the same queries directly in the database (e.g. in sqlplus console). My guess is that there will be no record according to the second WHERE clause...

Similar Messages

  • SQL UPDATE Statement Explaination (urgent please...)

    Hi,
    Could anyone explain for me what this statement will do:
    update KPIR KR
    set ( CA ) = (
    select sum(sl.RRC_CONN_STP_ATT) CA
    from PV_WCEL_SERVICE_LEVEL sl, UTP_MO um
    where sl.GLOBAL_ID = um.CO_GID
    group by sl.STARTTIME, um.OBJECT_INSTANCE
    I could not understand how the mapping between the two tables will be ("um" clause is not used in the select statement and it is used only in the "where" and "group by" arguments) What does this mean?.
    The actual problem is that when I execute the above SQL statement, it was take around just 3 minutes to be implemented. But after we upgrade from Oracle 8 to Oracle 9, this statement is taking around 3 hours to be implemented.
    Anyone have any idea what is the problem?

    Below is the plan:
    KPIR table:
    RNC_ID (str), PST ('YYYYMMDD_HH24'), CA (Numner)
    1, 20061105_13, 0
    1, 20061105_14, 0
    1, 20061105_15, 0
    2, 20061105_13, 0
    2, 20061105_14, 0
    2, 20061105_15, 0
    3, 20061105_13, 0
    3, 20061105_14, 0
    3, 20061105_15, 0
    4, 20061105_13, 0
    4, 20061105_14, 0
    4, 20061105_15, 0
    PV_WCEL_SERVICE_LEVEL table:
    GLOBAL_ID (str), STARTTIME ('YYYYMMDD_HH24'), RRC_CONN_STP_ATT (Number)
    A1, 20061101_00, 9
    A1, 20061101_01, 4
    A1, 20061101_23, 3
    A1, 20061130_23, 4
    A2, 20061101_00, 3
    A2, 20061101_01, 4
    A2, 20061101_23, 1
    A2, 20061130_23, 5
    UTP_MO table;
    RNC_ID (str), GLOBAL_ID (str), OBJECT_INSTANCE (str)
    1, A1, <A1_NAME>
    1, A2, <A2_NAME>
    1, A9, <A9_NAME>
    2, B1, <B1_NAME>
    2, B2, <B2_NAME>
    2, B9, <B9_NAME>
    3, C1, <C1_NAME>
    3, C2, <C2_NAME>
    3, C9, <C9_NAME>
    4, D1, <D1_NAME>
    4, D2, <D2_NAME>
    4, D9, <D9_NAME>
    Now, I want to update the value of CA in table KPIR:
    For instance, for RNC_ID='1' and at PST='20061105_13', the CA should equals to the sum of value RRC_CONN_STP_ATT for all GLOBAL_IDs under RNC_ID='1' and at STARTTIME '20061105_13'.
    So, is this SQL UPDATE statement will do it?
    update KPIR kr
    set ( CA ) = (
    select sum(sl.RRC_CONN_STP_ATT) CA
    from PV_WCEL_SERVICE_LEVEL sl, UTP_MO um
    where sl.GLOBAL_ID = um.GLOBAL_ID and kr.RNC_ID = um.RNC_ID and kr.PST = sl.STARTTIME
    group by sl.STARTTIME, um.OBJECT_INSTANCE
    And if so, why it is taking around 3 hours to be implemented? This issue is happened after upgrading from Oracle 8 to 9.
    Really appreciate your help and thanks in advance.

  • In Oracle this SQL update tatement not working but in MS SQL it works

    Dear Friends,
    The following sql update statement work fine in MS sql server but not working in Oracle. Can you kindly suggest, What is wrong with this statement ? and is their any other way of achieving the same in Oracle.
    UPDATE INPUTSTREET SET EDIT_FLAGS=S.EDIT_FLAGS From INPUTSTREET G, INPUT_SEGBASE S Where G.GEOKEY=S.GEOKEY
    This statement give error in Oralce saying - Statement not ended properly
    Cheers,
    Vinay

    You would normally write
    UPDATE inputStreet g
       SET edit_flags = (SELECT s.edit_flags
                           FROM input_segbase s
                          WHERE s.geokey = g.geokey)If you don't want to update all the rows in inputStreet, you can add a WHERE EXISTS clause.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Updates using single SQL Update statement.

    Hi Guys,
    I had an interview... and was not able to give an answer of one of the question.
    Given the emp table... need to update the salary with following requirement using one SQL statement...
    1. Update salary+1000 for those employees who have salary between 500 and 1000
    2. Update salary+500 for those employees who have salary between 1001 and 1500
    Both above requirement should be done by using only one SQL update statement... can some one tell me how to do it?

    update emp
      set salary   = case when salary between 500 and 1000
                                then salary + 1000
                                when salary between 1001 and 1500
                                then salary + 500
                          end;Regards
    Arun

  • Regex help for SQL update statement

    Hello,
    need help from IPS regex guru - trying to build the signature to detect SQL update statement in HTTP requests.
    1) Am I correct with regex below specified as Request-Regex?
    [Uu][Pp][Dd][Aa][Tt][Ee]([%]20|[+])[\x20-\x7e]+[Ss][Ee][Tt]([%]20|[+])[\x20-\x7e]+=
    2) How do I make sure that it detects 'Update' in URI and Arguments only and not in the body on entire webserver response (currently looks like the case)?

    1) It looks correct to me
    2) Typically, the "service HTTP" engine is used to inspect requests and the "TCP string" engine is used to inspect HTTP server responses. If you only want to inspect requests, use the service HTTP engine.

  • Update statement not working PL/SQL block

    Hi friends,
    My code is written the following way:
    declare
    var1 number;
    var2....
    Cursor c1 <select something>;
    Cursor c2 <select something>
    Begin
    Insert into table1 <different values>;
    Commit;
    /* first update statement */
    Update table1 set table1.col3 = (select col3 from table2 where table2.col1 = table1.col1 and table2.col2 = table1.col2);
    commit ;
    /* 2nd update statement */
    update table1 set table1.col4 = (select col4 from table3 where table3.col1 = table1.col1 and table3.col2 = table1.col2);
    commit ;
    for r2 in c2 loop
    update table1
    end loop;
    end;
    This code works till 1st update statement. But after that, even if I let my code run overnight, nothing happens. There are appropriate indexes on tables where join is done. All tables are in one schema.
    What could be the reason?

    darshilm wrote:
    /* first update statement */
    Update table1 set table1.col3 = (select col3 from table2 where table2.col1 = table1.col1 and table2.col2 = table1.col2);This is an unconstrained updated - meaning that it instructs the database that every single row in TABLE1 needs to be updated.
    For every single row, the "update" SQL has to be executed and a SELECT performed on TABLE2.
    Let's say there are a 100,000 rows in TABLE1. This means that the SELECT to find the updated value has to be executed a 100,000 times.
    Let's say that there are a 200,000 rows in TABLE2. This means that each time that SELECT runs, it potentially hits 200,000 rows. Does it do it via a full table scan? Index range scan?
    At what cost? Hitting the very same data set again and again and again, 100,000 times in a row.
    And that is only the start of your code... and you wonder why it does not seem to finish?
    Data processing in a RDBMS is about how to do the minimal amount of I/O to achieve the desired result. For example, instead of hitting TABLE2 100,000 times, you can write code to hit it once by joining it with TABLE1 and creating an "updateable view" of TABLE1 that can be updated with the join values of TABLE2.
    You also seem to use PL/SQL cursors to perform row-row (and slow-by-slow) processing. This typically pulls data from the SQL engine into the PL engine and then push that very same data from the PL engine to the SQL engine.. It is a lot faster and more efficient (and scalable) to rather stay inside the SQL engine and do data set processing there (as oppose to row-by-row on the client side).
    Performance in a RDBMS is primarily determined by the designer and the developer... are functions of how well designed the data model is, and how well designed and written the code is.

  • Problem in Update statement using Execute Immediate

    Hi All,
    I am facing problem in update statement.
    I am creating dynamic sql and use "execute immediate" statement to execute a update statement.
    But it is not updating any thing there in the table.
    I have created a query like :
    update_query='Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
    Execute immediate update_query using V_Id;
    commit;
    But it is not updating the table.
    I have a question , is execute immediate only does insert and delete?
    Thanks
    Ashok

    SQL> select * from t;
                     TID P
                     101 N
    SQL> declare
      2     V_Id          number := 101;
      3     Table_Name    varchar2(30) := 'T';
      4     update_query  varchar2(1000);
      5  begin
      6     update_query := 'Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
      7     Execute immediate update_query using V_Id;
      8     commit;
      9  end;
    10  /
    PL/SQL procedure successfully completed.
    SQL> select * from t;
                     TID P
                     101 Y                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • SQL Update statement taking too long..

    Hi All,
    I have a simple update statement that goes through a table of 95000 rows that is taking too long to update; here are the details:
    Oracle Version: 11.2.0.1 64bit
    OS: Windows 2008 64bit
    desc temp_person;
    Name                                                                                Null?    Type
    PERSON_ID                                                                           NOT NULL NUMBER(10)
    DISTRICT_ID                                                                     NOT NULL NUMBER(10)
    FIRST_NAME                                                                                   VARCHAR2(60)
    MIDDLE_NAME                                                                                  VARCHAR2(60)
    LAST_NAME                                                                                    VARCHAR2(60)
    BIRTH_DATE                                                                                   DATE
    SIN                                                                                          VARCHAR2(11)
    PARTY_ID                                                                                     NUMBER(10)
    ACTIVE_STATUS                                                                       NOT NULL VARCHAR2(1)
    TAXABLE_FLAG                                                                                 VARCHAR2(1)
    CPP_EXEMPT                                                                                   VARCHAR2(1)
    EVENT_ID                                                                            NOT NULL NUMBER(10)
    USER_INFO_ID                                                                                 NUMBER(10)
    TIMESTAMP                                                                           NOT NULL DATE
    CREATE INDEX tmp_rs_PERSON_ED ON temp_person (PERSON_ID,DISTRICT_ID) TABLESPACE D_INDEX;
    Index created.
    ANALYZE INDEX tmp_PERSON_ED COMPUTE STATISTICS;
    Index analyzed.
    explain plan for update temp_person
      2  set first_name = (select trim(f_name)
      3                    from ext_names_csv
      4                               where temp_person.PERSON_ID=ext_names_csv.p_id
      5                               and   temp_person.DISTRICT_ID=ext_names_csv.ed_id);
    Explained.
    @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 3786226716
    | Id  | Operation                   | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT            |                | 82095 |  4649K|  2052K  (4)| 06:50:31 |
    |   1 |  UPDATE                     | TEMP_PERSON    |       |       |            |          |
    |   2 |   TABLE ACCESS FULL         | TEMP_PERSON    | 82095 |  4649K|   191   (1)| 00:00:03 |
    |*  3 |   EXTERNAL TABLE ACCESS FULL| EXT_NAMES_CSV  |     1 |   178 |    24   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter("EXT_NAMES_CSV"."P_ID"=:B1 AND "EXT_NAMES_CSV"."ED_ID"=:B2)
    Note
       - dynamic sampling used for this statement (level=2)
    19 rows selected.By the looks of it the update is going to take 6 hrs!!!
    ext_names_csv is an external table that have the same number of rows as the PERSON table.
    ROHO@rohof> desc ext_names_csv
    Name                                                                                Null?    Type
    P_ID                                                                                         NUMBER
    ED_ID                                                                                        NUMBER
    F_NAME                                                                                       VARCHAR2(300)
    L_NAME                                                                                       VARCHAR2(300)Anyone can help diagnose this please.
    Thanks
    Edited by: rsar001 on Feb 11, 2011 9:10 PM

    Thank you all for the great ideas, you have been extremely helpful. Here is what we did and were able to resolve the query.
    We started with Etbin's idea to create a table from the ext table so that we can index and reference easier than an external table, so we did the following:
    SQL> create table ext_person as select P_ID,ED_ID,trim(F_NAME) fst_name,trim(L_NAME) lst_name from EXT_NAMES_CSV;
    Table created.
    SQL> desc ext_person
    Name                                                                                Null?    Type
    P_ID                                                                                         NUMBER
    ED_ID                                                                                        NUMBER
    FST_NAME                                                                                     VARCHAR2(300)
    LST_NAME                                                                                     VARCHAR2(300)
    SQL> select count(*) from ext_person;
      COUNT(*)
         93383
    SQL> CREATE INDEX EXT_PERSON_ED ON ext_person (P_ID,ED_ID) TABLESPACE D_INDEX;
    Index created.
    SQL> exec dbms_stats.gather_index_stats(ownname=>'APPD', indname=>'EXT_PERSON_ED',partname=> NULL , estimate_percent=> 30 );
    PL/SQL procedure successfully completed.We had a look at the plan with the original SQL query that we had:
    SQL> explain plan for update temp_person
      2  set first_name = (select fst_name
      3                    from ext_person
      4                               where temp_person.PERSON_ID=ext_person.p_id
      5                               and   temp_person.DISTRICT_ID=ext_person.ed_id);
    Explained.
    SQL> @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 1236196514
    | Id  | Operation                    | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT             |                | 93383 |  1550K|   186K (50)| 00:37:24 |
    |   1 |  UPDATE                      | TEMP_PERSON    |       |       |            |          |
    |   2 |   TABLE ACCESS FULL          | TEMP_PERSON    | 93383 |  1550K|   191   (1)| 00:00:03 |
    |   3 |   TABLE ACCESS BY INDEX ROWID| EXTT_PERSON    |     9 |  1602 |     1   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN          | EXT_PERSON_ED  |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - access("EXT_PERSON"."P_ID"=:B1 AND "RS_PERSON"."ED_ID"=:B2)
    Note
       - dynamic sampling used for this statement (level=2)
    20 rows selected.As you can see the time has dropped to 37min (from 6 hrs). Then we decided to change the SQL query and use donisback's suggestion (using MERGE); we explained the plan for teh new query and here is the results:
    SQL> explain plan for MERGE INTO temp_person t
      2  USING (SELECT fst_name ,p_id,ed_id
      3  FROM  ext_person) ext
      4  ON (ext.p_id=t.person_id AND ext.ed_id=t.district_id)
      5  WHEN MATCHED THEN
      6  UPDATE set t.first_name=ext.fst_name;
    Explained.
    SQL> @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 2192307910
    | Id  | Operation            | Name         | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | MERGE STATEMENT      |              | 92307 |    14M|       |  1417   (1)| 00:00:17 |
    |   1 |  MERGE               | TEMP_PERSON  |       |       |       |            |          |
    |   2 |   VIEW               |              |       |       |       |            |          |
    |*  3 |    HASH JOIN         |              | 92307 |    20M|  6384K|  1417   (1)| 00:00:17 |
    |   4 |     TABLE ACCESS FULL| TEMP_PERSON  | 93383 |  5289K|       |   192   (2)| 00:00:03 |
    |   5 |     TABLE ACCESS FULL| EXT_PERSON   | 92307 |    15M|       |    85   (2)| 00:00:02 |
    Predicate Information (identified by operation id):
       3 - access("P_ID"="T"."PERSON_ID" AND "ED_ID"="T"."DISTRICT_ID")
    Note
       - dynamic sampling used for this statement (level=2)
    21 rows selected.As you can see, the update now takes 00:00:17 to run (need to say more?) :)
    Thank you all for your ideas that helped us get to the solution.
    Much appreciated.
    Thanks

  • Using named parameters with an sql UPDATE statement

    I am trying to write a simple? application on my Windows 7 PC using HTML, Javascript and Sqlite.  I have created a database with a 3 row table and pre-populated it with data.  I have written an HTML data entry form for modifying the data and am able to open the database and populate the form.  I am having trouble with my UPDATE function.  The current version of the function will saves the entry in the last row of the HTML table into the first two rows of the Sqlite data table -- but I'm so worn out on this that I can't tell if it is accidental or the clue I need to fix it.
    This is the full contents of the function . . .
         updateData = new air.SQLStatement();
         updateData.sqlConnection = conn;
         updateData.text = "UPDATE tablename SET Gsts = "Gsts, Gwid = :Gwid, GTitle = :GTitle WHERE GId = ":GId;
              var x = document.getElementsById("formname");
              for (var i = 1, row, row = x.rows[i]; i++) {
                   updateData.parameters[":GId"] = 1;
                   for (var j = 0, col; col=row.cells[j]; j++) {
                        switch(j) {
                             case 0: updateData.parameters[":GTitle"] = col.firstChild.value; break;
                             case 1: updateData.parameters[":Gsts"] = col.firstChild.value; break;
                             case 2: updateData.parameters[":Gwid"] = col.firstChild.value; break;
    Note: When I inspect the contents of the col.firstChild.value cases, they show the proper data as entered in the form -- it just isn't being updated into the proper rows of the Sqlite table.
    Am I using the named parameters correctly? I couldn't find much information on the proper use of parameters in an UPDATE statement.

    Thank you for the notes.  Yes, the misplaced quotes were typos.  I'm handtyping a truncated version of the function so I don't put too much info in the post. And yes, i = 1 'cuz the first rows of the table are titles.  So the current frustration is that I seem to be assigning all the right data to the right parameters but nothing is saving to the database.
    I declare updateData as a variable at the top of the script file
    Then I start a function for updating the data which establishes the sql connection as shown above.
    The correctly typed.text statement is:
            updateData.text = "UPDATE tablename SET Gsts=:Gsts, Gwid=:Gwid, GTitle=:GTitle WHERE GId=:GId";
    (The data I'm saving is entered in text boxes inside table cells.) And the current version of the loop is:
            myTable = document.getElementById("GaugeSts");
            myRows= myTable.rows;
              for(i=1, i<myRows.length, i++) {
                   updateData.parameters[":GId"]=i;
                   for(j=0; j<myRows(i).cells.length, j++) {
                        switch(y) {
                             case 0: updateData.parameters[":GTitle"]=myrows[i].cells[y].firstChild.value; break;
                             case 1: updateData.parameters[":Gsts"]=myrows[i].cells[y].firstChild.value; break;
                             case 2: updateData.parameters[":Gwid"]=myrows[i].cells[y].firstChild.value; break;
                             updateData.execute;
    The whole thing runs without error and when I include the statements to check what's in myrows[i].cells[y].firstChild.value, I'm seeing that the correct data is being picked up for assignment to the parameters and the update. I haven't been able to double check that the contents of the parameters are actually taking the data 'cuz I don't know how to extract the data from the parameters. ( The only reference  I've found so far has said that it is not possible. I'm still researching that one.) I've also tried moving the position of the updateData execution statement to several different locations in the loop andstill nothing updates. 
    I am using a combination of air.Introspector.Console.log to check the results of code and I'm using Firefox's SQlite manager to handle the database.  The database is currently sitting on the Desktop to facilitate testing and I have successfully updated/changed data in this table through the SQLite Manager so I don't think I'm having permission errors and, see below, I have another function successfully saving data to another table.
    I currently have another function that uses ? for the parametersin the .text of a INSERT/REPLACE statement and that one works fine.  But, only one line of data is being saved so there is no loop involved.  I tried changing the UPDATE statement in this function to the INSERT/REPLACE just to make something save back to the database but I can't make that one work either.I've a (And, I've tried so many things now, I don't even remember what actually saved something --albeit incorrectly --to the database in one of my previous iterations with the for loops.)
    I'm currently poring through Sqlite and Javascript tomes to see if I can find what's missing but if anything else jumps out at you with the corrected code, I'd appreciate some ideas.
    Jeane

  • Update statement not working inside DBMS_PARALLEL_EXECUTE

    CREATE OR REPLACE procedure
    proc_table_mask_par2 (p_tblName in varchar2
    ,p_strmCount in number)
    IS
    | Name: proc_table_mask
    | Version: 1.0
    | Function: The procedure generates the block which will mask the table based on inputrs from
    MSK_INVENTORY_COLS table
    | Modification History:
    | Ver: Date: Who: What:
    | 1.0 2012-11-26 HB Created
    vtbl_Name varchar2(100);
    vtbl_Count number(19,0);
    vStrm_row_count number(19,0);
    vCurs_count number(19,0) := 1;
    vsql varchar2(30000);
    vsql1 varchar2(30000);
    vstragg varchar2(4000);
    v_try number;
    v_status number;
    v_status1 number;
    vtaskName varchar2(100) := 'Mask job for '||p_tblName ;
    pstartnum number(19,0);
    pendnum number(19,0);
    v_prim_key varchar2(100);
    --retries_in  PLS_INTEGER DEFAULT 2;
    --l_attempts    PLS_INTEGER := 1;
    begin
    -- Use function Stragg to get the update statement from MSK_INVENTORY_COLS
    select stragg(MIC.COLUMN_NAME || ' = ' || MIC.FUNCTION_NAME|| '(' ||MIC.COLUMN_NAME||')') into vstragg from MSK_INVENTORY_COLS mic
    WHERE MIC.TABLE_NAME = p_tblName;
    EXECUTE IMMEDIATE 'select count(1) from '||p_tblName into vtbl_Count;
    --DBMS_OUTPUT.PUT_LINE ( 'vtbl_Count : ' ||vtbl_Count);
    vStrm_row_count := round( vtbl_Count/p_strmCount);
    dbms_output.put_line(' vStrm_row_count : ' || vStrm_row_count);
    -- Update statement
    vsql := vsql ||chr(10) || ' UPDATE '|| p_tblName || ' /*+ parallel ( '||p_tblName ||', '||p_strmCount||') */ ' ;
    vsql := vsql ||chr(10) || ' SET '|| vstragg;
    vsql := vsql ||chr(10) || ' , lock_id = -1 ' ;
    vsql := vsql ||chr(10) || 'WHERE ROWID BETWEEN :starting_rowid AND :ending_rowid' ;
    vsql := vsql ||chr(10) || ' and lock_id <> -1 ; ' ;
    dbms_output.put_line (' vsql : ' || vsql);
    DBMS_PARALLEL_EXECUTE.CREATE_TASK (vtaskName);
    DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_ROWID (task_name => vtaskName
    , table_owner => SYS_CONTEXT ('USERENV', 'SESSION_USER') --USER
    , table_name => p_tblName
    , by_row => TRUE
    , chunk_size => vStrm_row_count
    DBMS_PARALLEL_EXECUTE.RUN_TASK (task_name => vtaskName
    , sql_stmt => vsql
    , language_flag => DBMS_SQL.native
    , parallel_level => p_strmCount
    -- Only resume for the following
    -- INVALID_STATE_FOR_REDSUME ORA - 29495
    -- Attempts to resume execution, but the task is not in FINISHED_WITH_ERROR or CRASHED state
    -- Constant value for CRASHED = 8
    -- Constant value for FINISHED_WITH_ERROR = 7
    v_try := 0;
    v_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
    dbms_output.put_line (' v_status : ' || v_status);
    dbms_output.put_line (' v_try : ' || v_try);
    WHILE(v_try < 2 and v_status != DBMS_PARALLEL_EXECUTE.FINISHED and ((v_status = 7) or( v_status = 8) ))
    LOOP
    v_try := v_try + 1;
    DBMS_OUTPUT.PUT_LINE (' Why am I getting into this loop : ' );
    DBMS_PARALLEL_EXECUTE.RESUME_TASK(vtaskName);
    v_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
    END LOOP;
    DBMS_PARALLEL_EXECUTE.DROP_TASK(vtaskName);
    exception
    when
    others then
    raise;
    dbms_output.put_line(sqlerrm);
    end;
    Gurus
    I am executing the procedure above using the following anonymous block.
    DECLARE
    P_TBLNAME VARCHAR2(32767);
    P_STRMCOUNT NUMBER;
    BEGIN
    P_TBLNAME := 'EMPLOYEE_DIM';
    P_STRMCOUNT := 10;
    A516907.PROC_TABLE_MASK_PAR2 ( P_TBLNAME, P_STRMCOUNT );
    COMMIT;
    END;
    I have used dbms_output for getting values for the following variables. When I check the values the update does not seem to be working.
    vStrm_row_count : 60143
    vsql :
    UPDATE EMPLOYEE_DIM /*+ parallel ( EMPLOYEE_DIM, 10) */
    SET
    BUSINESS_TITLE_NM = FN_TITLE_DRM_ENCRYPTNSUM(BUSINESS_TITLE_NM),COST_CENTER_CD =
    FN_COSTCTR_DRM_ENCRYPTNSUM(COST_CENTER_CD),DIRECT_MGR_NM =
    FN_DRM_REG_ADDR_TEXT(DIRECT_MGR_NM),FIRST_NM =
    FN_FNM_DRM_ENCRYPTNSUM(FIRST_NM),LAST_FIRST_FULL_NM =
    FN_DRM_REG_ADDR_TEXT(LAST_FIRST_FULL_NM),LAST_FIRST_MIDDLE_FULL_NM =
    FN_DRM_REG_ADDR_TEXT(LAST_FIRST_MIDDLE_FULL_NM),LAST_NM =
    FN_LNM_DRM_ENCRYPTNSUM(LAST_NM),PHONE_NO =
    FN_PHONE_DRM_ENCRYPTNSUM(PHONE_NO),PRIMARY_EMAIL_ADDRESS_NM =
    FN_EMAIL_DRM_ENCRYPTNSUM(PRIMARY_EMAIL_ADDRESS_NM)
    , lock_id = -1
    WHERE ROWID
    BETWEEN :starting_rowid AND :ending_rowid
    and lock_id <> -1 ;
    v_status : 4
    v_try : 0

    I tried to do the update using chunk sql and ran the procedure again..No updates are made.
    CREATE OR REPLACE procedure
    proc_table_mask_chunk_sql (p_tblName in varchar2
    ,p_strmCount in number)
    IS
    | Name: A516907.proc_table_mask
    | Version: 1.0
    | Function: The procedure generates the block which will mask the table based on inputrs from
    MSK_INVENTORY_COLS table
    | Modification History:
    | Ver: Date: Who: What:
    | 1.0 2012-11-26 HB Created
    vtbl_Name varchar2(100);
    vtbl_Count number(19,0);
    vStrm_row_count number(19,0);
    vCurs_count number(19,0) := 1;
    vsql varchar2(1000);
    vsql_pk varchar2(1000);
    vstragg varchar2(4000);
    vtaskName varchar2(100) := 'Mask Data in table '||p_tblName ;
    pstartnum number(19,0);
    pendnum number(19,0);
    upd_st number(19,0) := 1;
    v_prim_key varchar2(100);
    l_try NUMBER;
    l_status NUMBER;
    begin
    DBMS_PARALLEL_EXECUTE.CREATE_TASK (vtaskName);
    -- Use function Stragg to get the update statement from MSK_INVENTORY_COLS
    select stragg(MIC.COLUMN_NAME || ' = ' || MIC.FUNCTION_NAME|| '(' ||MIC.COLUMN_NAME||')') into vstragg from MSK_INVENTORY_COLS mic
    WHERE MIC.TABLE_NAME = p_tblName;
    select stragg(UCC.COLUMN_NAME) COLUMN_NAME into v_prim_key
    from user_constraints uc , user_cons_Columns ucc
    where UC.CONSTRAINT_TYPE = 'P'
    and UC.CONSTRAINT_NAME = UCC.CONSTRAINT_NAME
    and UCC.TABLE_NAME = p_tblName;
    vsql_pk := 'SELECT distinct ' || v_prim_key || ','|| v_prim_key || ' FROM ' || p_tblName;
    DBMS_OUTPUT.PUT_LINE ( 'vsql_pk : ' ||vsql_pk);
    --EXECUTE IMMEDIATE ' select stragg(COLUMN_NAME ||''=''||FUNCTION_NAME||''(''||COLUMN_NAME||'')'') from MSK_INVENTORY_COLS WHERE TABLE_NAME = ' ||p_tblName  INTO vstragg ;
    --EXECUTE IMMEDIATE 'select count(1)   from vtbl_Name' into vtbl_Count;
    EXECUTE IMMEDIATE 'select count(1) from '||p_tblName into vtbl_Count;
    --DBMS_OUTPUT.PUT_LINE ( 'vtbl_Count : ' ||vtbl_Count);
    vStrm_row_count := round( vtbl_Count/p_strmCount);
    DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_SQL(vtaskName, vsql_pk, false);
    --DBMS_OUTPUT.PUT_LINE ( 'vStrm_row_count : ' ||vStrm_row_count);
    --EXECUTE IMMEDIATE 'SELECT MIN( '||v_prim_key||') from ' ||p_tblName into pstartnum;
    ----dbms_output.put_line (' pstartnum : ' || pstartnum);
    --pendnum :=  vStrm_row_count;
    ----dbms_output.put_line (' pendnum : ' || pendnum);
    -- Update statement
    vsql := vsql ||chr(10) || ' UPDATE '|| p_tblName || ' /*+ parallel ( '||p_tblName ||', '||p_strmCount||') */ ' ;
    vsql := vsql ||chr(10) || ' SET '|| vstragg;
    vsql := vsql ||chr(10) || ' , lock_id = -1 WHERE ' ;
    vsql := vsql ||chr(10) || v_prim_key|| ' BETWEEN :start_id and :end_id ';
    vsql := vsql ||chr(10) || ' and lock_id <> -1 ; ' ;
    --DBMS_PARALLEL_EXECUTE.CREATE_TASK (vtaskName||'_'||upd_st);
    DBMS_PARALLEL_EXECUTE.RUN_TASK ( vtaskName
    , vsql
    , DBMS_SQL.native
    , parallel_level => p_strmCount
    L_try := 0;
    L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
    WHILE(l_try < 2 and L_status != DBMS_PARALLEL_EXECUTE.FINISHED and ((L_status = 7) or( L_status = 8) ))
    Loop
    L_try := l_try + 1;
    DBMS_PARALLEL_EXECUTE.RESUME_TASK(vtaskName);
    L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(vtaskName);
    END LOOP;
    end;
    Block run :
    DECLARE
    P_TBLNAME VARCHAR2(32767);
    P_STRMCOUNT NUMBER;
    BEGIN
    P_TBLNAME := 'EMPLOYEE_DIM';
    P_STRMCOUNT := 10;
    A516907.PROC_TABLE_MASK_CHUNK_SQL ( P_TBLNAME, P_STRMCOUNT );
    COMMIT;
    END;
    /

  • Use of ROWID in SQL Update Statement

    Hi All,
    I have an update statement which uses the rowid column to perform the selection on the target table. Given that a rowid represents the physical location of a row on disk we know that this reference can change when various activities are performed on the database/table/row etc...
    Here is an example of the statement I am issuing:
    UPDATE tabA outertab SET col1 = 'Value'
    WHERE EXISTS (SELECT 1 FROM tabA innertab WHERE outertab.ROWID = outertab.ROWID AND ...)
    Obviously the inner query is more complicated and uses other tables etc... but for the purposes of the example we dont need to include the detail.
    My question is: When using rowid in a single SQL statement as a reference from a subquery to the outer statement is there a risk that external activities can change the rowid and those changes be reflected within the database session that my query is executing thus causing an inconsistency between the inner and outer SQL clause?
    In response to the question which will follow this post: "Why don't you just use a PK", We would like to avoid maintaining a PK on the table as we are talking about very large volumes of data and we dont want to have to issue a call to a sequence if we can avoid it when we are inserting the data. If however there is a risk that this Update statement could fail or update the wrong rows then we may have to use a PK.
    I know there is a lot of threads about this but I havnt been able to find one that someone has answered with any kind of confidence or clarity, any help would be much appreciated.
    Thanks
    Keith
    Edited by: The Turtle on Mar 5, 2009 5:24 AM

    When using rowid in a single SQL statement as a reference from a subquery to the outer statement is there a risk that external activities can change the rowid and those changes be reflected within the database session that my query is executing thus causing an inconsistency between the inner and outer SQL clause?No, it's safe to use rowid in this type of query. Docs
    A row's assigned rowid remains unchanged unless the row is exported and imported using the Import and Export utilities. When you delete a row from a table and then commit the encompassing transaction, the deleted row's associated rowid can be assigned to a row inserted in a subsequent transaction.

  • How to convert the following FORALL Update to direct SQL UPDATE statement

    I have a FORALL loop to update a table. It is taking too long. I want to rewrite the code to a direct UPDATE sql. Also, any other tips or hints which can help run this proc faster?
    CURSOR cur_bst_tm IS
    SELECT listagg(tm, ' ') WITHIN GROUP(ORDER BY con_addr_id) best_time,
           con_addr_id
       FROM   (select Trim(Upper(con_addr_id)) con_addr_id,
                      ||decode(Initcap(start_day),
                                      'Monday', 'm',
                                    'Tuesday', 'tu',
                                    'Wednesday', 'w',
                                    'Thursday', 'th',
                                    'Friday', 'f',
                                     Initcap(start_day))
                      ||'='
                      ||trunc(( ( TO_DATE(start_tm,'HH12:MI:SS PM') - trunc(TO_DATE(start_tm,'HH12:MI:SS PM')) ) * 24 * 60 ))
                      ||','
                      ||trunc(( ( TO_DATE(end_tm,'HH12:MI:SS PM') - trunc(TO_DATE(end_tm,'HH12:MI:SS PM')) ) * 24 * 60 )) tm
               FROM   (SELECT DISTINCT * FROM ODS_IDL_EDGE_OFFC_BST_TM)
                 WHERE con_addr_id is not null)
      GROUP  BY con_addr_id
      ORDER BY con_addr_id;
    TYPE ARRAY IS TABLE OF cur_bst_tm%ROWTYPE;
    l_data ARRAY;
    BEGIN
    OPEN cur_bst_tm;
         LOOP
        FETCH cur_bst_tm BULK COLLECT INTO l_data LIMIT 1000;
        FORALL i IN 1..l_data.COUNT
          UPDATE ODS_CONTACTS_ADDR tgt
          SET best_times = l_data(i).best_time,
          ODW_UPD_BY = 'IDL - MASS MARKET',
           ODW_UPD_DT = SYSDATE,
          ODW_UPD_BATCH_ID = '0'
          WHERE Upper(edge_id) = l_data(i).con_addr_id
           AND EXISTS (SELECT 1 FROM ods_idl_edge_cont_xref src
                       WHERE tgt.contacts_odw_id = src.contacts_odw_id
                          AND src.pc_flg='Y')  
        EXIT WHEN cur_bst_tm%NOTFOUND;
        END LOOP;
      CLOSE cur_bst_tm;Record count:-
    select count(*) from
    ODS_IDL_EDGE_OFFC_BST_TM;
    140,000
    SELECT count(*)
    FROM ods_idl_edge_cont_xref src
    WHERE src.pc_flg='Y';
    118,000
    SELECT count(*)
    FROM ODS_CONTACTS_ADDR;
    671,925
    Database version 11g.
    Execution Plan for the update:
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    UPDATE STATEMENT Optimizer Mode=ALL_ROWS          6 K          8120                     
    UPDATE     ODW_OWN2.ODS_CONTACTS_ADDR                                   
    HASH JOIN SEMI          6 K     256 K     8120                     
    TABLE ACCESS FULL     ODW_OWN2.ODS_CONTACTS_ADDR     6 K     203 K     7181                     
    TABLE ACCESS FULL     ODW_OWN2.ODS_IDL_EDGE_CONT_XREF     118 K     922 K     938
    Edited by: user10566312 on May 14, 2012 1:07 AM

    The code tag should be in lower case like this {noformat}{noformat}. Otherwise your code format will be lost.
    Here is a update statementupdate ods_contacts_addr tgt
    set (
              best_times, odw_upd_by, odw_upd_dt, odw_upd_batch_id
         ) =
              select best_time, odw_upd_by, odw_upd_dt, odw_upd_batch_id
              from (
                   select listagg(tm, ' ') within group(order by con_addr_id) best_time,
                        'IDL - MASS MARKET' odw_upd_by,
                        sysdate odw_upd_dt,
                        '0' odw_upd_batch_id,
                        con_addr_id
                   from (
                             select Trim(Upper(con_addr_id)) con_addr_id,
                                  ||decode(Initcap(start_day), 'Monday', 'm', 'Tuesday', 'tu', 'Wednesday', 'w', 'Thursday', 'th', 'Friday', 'f', Initcap(start_day))
                                  ||'='
                                  ||trunc(((TO_DATE(start_tm,'HH12:MI:SS PM')-trunc(TO_DATE(start_tm,'HH12:MI:SS PM')))*24*60 ))
                                  ||','
                                  ||trunc(((TO_DATE(end_tm,'HH12:MI:SS PM')-trunc(TO_DATE(end_tm,'HH12:MI:SS PM')))*24*60)) tm
                             FROM (
                                  select distinct * from ods_idl_edge_offc_bst_tm
                             WHERE con_addr_id is not null
                   group
                   by con_addr_id
              where upper(tgt.edge_id) = con_addr_id
    where exists
              SELECT 1
              FROM ods_idl_edge_cont_xref src
              WHERE tgt.contacts_odw_id = src.contacts_odw_id
              AND src.pc_flg='Y'
    and exists
              select null
              from (
                   SELECT listagg(tm, ' ') WITHIN GROUP(ORDER BY con_addr_id) best_time,
                        'IDL - MASS MARKET' odw_upd_by,
                        SYSDATE odw_upd_dt,
                        '0' odw_upd_batch_id,
                        con_addr_id
                   FROM (
                             select Trim(Upper(con_addr_id)) con_addr_id,
                                  ||decode(Initcap(start_day), 'Monday', 'm', 'Tuesday', 'tu', 'Wednesday', 'w', 'Thursday', 'th', 'Friday', 'f', Initcap(start_day))
                                  ||'='
                                  ||trunc(((TO_DATE(start_tm,'HH12:MI:SS PM')-trunc(TO_DATE(start_tm,'HH12:MI:SS PM')))*24*60 ))
                                  ||','
                                  ||trunc(((TO_DATE(end_tm,'HH12:MI:SS PM')-trunc(TO_DATE(end_tm,'HH12:MI:SS PM')))*24*60)) tm
                             FROM (
                                  SELECT DISTINCT * FROM ODS_IDL_EDGE_OFFC_BST_TM
                             WHERE con_addr_id is not null
                   GROUP
                   BY con_addr_id
              where upper(tgt.edge_id) = con_addr_id
    This is an untested code. If there is any syntax error then please fix it and try.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sql Update Statement (complex)

    Hi ,
    A very good morning to all.
    I am stuck in a problem , and i really hope for solutiion.
    I have a dimension table (DIM_CAR) for which i need to write a update statement.
    My table structure is :
    C_ID           Startdate                       EndDate
    7546343    2012-05-29 00:00:00    NULL
    7546343    2012-05-18 00:00:00    2012-05-29 00:00:00
    7546343    2012-05-14 00:00:00    2012-05-18 00:00:00
    7546343    2012-05-10 00:00:00    2012-05-10 00:00:00
    7546343    2012-05-10 00:00:00    2012-05-14 00:00:00
    7546343    2012-03-22 00:00:00    2012-03-22 00:00:00
    7546343    2012-03-15 00:00:00    2012-03-22 00:00:00
    7546343    2012-02-02 00:00:00    2012-03-15 00:00:00
    7546343    2012-01-31 00:00:00    2012-02-02 00:00:00
    Now the scenario is Whenever any update comes in car , then it closes the previous record and open a new record(SCD)
    For e.g the 1st update comes on 2012-02-02 , so it closes the last record (by putting 2012-02-02) in end date and open a new record by putting 2012-02-02 in startdate. Then update comes in 2012-03-15 and so on. The last record is for 2012-05-29 which is
    still open as there is no update after that,
    so whenever any update come it opens a new record with startdate value is extract date and enddate value NULL and closes the previous. Then  after another update , that NULL value is replace by the new date and another record opens.
    My prob is if you will closely analyse the dates , then there are some records missing in the above table due to which there are discrepencies in dates.
    E.g. If u see the 6th row, startdate is 2012-03-22 and enddate is also 2012-03-22. But here in this case the enddate should be 2012-05-10(which is next update)
    I need to write a sql script to update enddates with the latest update startdate in my table. I have 60000 of C_id which are affected.
    COULD ANYONE plz Help.. I knw its difficult but u can give a try ..........Plz ask if anyone requires more info.
    Abhishek

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> I have a dimension table (DIM_CAR) for which I need to write a update statement. My table structure is : <<
    NO! This is a picture of the data; it is not DDL! Is this what you would have posted if you had manners? 
    CREATE TABLE Foobars
    (c_id CHAR(7) NOT NULL, 
     foo_start_date DATE NOT NULL, 
     PRIMARY KEY (c_id, foo_start_date), -- my guess!!
     CHECK (foo_start_date < foo_end_date),-- another guess! 
     foo_end_date DATE);
    INSERT INTO Foobar
    VALUES 
    ('7546343', '2012-05-29', 'NULL), 
    ('7546343', '2012-05-18', '2012-05-29'), 
    ('7546343', '2012-05-14', '2012-05-18'), 
    ('7546343', '2012-05-10', '2012-05-10'), 
    ('7546343', '2012-05-10', '2012-05-14'), 
    ('7546343', '2012-03-22', '2012-03-22'), 
    ('7546343', '2012-03-15', '2012-03-22'), 
    ('7546343', '2012-02-02', '2012-03-15'), 
    ('7546343', '2012-01-31', '2012-02-02');
    Now the scenario is Whenever any update comes in car, then it closes the previous record [sic: rows are not records! Please learn basic terms] and open a new record [sic](SCD). 
    What is “SCD” and why do you think it is meaningful to us? Here is an article on this topic. 
    Modifying Contiguous Time Periods
    This article explains how to modify contiguous time periods that were described in Joe Celko’s article 'Contiguous Time Periods in SQL'.  Joe describes the table itself that he calls the 'Kuznetsov History Table'. He explains how it is used to store contiguous
    time intervals with constraint to ensure that the date periods really are contiguous, The editor suggested that I give a brief description of how to modify the data in the History table as this may not be entirely obvious.
    When trusted constraints enforce data integrity, the data is guaranteed to be valid at the end of any statement, even if it is not committed. When we modify contiguous time periods, in order to get from one valid state to another we may need to insert a row
    and update another one, or we may need to delete a row and update another one. This is one of those cases when MERGE really shines – it allows us to get from one valid state to another in one statement, inserting, updating, and deleting rows as needed.
    CREATE TABLE Tasks
    (task_id INT NOT NULL, 
     task_score INTEGER NOT NULL, 
     current_start_date DATE NOT NULL, 
     current_end_date DATE NOT NULL, 
     previous_end_date DATE NULL, 
     CONSTRAINT PK_Tasks_task_id_current_end_date 
     PRIMARY KEY (task_id, current_end_date), 
     CONSTRAINT UNQ_Tasks_task_id_previous_end_date 
      UNIQUE (task_id, previous_end_date), 
     CONSTRAINT FK_Tasks_task_id_previous_end_date 
      FOREIGN KEY (task_id, previous_end_date) 
      REFERENCES Tasks (task_id, current_end_date), 
     CONSTRAINT CHK_Tasks_previous_end_date_NotAfter_current_start_date 
      CHECK (previous_end_date <= current_start_date), 
     CONSTRAINT CHK_Tasks_current_start_date_Before_current_end_date 
      CHECK (current_start_date < current_end_date)
    Some Easy Modifications.
    It is easy to begin a new series of time periods
    INSERT INTO Tasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date)
    VALUES (1, 100, '2010-1002', '2010-1023', NULL),
           (1, 80, '2010-1023', '2010-11-03', '2010-1023');  
     It is just as easy to continue adding periods to the end of the series.
    INSERT INTO Tasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date)
    VALUES(1, 98, '2010-11-20', '2010-11-25', '2010-11-03'),
          (1, 75, '2010-11-26', '2010-11-27', '2010-11-25');
    Deleting one or more rows from the end is just as easy, and we shall skip the example. As we have seen, it is easy to perform typical, the most common operations against history of periods.
    However, some other operations are less easy and need more explanations. Now that we have enough test data, let us move on to more complex examples. Here is the test data at this moment: 
    Adding periods to the beginning.
    Each series of periods has exactly one first period – this is enforced by the following constraint: Unique_task_id_and_previous_end_date
    As a result, when we are inserting one or more periods to the beginning of the series, we have to update the period that used to be the first, as follows:
    MERGE INTO Tasks 
    USING (VALUES (1, 98, '2009-03-01', '2009-03-06', NULL),
                  (1, 100, '2010-10-02', '2010-10-23', '2009-03-06') 
           ) AS Source (task_id, task_score, current_start_date, current_end_date, previous_end_date)
       ON Tasks.task_id = Source.task_id
           AND Tasks.current_start_date = Source.current_start_date
    WHEN MATCHED 
    THEN UPDATE
         SET task_score = Source.task_score, 
             current_start_date = Source.current_start_date, 
             current_end_date = Source.current_end_date, 
             previous_end_date = Source.previous_end_date
    WHEN NOT MATCHED 
    THEN INSERT (task_id, task_score, current_start_date, current_end_date, previous_end_date)
     VALUES (Source.task_id, Source.task_score, Source.current_start_date,
             Source.current_end_date, Source.previous_end_date); 
    Now we will verify that our test data looks as expected, with a new row at the beginning, and previous_end_date column is modified to point to the new row for the row that used to be the first before this modification:
    We are also going to discuss some other scenarios, such as adding/deleting periods in the middle of the series. In all these cases we shall be using MERGE, and the DML looks quite similar, so let us wrap it up in a stored procedure.
    CREATING A STORED PROCEDURE
    The following code implements this merging functionality with a stored procedure that uses a table to hold teh new rows:
    CREATE TABLE NewTasks
    (task_id INTEGER NOT NULL, 
    task_score INTEGER NOT NULL, 
    current_start_date DATE NOT NULL, 
    current_end_date DATE NOT NULL, 
    previous_end_date DATE NULL,
    deletion_flg CHAR(1));
    CREATE PROCEDURE MergeNewTasks
    AS BEGIN 
    MERGE INTO Tasks 
    USING (SELECT task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg
             FROM NewTasks) AS Source
       ON Tasks.task_id = Source.task_id
          AND Tasks.current_start_date = Source.current_start_date
    WHEN MATCHED AND deletion_flg = 'Y'
    THEN DELETE
    WHEN MATCHED 
    THEN UPDATE SET
         task_score = Source.task_score, 
         current_start_date = Source.current_start_date, 
         current_end_date = Source.current_end_date, 
         previous_end_date = Source.previous_end_date
    WHEN NOT MATCHED 
    THEN INSERT (task_id, task_score, current_start_date, current_end_date, previous_end_date) 
     VALUES (Source.task_id, Source.task_score, Source.current_start_date, Source.current_end_date, Source.previous_end_date);
    END; 
    Let us use this stored procedure.
    Filling a gap in the middle of the series
    The following code fills the gap on November 25th.
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg)
    VALUES (1, 75, '2010-11-25', '2010-11-26', '2010-11-25', 'N'),
     (1, 80, '2010-11-26', '2010-11-27', '2010-11-26', 'N');
    EXEC MergeNewTasks NewTasks = NewTasks;  
    Here is the data after this modification, with a period added in the middle fo the series:
    Deleting a period in the middle of the series
    The following code deletes the period added in the previous example.
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, 
        previous_end_date, deletion_flg)
    VALUES (1, 75, '2010-11-25', '2010-11-26', '2010-11-25', 'Y'),
           (1, 80, '2010-11-26', '2010-11-27', '2010-11-25', 'N');
    EXEC MergeNewTasks;  
    Here is the data after this modification:
    Inserting two periods in the middle, and adjusting an exaisting period to make room for them. This is the last and most complex example involving our stored procedure:
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg)
    VALUES (1, 98, '2010-11-20', '2010-11-22', '2010-11-03', 'N'), 
           (1, 75, '2010-11-22', '2010-11-23', '2010-11-22', 'N'),
           (1, 98, '2010-11-23', '2010-11-25', '2010-11-23', 'N');
    EXEC MergeNewTasks; 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Basic sql update statement

    here are my columns:
    SQL> desc leaguetable;
    Name Null? Type
    LEAGUETABLEID NOT NULL NUMBER(8)
    TOURID NUMBER(8)
    TEAMNAME VARCHAR2(25)
    PLAYED NUMBER(3)
    WON NUMBER(3)
    LOST NUMBER(3)
    DRAW NUMBER(3)
    FORFOR NUMBER(3)
    AGAINST NUMBER(3)
    POINTS NUMBER(3)
    POSITION NUMBER(3)
    here is my update statement...
    Update LEAGUETABLE set played = 1, won = 1, forfor = 3, against = -2, points = 3 where tourid = 10 AND teamName = dundee ;
    here is my error...
    ERROR at line 1:
    ORA-00904: invalid column name
    i dont see anything wrong with my sql statement. any ideas?

    You put us (me) on the wrong track... ORA-00904 is "ORA-00904 string: invalid identifier" not invalid column name.
    But, there is your answer: value should be like "Dundee", with quotes.
    Example:
    SQL> desc leaguetable
    Name Null? Type
    LEAGUETABLEID NOT NULL NUMBER(8)
    TOURID NUMBER(8)
    TEAMNAME VARCHAR2(25)
    PLAYED NUMBER(3)
    WON NUMBER(3)
    LOST NUMBER(3)
    DRAW NUMBER(3)
    FORFOR NUMBER(3)
    AGAINST NUMBER(3)
    POINTS NUMBER(3)
    POSITION NUMBER(3)
    SQL> Update LEAGUETABLE set played = 1, won = 1, forfor = 3, against = -2, points = 3 where tourid =
    10 AND teamName = dundee ;
    ERROR at line 1:
    ORA-00904: "DUNDEE": invalid identifier
    SQL> Update LEAGUETABLE set played = 1, won = 1, forfor = 3, against = -2, points = 3 where tourid =
    10 and teamname = 'DUNDEE';
    1 row updated.

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

Maybe you are looking for

  • March's TechNet Wiki SSIS Guru Winners announced!!

    The results for March'sTechNet Guru competition have been posted! http://blogs.technet.com/b/wikininjas/archive/2014/04/17/the-microsoft-technet-guru-awards-march-2014.aspx <- results page! Congratulations to all our new Gurus for March! We will be i

  • Installation Failed

    I'm trying to install Photoshop CS2 onto a 24" iMac (Intel 2.4ghz) running Leopard. I've successfully installed on 4 other identical machines but this one is giving me a hard time. It proceeds through the installation process and gets to 'Installing

  • Why are certain songs syncing to my iPhone!?

    I have iTunes set to sync a couple if specific playlists (both smart, and static). However, there are a handful of certain songs that keep syncing to my iPhone no matter how many times I delete them. They are not in any of the playslists set to sync.

  • Toshiba Regza fades to black

    I have a 42" Toshiba Regza about five years old.  Recently, when I turn it on the picture shows for a second and then fades to black.  The audio still works during this time.  I turn it off and on a few times and finally the picture stays.  Anyone kn

  • Button pops link in a new window

    Hello everyone, This is a rather simple question for all gurus out there, but it seems a bit hard to find on documentation. How can you open a link in a new window with a button in a flash form? I want a button on my form to pop a new window with the