Update Statement: Multi Level Inline view.

Here is the test case.
create table source(old_val integer, new_val integer)
create table target(val integer)
insert into target values(1)
insert into target values(2)
insert into target values(3)
insert into source values(1,4)
insert into source values(1,5)
insert into source values(2,6)
insert into source values(3,7)
insert into source values(3,8)
commit
/ Now i want to update target.val with source.val and the matching condition is source.old_val = target.val
But source.old_val may have multiple values for a given target.val. You can see that in the example. So i want to order by ROWID of source and pick the first record.
So i wrote a UPDATE.
SQL> update target t
  2     set (val) = (select new_val
  3               from (select new_val, row_number() over(order by rowid) rno
  4                       from source s
  5                      where s.old_val = t.val)
  6              where rno = 1)
  7   where exists(select null
  8             from source s
  9            where t.val = s.old_val)
10  /
3 rows updated.and this is what i got.
SQL> select * from target
  2  /
       VAL
         4
         4
         4
SQL> select * from source
  2  /
   OLD_VAL    NEW_VAL
         1          4
         1          5
         2          6
         3          7
         3          8i was expecting the value to be updated as 4,6,7 or 5,6,8 but not sure why its 4,4,4.
Just trying to understand how this update is being processed. Not sure if i am missing something basic.
NOTE: I am interested in knowing the behavior of this update statement and not an alternative method to solve the issue.
Thanks,
Karthick.

>
Karthick_Arp wrote
i was expecting the value to be updated as 4,6,7 or 5,6,8 but not sure why its 4,4,4.
>
if you want 4,5,6 , why you are defining RNO = 1!?
SQL> SELECT new_val
  2    FROM (SELECT new_val
  3                ,row_number() over(Order BY s.Rowid) rno
  4            FROM Source s
  5                ,target t
  6           WHERE s.old_val = t.val)
  7   WHERE rno = 1
  8  /
                                NEW_VAL
                                      4look at this,
SQL> SELECT new_val
  2    FROM (SELECT new_val
  3                ,row_number() over(Order BY s.Rowid) rno
  4            FROM Source s
  5                ,target t
  6           WHERE s.old_val = t.val)
  7   WHERE rno <= 3
  8  /
                                NEW_VAL
                                      4
                                      5
                                      6Regards,
Christian Balz
Edited by: Christian Balz on 22/06/2009 06:06

Similar Messages

  • Hint in Update or Select Statement in an inline query ??

    Hi ,
    I had an update statement that will get the data from the inline select statement,now where can i can keep the hint ,either in update statement or in Select statement...
    Please let me know if my sample script is wrong or any better way to approach...Please assume that Salary table had millions of employee's salary records.
    update emp
    set salary = salary + (select /*+ full(a) parallel(a,4)  */ salary from Salary
                             where   experience > 5  and empno = 55 )
    where empno = 85Thanks
    Rede

    You would put the hint in the select statement as you have it, but it won't work until you alias your table name to "a" since that is how you are referencing it in the hint:
    update emp
    set salary = salary + (select /*+ full(a) parallel(a,4)  */ salary from Salary a
                             where   experience > 5  and empno = 55 )
    where empno = 85
    NOTE I added the "a" right after the Salary table name AND you can only do parallel updates on partitioned table, but the select will run in parallel to at least get the data for you quickly.
    To answer your other question about syntax, it is incorrect and there are a lot of ways to write it but a straight forward way would be to use the merge statement
    merge into emp e
    using (select /*+ full(s) parallel(s,4)  */ s.salary from salary s where s.experience > 5) s
    on (e.empno = s.empno)
    when matched then update
    set salary = s.salary;

  • Updated content for multi-level record structure in PLSQL

    Hi All,
    please help me
    Need a FUNCTION which would take PERSON_id as the INPUT PARAMETER and RETURN the FULL DETAILS in a multi-level record structure in PLSQL.
    CREATE TABLE people(
    name VARCHAR2(5),
    person_id number
    INSERT INTO people(name,person_id) VALUES ('n1',1);
    INSERT INTO people(name,person_id) VALUES ('n2',2);
    INSERT INTO people(name,person_id) VALUES ('n3',3);
    INSERT INTO people(name,person_id) VALUES ('n4',4);
    INSERT INTO people(name,person_id) VALUES ('n5',5);
    INSERT INTO people(name,person_id) VALUES ('n6',6);
    A person can be assigned many tasks. Below,we can see person_id =1 has 2 tasks 10,20
    CREATE TABLE tasks(
    task_id number,              --->PK
    task_name VARCHAR2(5),
    person_id number          -->FK to People
    INSERT INTO tasks(task_id,task_name,person_id) VALUES (10, 'cleaning',1);
    INSERT INTO tasks(task_id,task_name,person_id) VALUES (20', 'washing',1);
    INSERT INTO tasks(task_id,task_name,person_id) VALUES (30, 'sweeping',2);
    INSERT INTO tasks(task_id,task_name,person_id) VALUES (40, 'ironing',3);
    Each TASK has many ACTIVTIES as below. Below,we can see task_id =10 ---->3 ACTIVITIES of activity_id of 100,200,300
    CREATE TABLE activities(
    activity_id number,
    activity_name VARCHAR2(50),
    task_id number,              --->FK  to task table
    INSERT INTO activities(activity_id,activity_name,task_id)VALUES (100, 'Clean home',10);
    INSERT INTO activities(activity_id,activity_name,task_id)VALUES (200, 'Clean Garden',10);
    INSERT INTO activities(activity_id,activity_name,task_id)VALUES (300, 'Clean clothes,10');
    INSERT INTO activities(activity_id,activity_name,task_id)VALUES (400, 'Wash car',20);
    Write a FUNCTION which would take PERSON_id as the INPUT PARAMETER and RETURN the FULL DETAILS in a multi-level record structure in PLSQL.
    Meaning We would get
    First ,person_details for a person-->next level is TASKS-->Activities_list in a NESTED RECORD SET
    create or replace function person_details(person_id NUMBER)
    RETURNs a
    PERSON_DETAILS RECORD structure as shown below.A person -->Tasks--> all activities
    record PERSON_DETAILS[1]
         person_id,
         name
         TASKS_DETAILS[1]          ---->2nd level
                     task_id[1],
               task_name[1]
                   ACTIVITIES[1]----->3rd level
                        activity_id[1],
                        activity_name[1]     
                      ACTIVITIES[2]
                        activity_id[2],
                        activity_name[2]                    
                   ACTIVITIES[3]
                        activity_id[3],
                        activity_name[3]
    *(1)--Most important part is how do i DEFINE AND DECLARE the RESULT RECORD SET in my FUNCTION?
      (2)--HOW DO WE DYNAMICALLY ALOCATE MEMORY for the record structure based on the no. of rows by each SELECT?
       (3)Access the nested levels and FILL in the DATA in the above record seperately USING SELECT statements.
    */*SELECT 1 ---Find and fill Person*/*
    *select person_id,name from people where person_id =1*
    *-->From this SELECT fill the OUTER record PERSON_DETAILS[no. of records] -->person_id,name*
    */**SELECT 2 ---I want to FIND all TASKS for THE ABOVE PERSON and fill the next part */*
    *select task_id,name from tasks where person_id = PERSON_DETAILS[1].person_id*
    *We get three TASK_ids,*
    *-->From this, HOW TO fill DATA for each TASK,how to  PERSON_DETAILS[1]->TASKS_DETAILS[1st record].task_id -->person_id,name*
    */**SELECT 3 ---I want to FIND all ACTIVITIES for THE ABOVE TASKS and fill the next part */*
    *for EACH of the TASKS found,we need to LOOP and*
    *select activity_id,name from activities where task_id = PERSON_DETAILS[1].-->TASKS_DETAILS[1st record]--->ACTIVITY_DETAILS[1].activity_id*
    I have tried my best to explain with the tables and the relationships.I just hope its not confusing now.Edited by: user_7000011 on 01-Apr-2009 12:46

    try this one.
    Learned something new today.
    CREATE TABLE temp_clob_tab(result CLOB);
    CREATE or replace TYPE task_t AS OBJECT("@task_id"   NUMBER,
                                last_name        VARCHAR2(20),
                                 activitylist     activity_tab
    create or replace type activity_t as object("@activity_id" number, activity_name varchar2(20));
    CREATE or replace  TYPE tasklist_t AS TABLE OF task_t;
    create or replace type activity_tab as table of activity_t;
    CREATE or replace TYPE people_t AS OBJECT("@people_id" NUMBER,
                                 task_name  VARCHAR2(20),
                                 task_t          tasklist_t
    DECLARE
      qryCtx DBMS_XMLGEN.ctxHandle;
      result CLOB;
    BEGIN
      DBMS_XMLGEN.setRowTag(qryCtx, NULL);
      qryCtx := DBMS_XMLGEN.newContext
        ('SELECT people_t(person_id,
                        name,
                        CAST(MULTISET
                               (SELECT e.task_id, e.task_name,cast(multiset
                                        (select activity_id,activity_name from activities a
                                            where a.task_id = e.task_id) as activity_tab)
                                  FROM tasks e
                                  WHERE e.person_id= d.person_id)
                             AS tasklist_t))
            AS peoplexml
            FROM people d
            where person_id = 1');
      -- now get the result
      result := DBMS_XMLGEN.getXML(qryCtx);
      INSERT INTO temp_clob_tab VALUES (result);
      -- close context
      DBMS_XMLGEN.closeContext(qryCtx);
    END;
    select * from          temp_clob_tab ;output
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
      <PEOPLEXML people_id="1">
       <TASK_NAME>n1</TASK_NAME>
       <TASK_T>
        <TASK_T task_id="10">
         <LAST_NAME>cleaning</LAST_NAME>
         <ACTIVITYLIST>
          <ACTIVITY_T activity_id="100">
           <ACTIVITY_NAME>Clean home</ACTIVITY_NAME>
          </ACTIVITY_T>
          <ACTIVITY_T activity_id="200">
           <ACTIVITY_NAME>Clean Garden</ACTIVITY_NAME>
          </ACTIVITY_T>
          <ACTIVITY_T activity_id="300">
           <ACTIVITY_NAME>Clean clothes</ACTIVITY_NAME>
          </ACTIVITY_T>
         </ACTIVITYLIST>
        </TASK_T>
        <TASK_T task_id="20">
         <LAST_NAME>washing</LAST_NAME>
         <ACTIVITYLIST>
          <ACTIVITY_T activity_id="400">
           <ACTIVITY_NAME>Wash car</ACTIVITY_NAME>
          </ACTIVITY_T>
         </ACTIVITYLIST>
        </TASK_T>
       </TASK_T>
      </PEOPLEXML>
    </ROW>
    </ROWSET>

  • Multi level grouping in views

    Hi 
    I am using SharePoint 2013, I wanted help on how to do multi level grouping in views.
    The view should be like as follows:
    -Category1
       -Level1
          -Title1
               data
    -Category2
        -Level2
           -Title2
               data 

    http://social.technet.microsoft.com/Forums/sharepoint/en-US/7085c62f-ee31-4655-bca9-0d4cef946374/multi-level-grouping-issue-in-sharepoint-2010?forum=sharepointgeneralprevious
    previously asked questions contain a link to:
    http://techtrainingnotes.blogspot.in/2011/01/sharepoint-group-by-on-more-than-2.html
    The article basically describes how to create and use a DVWP instead of a XSLT List View. The out of the box SharePoint list view cannot have more than two groups. You need to either edit the View page and add a DVWP or create a new page with a DVWP.
    SP 2010 view pages lose some functionality if web parts are added (showing ribbon is not as straightforward and view selector disappears), but there are workarounds.
    In some cases, a Web Part Page with a DVWP may be a better alternative.
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/82e7123d-9ff1-430b-a43c-0b937185574f/multiple-level-grouping-and-counting-help-in-sharepoint-designer?forum=sharepointcustomizationlegacy
    http://suguk.org/forums/11092/ShowThread.aspx

  • Inline views in a cursor statements

    Hi,
    I just want to know is it possible to use an inline view in a cursor, like
    cursor sample is select sysdate,(select sysdate from dual) from dual;
    if not what are the other alternatives, kindly revert as soon as possible...its a bit urgent...
    cheere

    i used the following anonymous block, and i get the following error,
    declare
    cursor indiavsaustralia is select sysdate,(select sysdate from dual) from dua;
    begin
    null;
    emd;
    The following error has occurred:
    ORA-06550: line 2, column 44:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + mod not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count current exists max min prior sql stddev sum variance
    execute forall time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string>
    ORA-06550: line 2, column 70:
    PLS-00103: Encountered the symbol "FROM" when expecting one of the following:
    ; return returning and or
    ORA-06550: line 6, column 0:
    PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
    begin declare end exception exit for goto if loop mod null
    pragma raise return select update while <an identifier>
    <a double-quoted delimited-id
    cheere..........

  • UPDATING OSX MOUNTAIN LION ADOBE VIEWER. recently received e-bill statement. could not view. site recommended updating adobe viewer. as this feature comes OEM from Apple, how is this accomplished?

    UPDATING OSX MOUNTAIN LION ADOBE VIEWER. recently received e-bill statement. could not view. site recommended updating adobe viewer. as this feature comes OEM from Apple, how is this accomplished? Note, this was an online view for the PDF document.

    Thanks for your help.  Final question. So I am assuming that PDF funcitonality is accomplished via Preview.  I assume then that the PDF creation in Mail is also similarly accomplished, that is not via an Adobe product, but equivalent funcitonality. I see now that I can download Adobe. But, does the Apple PDF equivlant provide updates to keep up witht the new encoding structures released by Adobe, so that I can only update the Apple equivalent, or is this not practical because Apple would be chasing Adobe for software updates?

  • How to create view that has an update statement

    Tools: MS Management Studio SQL 2008 R2
    Code:
    Create View as Mocha
    UPDATE dbo.Cola
    SET Login_ID = Replace(PE15,RTRIM(Cast(Login_ID),'')
    UPDATE dbo.cola
    SET P4 = NullIf(P4,'')
    I would like to create a database object "View" to hand it over to a user and run the script. How I would create a a view that would accept an update statement. Are any work around to accomplish this goal

    Not quite sure what you want to achieve.
    However, if your view displays rows from a single table and each row relates to exactly one row in the source table (no aggregates, no join, no transformation) then you can update it.  The update will be executed on the table it refers to.
    If you view is more complex, contains joins, aggregates and such, you can create a trigger on it to update the base table(s).
    The conditions for a view to be updatable are a little more complex then what I wrote but you can find it here under "updatable view":
    http://msdn.microsoft.com/en-CA/library/ms187956.aspx
    In the end, you would have a view which displays rows and can be updated.
    If all you want is to modify rows without viewing them then HuaMin Chen's solution is the one for you, create a stored procedure instead.

  • Oracle 11G - Update is very slow on View

    I have big trouble with some Update query on Oracle 11G.
    I have a set of tables (5) of identical structures and a view that consists in an UNION ALL of the 5 tables.
    None of this table contains more than 20 000 rows.
    Let's call the view V_INTE_NE. Each of the basic table has a PRIMARY KEY defined on 3 NUMBERS(10,0) -> INTE_REF / NE_REF / INSTANCE.
    Now, I get 6 rows in another table and I want to update my view from the data of this small table (let's call it SMALL). This table has the 3 columns INTE_REF / NE_REF / INSTANCE.
    When I try to join the two tables :
    SELECT * FROM T_INTE_NE T2
    WHERE EXISTS ( SELECT 1 FROM SMALL T1 WHERE T2.INTE_REF = T1.INTEREF AND T2.NE_REF = T1.NEREF AND T2.INTE_INST = T1.INSTANCE )
    I get the 6 lines in 0.037 seconds
    When I try to update the view (I have an INSTEAD OF trigger that does nothing (just return for testing even without modifying anything), I execute the following query :
    UPDATE T_INTE_NE T2
    SET INTE_STATE = -11 WHERE
    EXISTS ( SELECT 1 FROM SMALL T1 WHERE T2.INTE_REF = T1.INTEREF AND T2.NE_REF = T1.NEREF AND T2.INTE_INST = T1.INSTANCE )
    The 6 rows are updated (at least TRIGGER is called) in 20 seconds.
    However, in the execution plan, I can't see where Oracle takes time to achieve the query :
    Plan hash value: 907176690
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | UPDATE STATEMENT | | 6 | 36870 | 153 (1)| 00:00:02 |
    | 1 | UPDATE | T_INTE_NE | | | | |
    |* 2 | HASH JOIN RIGHT SEMI | | 6 | 36870 | 153 (1)| 00:00:02 |
    | 3 | TABLE ACCESS FULL | SMALL | 6 | 234 | 9 (0)| 00:00:01 |
    | 4 | VIEW | T_INTE_NE | 6 | 36636 | 143 (0)| 00:00:02 |
    | 5 | VIEW | X_V_T_INTE_NE | 6 | 18636 | 143 (0)| 00:00:02 |
    | 6 | UNION-ALL | | | | | |
    | 7 | TABLE ACCESS FULL| SECNODE1_T_INTE_NE | 1 | 3106 | 60 (0)| 00:00:01 |
    | 8 | TABLE ACCESS FULL| SECNODE2_T_INTE_NE | 1 | 3106 | 60 (0)| 00:00:01 |
    | 9 | TABLE ACCESS FULL| SECNODE3_T_INTE_NE | 1 | 3106 | 2 (0)| 00:00:01 |
    | 10 | TABLE ACCESS FULL| SECNODE4_T_INTE_NE | 1 | 3106 | 2 (0)| 00:00:01 |
    | 11 | TABLE ACCESS FULL| SECNODE5_T_INTE_NE | 1 | 3106 | 2 (0)| 00:00:01 |
    | 12 | TABLE ACCESS FULL| SYS_T_INTE_NE | 1 | 3106 | 17 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - access("T2"."INTE_REF"="T1"."INTEREF" AND "T2"."NE_REF"="T1"."NEREF" AND
    "T2"."INTE_INST"="T1"."INSTANCE")
    Note
    - dynamic sampling used for this statement (level=2)
    Statistics
    3 user calls
    0 physical read total bytes
    0 physical write total bytes
    0 spare statistic 3
    0 commit cleanout failures: cannot pin
    0 TBS Extension: bytes extended
    0 total number of times SMON posted
    0 SMON posted for undo segment recovery
    0 SMON posted for dropping temp segment
    0 segment prealloc tasks
    What could explain the difference ?
    I get exactly the same execution plan (when autotrace is ON).
    Furthermore, if I try to do the same update on each of the basic tables, I get the rows updated instantaneously.
    Is there any reason for avoiding this kind of query ?
    Any help would be greatly appreciated :-)
    Regards,
    Patrick

    Sorry for this, I lost myself in conjonctures and I didn't think I would have to explain the whole case.
    So, I wrote a small piece of PL/SQL that reproduces the same issue.
    It seems that my issue is not due to the UPDATE but to the use of the IN predicate.
    As you can see at the end of the script, I try to join the 2 tables using different technics.
    The first query is very fast, the second is very slow.
    I need the second one if I want to do any update.
    DROP TABLE Part1;
    DROP TABLE Part2;
    DROP TABLE Part3;
    DROP TABLE Part4;
    CREATE TABLE Part1 ( Key1 NUMBER(10, 0), Key2 NUMBER(10, 0), Key3 NUMBER(10, 0), PartId NUMBER(10, 0) DEFAULT( 1 ) NOT NULL, Data1 VARCHAR2(1000), X_Data2 VARCHAR2(2000) NULL, X_Data3 VARCHAR2(2000) NULL, CONSTRAINT PK_Part1 PRIMARY KEY( Key1, Key2, Key3 ) );
    CREATE TABLE Part2 ( Key1 NUMBER(10, 0), Key2 NUMBER(10, 0), Key3 NUMBER(10, 0), PartId NUMBER(10, 0) DEFAULT( 2 ) NOT NULL, Data1 VARCHAR2(1000), X_Data2 VARCHAR2(2000) NULL, X_Data3 VARCHAR2(2000) NULL, CONSTRAINT PK_Part2 PRIMARY KEY( Key1, Key2, Key3 ) );
    CREATE TABLE Part3 ( Key1 NUMBER(10, 0), Key2 NUMBER(10, 0), Key3 NUMBER(10, 0), PartId NUMBER(10, 0) DEFAULT( 3 ) NOT NULL, Data1 VARCHAR2(1000), X_Data2 VARCHAR2(2000) NULL, X_Data3 VARCHAR2(2000) NULL, CONSTRAINT PK_Part3 PRIMARY KEY( Key1, Key2, Key3 ) );
    CREATE TABLE Part4 ( Key1 NUMBER(10, 0), Key2 NUMBER(10, 0), Key3 NUMBER(10, 0), PartId NUMBER(10, 0) DEFAULT( 4 ) NOT NULL, Data1 VARCHAR2(1000), X_Data2 VARCHAR2(2000) NULL, X_Data3 VARCHAR2(2000) NULL, CONSTRAINT PK_Part4 PRIMARY KEY( Key1, Key2, Key3 ) );
    CREATE OR REPLACE FUNCTION Decrypt
    x_in IN VARCHAR2
    ) RETURN VARCHAR2
    AS
    x_out VARCHAR2(2000);
    BEGIN
    SELECT REVERSE( x_in ) INTO x_out FROM DUAL;
    RETURN ( x_out );
    END;
    CREATE OR REPLACE VIEW AllParts AS
    SELECT Key1, Key2, Key3, PartId, Data1, Decrypt( X_Data2 ) AS Data2, Decrypt( X_Data3 ) AS Data3 FROM Part1
    UNION ALL
    SELECT Key1, Key2, Key3, PartId, Data1, Decrypt( X_Data2 ) AS Data2, Decrypt( X_Data3 ) AS Data3 FROM Part2
    UNION ALL
    SELECT Key1, Key2, Key3, PartId, Data1, Decrypt( X_Data2 ) AS Data2, Decrypt( X_Data3 ) AS Data3 FROM Part3
    UNION ALL
    SELECT Key1, Key2, Key3, PartId, Data1, Decrypt( X_Data2 ) AS Data2, Decrypt( X_Data3 ) AS Data3 FROM Part4;
    DROP TABLE Small;
    CREATE TABLE Small ( Key1 NUMBER(10, 0), Key2 NUMBER(10, 0), Key3 NUMBER(10, 0), Data1 VARCHAR2(1000) );
    BEGIN
    DECLARE
    n_Key NUMBER(10, 0 ) := 0;
    BEGIN
    WHILE ( n_Key < 50000 )
    LOOP
    INSERT INTO Part1( Key1, Key2, Key3 )
    VALUES( n_Key, FLOOR( n_Key / 10 ), FLOOR( n_Key / 100 ) );
    INSERT INTO Part2( Key1, Key2, Key3 )
    VALUES( n_Key, FLOOR( n_Key / 10 ), FLOOR( n_Key / 100 ) );
    INSERT INTO Part3( Key1, Key2, Key3 )
    VALUES( n_Key, FLOOR( n_Key / 10 ), FLOOR( n_Key / 100 ) );
    INSERT INTO Part4( Key1, Key2, Key3 )
    VALUES( n_Key, FLOOR( n_Key / 10 ), FLOOR( n_Key / 100 ) );
    n_Key := n_Key + 1;
    END LOOP;
    INSERT INTO Small( Key1, Key2, Key3, Data1 ) VALUES ( 1000, 100, 10, 'Test 1000' );
    INSERT INTO Small( Key1, Key2, Key3, Data1 ) VALUES ( 3000, 300, 30, 'Test 3000' );
    INSERT INTO Small( Key1, Key2, Key3, Data1 ) VALUES ( 5000, 500, 50, 'Test 5000' );
    COMMIT;
    END;
    END;
    SELECT T2.*
    FROM Small T1, AllParts T2
    WHERE T2.Key1 = T1.Key1 AND T2.Key2 = T1.Key2 AND T2.Key3 = T1.Key3;
    SELECT T1.*
    FROM AllParts T1
    WHERE ( T1.Key1, T1.Key2, T1.Key3 ) IN ( SELECT T2.Key1, T2.Key2, T2.Key3 FROM Small T2 );

  • 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

  • Update a table from a view (WITH)

    Hello,
    Is the below valid? Can I update table1 from table2 (view)?
    Oracle is 9i
    UPDATE
    WITH t2 AS (
    SELECT....................
    SELECT t1.name n1, t2.name n2
    FROM cell_info t1, t2
    WHERE t1.cell = t2.cell
    AND t1.name IS NULL
    SET n1 = n2;
    SQL Error: ORA-01732: data manipulation operation not legal on this view
    01732. 00000 - "data manipulation operation not legal on this view"

    Hi,
    there are cases where you can update an inline view :Scott@my10g SQL>create table t1 as select level id, chr(96+level) val
      2  from dual
      3  connect by level <= 6
      4  /
    Table created.
    Scott@my10g SQL>create table t2 as select level id, cast(null as varchar2(30)) val
      2  from dual
      3  connect by level <= 6
      4  /
    Table created.
    Scott@my10g SQL>alter table t1 add constraint t1_pk primary key (id);
    Table altered.
    Scott@my10g SQL>alter table t2 add constraint t2_pk primary key (id);
    Table altered.
    Scott@my10g SQL>select * from t1;
            ID VAL
             1 a
             2 b
             3 c
             4 d
             5 e
             6 f
    6 rows selected.
    Scott@my10g SQL>select * from t2;
            ID VAL
             1
             2
             3
             4
             5
             6
    6 rows selected.
    Scott@my10g SQL>update (
      2  select t1.id, t1.val t1val, t2.val t2val
      3  from t1
      4  join t2
      5  on t1.id=t2.id
      6  )
      7  set t2val=t1val
      8  /
    6 rows updated.
    Scott@my10g SQL>select * from t2;
            ID VAL
             1 a
             2 b
             3 c
             4 d
             5 e
             6 f
    6 rows selected.

  • What is the best way to replace the Inline Views for better performance ?

    Hi,
    I am using Oracle 9i ,
    What is the best way to replace the Inline Views for better performance. I see there are lot of performance lacking with Inline views in my queries.
    Please suggest.
    Raj

    WITH plus /*+ MATERIALIZE */ hint can do good to you.
    see below the test case.
    SQL> create table hx_my_tbl as select level id, 'karthick' name from dual connect by level <= 5
    2 /
    Table created.
    SQL> insert into hx_my_tbl select level id, 'vimal' name from dual connect by level <= 5
    2 /
    5 rows created.
    SQL> create index hx_my_tbl_idx on hx_my_tbl(id)
    2 /
    Index created.
    SQL> commit;
    Commit complete.
    SQL> exec dbms_stats.gather_table_stats(user,'hx_my_tbl',cascade=>true)
    PL/SQL procedure successfully completed.
    Now this a normal inline view
    SQL> select a.id, b.id, a.name, b.name
    2 from (select id, name from hx_my_tbl where id = 1) a,
    3 (select id, name from hx_my_tbl where id = 1) b
    4 where a.id = b.id
    5 and a.name <> b.name
    6 /
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=7 Card=2 Bytes=48)
    1 0 HASH JOIN (Cost=7 Card=2 Bytes=48)
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'HX_MY_TBL' (TABLE) (Cost=3 Card=2 Bytes=24)
    3 2 INDEX (RANGE SCAN) OF 'HX_MY_TBL_IDX' (INDEX) (Cost=1 Card=2)
    4 1 TABLE ACCESS (BY INDEX ROWID) OF 'HX_MY_TBL' (TABLE) (Cost=3 Card=2 Bytes=24)
    5 4 INDEX (RANGE SCAN) OF 'HX_MY_TBL_IDX' (INDEX) (Cost=1 Card=2)
    Now i use the with with the materialize hint
    SQL> with my_view as (select /*+ MATERIALIZE */ id, name from hx_my_tbl where id = 1)
    2 select a.id, b.id, a.name, b.name
    3 from my_view a,
    4 my_view b
    5 where a.id = b.id
    6 and a.name <> b.name
    7 /
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=1 Bytes=46)
    1 0 TEMP TABLE TRANSFORMATION
    2 1 LOAD AS SELECT
    3 2 TABLE ACCESS (BY INDEX ROWID) OF 'HX_MY_TBL' (TABLE) (Cost=3 Card=2 Bytes=24)
    4 3 INDEX (RANGE SCAN) OF 'HX_MY_TBL_IDX' (INDEX) (Cost=1 Card=2)
    5 1 HASH JOIN (Cost=5 Card=1 Bytes=46)
    6 5 VIEW (Cost=2 Card=2 Bytes=46)
    7 6 TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D6967_3C610F9' (TABLE (TEMP)) (Cost=2 Card=2 Bytes=24)
    8 5 VIEW (Cost=2 Card=2 Bytes=46)
    9 8 TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D6967_3C610F9' (TABLE (TEMP)) (Cost=2 Card=2 Bytes=24)
    here you can see the table is accessed only once then only the result set generated by the WITH is accessed.
    Thanks,
    Karthick.

  • Errow with IF statement in Scripted Calculation view

    Hi Team,
    I am trying to use IF statement in Scripted Calculation view.
    My scenario is:-
    I need to create a restricted Key figure based on input date from user.
    While i am activating my view system gives "Internal deployment of object failed;Repository: Encountered an error in repository runtime extension;Internal Error:Deploy Calculation View: SQL: transaction rolled back by an internal error: Syntax Error for calculated Attribute: line 29 col 9 (at pos 1501)" error.
    Below is the code i have used in my CV.
    CE_CALC('IF((to_int("BUDAT") >= to_int(2013-01-01),"AMOUNT",'''')', DECIMAL(13,2)) AS "DTR"
    Here, "AMOUNT" is another calculated field created using CE_CALC.
    Without above IF statement my CV runs perfectly fine. The moment i include IF statement it does not activate.
    Kindly provide your inputs.
    Thanks & Regards,
    Anup

    Hi Lars,
    I am extremely sorry about the confusion.
    There was an extra parenthesis in the IF statement which was not allowing the CV to be activated. CV is now successfully activated.
    But my data is not getting restricted correctly.
    It is showing 0 against all the records.
    Below is the sql used for calling the CV.
    SELECT * FROM "_SYS_BIC"."A_123/CV_SCR_BSID_BSAD_ITEMS" ('PLACEHOLDER' = ('$$Currency$$', '''Local'''),'PLACEHOLDER' = ('$$Date_From$$','2014-01-01' ), 'PLACEHOLDER' = ('$$Date_To$$','2014-06-30' ));
    Below is my updated CE_CALC function :-
    CE_CALC('IF(date("BUDAT") >= date(:Date_From) and date("BUDAT") <= date(:Date_To),"AMOUNT",0)', DECIMAL(13,2)) AS "DTR"
    Is there any issue while passing values here?
    Regards,
    Anup

  • Multi level attribute form LDAP

    multi level attribute form LDAP
    I am trying to write an custom mapping to use to retrieve a value from a multialued field in LDAP (nsRole). Has anyone done this before?
    Rigth now all my mappings are 1:1. However the goal is to get a 1 : M and parse thru it till i get the desied value (1:1)

    Darwin Hammons - Assurant 
    2:44pm, May 17 
    Great conversation. I have a very similar question about the use of the custom JAVA mappings with the LDAP Login process. I want to include an additional (event) step in the login process. Does anyone have an example or experience with a custom Java Class mapping that can use an LDAP attribute (location)  queriing the data to execute an event that populates an RequestCenter OU or Group if the person login location equal say " Argentina" ? Looking for a way to manage / build catalog entitlements during login. Suggestions ?
    Great conversation. I have a very similar question about the use of the custom JAVA mappings with the LDAP Login process. I want to include an additional (event) step in the login process. Does anyone have an example or experience with a custom Java Class mapping that can use an LDAP attribute (location)  queriing the data to execute an event that populates an RequestCenter OU or Group if the person login location equal say " Argentina" ? Looking for a way to manage / build catalog entitlements during login. Suggestions ?
    Anthony Erickson
    2:52pm, May 18  
    Hi Darwin,
    We're about to embark on a piece of work with newScale which would be similar to this to support our Multilingual catalogue.  I'll provide any updates I'm able. 
    Thanks,
    Ant 
    Darwin Hammons - Assurant 
    3:25pm, May 18 
    Great, Thanks Anthony ! I hope our bringing up this topic will spark a bit of interest. The Custom Java Mapping  / Directory integration is documented more with RC 9.1. It will be good to hear more about your project and use of Java mappings with LDAP Directories. 

  • How to create multi-level style pulling in a .jpg image as a bullet?

    From within RoboHelp 8 HTML, when creating/editing a 3-tier multi-level style, I want to use a .jpg image for the bullet(s).  I can not find a way to point to the image while in Edit mode.  My only choices are predefined bullets for the List Style.
    When searching for an answer within the forum, I noticed mention of a Baggage folder in RoboHelp.  I do not have a Baggage folder.  I do have links to websites accessible from within the web-based Help file I've created beneath the URLs folder in the Project Manager.
    Thank you for any help you can provide.

    Hi there
    I never really played much with adding images to the oddly formatted Multi-list styles.
    The Project Manager has two views. Sounds like you are using the new "global" view. In that view you don't see a special area labeled Baggage Files. In this view the files are simply listed among the other content. If you change the view to Classic (I think it's the first icon on the left of the pod toolbar) you will then see the Baggage Files folder.
    Cheers... Rick
    Helpful and Handy Links
    RoboHelp Wish Form/Bug Reporting Form
    Begin learning RoboHelp HTML 7 or 8 within the day - $24.95!
    Adobe Certified RoboHelp HTML Training
    SorcerStone Blog
    RoboHelp eBooks

  • Does an inline view execute before the rest of the select?

    Hi,
    The O'Reilly book Mastering Oracle Sql defines an inline view simply as a
    subquery in a select FROM clause. This conforms to the definitions in
    the Oracle 9i and 10g docs.
    But unlike the Oracle docs, the O'Reilly book says the inline view is,
    like a WITH clause, executed before the rest of the query. I can't see
    how this can be done unless the inline view makes no reference to
    other tables joined in the FROM clause.
    Is there a species of inline view in 9i/10g that IS restricted as above -
    no refs to other tables in the FROM clause - and what is it called?
    Thanks for any help.
    Ken Quirici

    As explained above, Oracle can choose to merge the query if feasible to do so. Look at the two queries and their plans below. The plan in second query changes to creating a temporary VIEW since in that case, Oracle is unable to perform the merge:
    SQL> select *
      2          from scott.emp e,
      3                  (select * from scott.dept d where d.deptno = 10) dd
      4  where
      5          e.deptno = dd.deptno
      6  /
         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO     DEPTNO DNAME          LOC
          7782 CLARK      MANAGER         7839 09-JUN-1981       2450                    10         10 ACCOUNTING     NEW YORK
          7839 KING       PRESIDENT            17-NOV-1981       5000                    10         10 ACCOUNTING     NEW YORK
          7934 MILLER     CLERK           7782 23-JAN-1982       1300                    10         10 ACCOUNTING     NEW YORK
    3 rows selected.
    Execution Plan
    Plan hash value: 3570059291
    | Id  | Operation                    | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |                |     3 |   171 |     2   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                |                |     3 |   171 |     2   (0)| 00:00:01 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| DEPT           |     1 |    20 |     1   (0)| 00:00:01 |
    |*  3 |    INDEX UNIQUE SCAN         | PK_DEPT        |     1 |       |     0   (0)| 00:00:01 |
    |   4 |   TABLE ACCESS BY INDEX ROWID| EMP            |     3 |   111 |     1   (0)| 00:00:01 |
    |*  5 |    INDEX RANGE SCAN          | IDX_EMP_DEPTNO |     3 |       |     0   (0)| 00:00:01 |
    SQL> select *
      2          from scott.emp e,
      3                  (select * from scott.dept d where d.deptno = 10 and rownum > 0) dd
      4  where
      5          e.deptno = dd.deptno
      6  /
         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO     DEPTNO DNAME          LOC
          7782 CLARK      MANAGER         7839 09-JUN-1981       2450                    10         10 ACCOUNTING     NEW YORK
          7839 KING       PRESIDENT            17-NOV-1981       5000                    10         10 ACCOUNTING     NEW YORK
          7934 MILLER     CLERK           7782 23-JAN-1982       1300                    10         10 ACCOUNTING     NEW YORK
    3 rows selected.
    Execution Plan
    Plan hash value: 1670713873
    | Id  | Operation                       | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                |                |     5 |   280 |     2   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                   |                |     5 |   280 |     2   (0)| 00:00:01 |
    |   2 |   VIEW                          |                |     1 |    19 |     1   (0)| 00:00:01 |
    |   3 |    COUNT                        |                |       |       |            |          |
    |*  4 |     FILTER                      |                |       |       |            |          |
    |   5 |      TABLE ACCESS BY INDEX ROWID| DEPT           |     1 |    20 |     1   (0)| 00:00:01 |
    |*  6 |       INDEX UNIQUE SCAN         | PK_DEPT        |     1 |       |     0   (0)| 00:00:01 |
    |   7 |   TABLE ACCESS BY INDEX ROWID   | EMP            |     5 |   185 |     1   (0)| 00:00:01 |
    |*  8 |    INDEX RANGE SCAN             | IDX_EMP_DEPTNO |     5 |       |     0   (0)| 00:00:01 |
    SQL> disconnect
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL>
    can it, in it's WHERE clause, reference other tables in the FROM clause?No. it cannot. but as said above, tha may not stop Oracle from merging the queries.
    SQL> select *
      2          from scott.emp e,
      3                  (select * from scott.dept d where d.deptno = 10 and e.sal > 1000) dd
      4  where
      5          e.deptno = dd.deptno
      6  /
                    (select * from scott.dept d where d.deptno = 10 and e.sal > 1000) dd
    ERROR at line 3:
    ORA-00904: "E"."SAL": invalid identifier
    SQL>

Maybe you are looking for

  • JDBC runtime error using data source (Oracle 9i server & Oracle 8i client)

    Hi, Wud someone help me with this? Why am I getting this run-time error? D:\shilpa\javaprogs>java -classpath %classpath%;.; CreateMovieTables javax.naming.NoInitialContextException: Need to specify class name in environmen t or system property, or as

  • Numeric value to letter grade equivalent?

    What formula would I enter if I wanted to convert a numeric value (summation or average) into a letter grade? For example, I would like to create a formula that would look at a numeric value, determine its range, and then assign a simple letter grade

  • Question about changing method signature

    Hello. I've inherited some code which contains a method with the following signature: foo(int x, MyObject myObject) Okay, so that's not really the exact signature :) In any case, I need to modify the signature to: foo(int x, Object myObject) I believ

  • HT2731 How do I create a password before i purchase songs or books?

    When I purchase songs or books it automatically charges my acct.  I would like to use my password first.  How do I set that up?

  • Capacity planning in ASCP

    Hi, Does anyone know how ascp plan calculates "Daily Hours","Touch Time" and "Adjusted Resource Hours" in horizontal plan for a resource? Looks like plan used below logic to calculate resource hours. (usage rate of a resource in Minutes/60) * Schedul