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;

Similar Messages

  • Using Hint in Update or Select Statement...

    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

    The better approach would be to determine why you need a hint in the first place. If you're using a hint, that implies that the optimizer is choosing the incorrect plan when left to its own devices. That, in turn, implies that the statistics on your objects, the statistics on your system, your optimizer parameters, your session's optimizer settings or some other variable is incorrect. You're generally better off fixing the root problem than hinting every query.
    In this specific case, the parallel hint is invalid because there is no table aliased A. The full hint is invalid for similar reasons. Plus, with the query you provided, if A was intended to be the SALARY table, it seems exceptionally unlikely that you really want to do a full scan on the salary table to look for what had better be a single row (otherwise your query would throw a "too many rows returned" exception).
    Justin

  • Use of the "updlock" hint with update and insert statements

    I have inherited some stored procedures and am trying to figure out why the developers decided to use the "updlock" hint on many of the update and insert statements. I have looked around everywhere and have found only one explanation of why "update...with
    (updlock)" can be useful, namely when a table has no clustered index:
    http://www.sqlnotes.info/2012/10/10/update-with-updlock/ I have found nothing yet that mentions why "insert into...with (updlock)" might be used. I understand why the hint
    might be useful on select statements in some cases, but if all of the tables have clustered indexes, is there any good reason to use it on update and insert statements?
    Thanks,
    Ron
    Ron Rice

    This form of deadlock error can occur on a table which has a clustered index.
    If you are doing updates on a table which has a clustered index and that table also has a nonclustered index and the nonclustered index is used to find the row to update you can see this type of deadlock.  For example create a table with a clustered
    primary key index and a nonclustered index by running
    Create Table Foo(PK int primary key identity, OtherKey varchar(10), OtherData int);
    go
    Insert Foo Default Values;
    go 10000
    Update Foo Set OtherKey = 'C' + Cast(PK As varchar(10))
    Create Unique Index FooIdx On Foo(OtherKey);
    That creates a table with 10000 rows, a clustered index and a nonclustered index.  Then run
    Begin Transaction
    Update Foo Set OtherData = 1 Where OtherKey = 'C5'
    That will use the FooIdx index to find the row that needs to be updated.  It will get a U lock on the index row in the FooIdx index, then an X lock on the row in the clustered index, update that row, then free the U lock on FooIdx, but keep the X lock
    on the row in the clustered index.  (There is other locking going on, but to simplify things, I'm only showing the locks that lead to the deadlock).
    Then in another window, run
    Begin Transaction
    Update Foo Set OtherData = 2 Where OtherKey = 'C5'
    This will get a U lock on the index row in the FooIdx index, then try to get an X lock on the row in the clustered index.  But that row is already exclusively locked, so this second window will wait holding a U lock on FooIdx row and is waiting for
    an X lock on the clustered index row.
    Now go back to the first window and run
    Update Foo Set OtherData = 3 Where OtherKey = 'C5'
    This will once again try to get the U lock on the FooIdx row, but it is blocked by the U lock the second window holds.  Of course the second window is blocked by the X lock on the clustered index row and you have a deadlock.
    All that said, I certainly do not routinely code my updates with UPDLOCK.  I try to design databases and write code so that deadlocks will be rare without holding excessive locks.  The more locks you hold and the longer you hold them, the more
    blocking you will get and the slower your system will run.  So I write code that if a deadlock exception occurs, it is properly handled.  Then if too many deadlocks occur, that is the time to go back to the code to see what changes are needed to
    decrease the number of deadlocks (one way to do that may be to get locks earlier and/or hold them longer. 
    But I wouldn't worry much about this form of deadlock.  It is, in my experience, vary rare.  I don't recall ever seeing it in a production environment.
    Tom

  • For update in select statement

    i have a table which store data in a clob. sometimes user forget to add and extra carriage return after last line. so i am doing the following to modify the clob
    SELECT file_content INTO lv_lob FROM files WHERE id = p__id FOR UPDATE;
    dbms_lob.writeappend(lv_lob,2,C_NEW_LINE);
    C_NEW_LINE CONSTANT VARCHAR2(2) := Chr(13)||Chr(10);
    'for update' should only lock that specific row since id is a pk key in the table.
    i have two front end screen where people upload file. a unique id is generated for each file and the data with id inserted in the table. user can upload file from the two different screen at same time.
    the problem is that i am getting a 'resource busy and acquire with NOWAIT specified' error. i don't know why if every file i upload belongs to different row.
    anybody knows why i would get this error and how can i solve it?

    How are you generating the unique ID? Are you using a sequence? Or are you using something that forces serialization?
    Where in the program flow are you adding the extra carriage return?
    Is it this SELECT statement that is throwing the error? Or is it being thrown somewhere else?
    Justin

  • Update From Select statement

    I'm very new to Oracle so please bear with me.
    I need to Update a table ( T1) with dates selected from another table (T2). However, because of the size of the tables (the second one has upwards of 3,000,000 rows) I have to do it incrementally, say 10k rows at a time. However, there's no field in T1 that I can use as a flag to say the row's been updated. But I do have an ascending numeric field that I can do a Max() function on. My thought was to capture the max numeric function in local variable and use it in a where clause so I only get the rows I need to update. Pseudo-ish code follows:
    DECLARE
    mDoc NUMBER
    maxNum NUMBER
    BEGIN
    mDoc = 0;
    SELECT MAX(doc_id_n) INTO maxNum FROM T2;
    WHILE NOT mDoc > maxNum
    LOOP
    SELECT MAX(doc_id_n) INTO mDoc FROM T2
    WHERE doc_id_n > mDoc AND rownum < 10001;
    UPDATE T1 SET scan_d =
    (select to_date(t.ddate,'MM/DD/YYYY') as ndate
    from T2 t, T1 i
    where i.stor_rep_id = 'HRPAYROLL1' and
    t.doc_id_n = i.doc_id_n and rownum < 10001
    AND NOT t.doc_id_n > mDoc
    ORDER BY t.doc_id_n)
    END LOOP;
    END;

    You say:
    <However, there's no field in T1 that I can use as a flag to say the row's been updated.
    That's fine, you needn't nor might you want to do this incrementally. Instead, what basis or values in table(T1) are you using to determine which rows are updated? For example, you might want to use a particular field as your 'filter' between the two tables. Still it's not fun :)
    UPDATE T1 SET date_column = (SELECT inserted_date FROM T2 WHERE customer = 'ABC')
    WHERE customer = 'ABC';
    UPDATE T1 SET date_column = (SELECT inserted_date FROM T2 WHERE customer = 'XYZ')
    WHERE customer = 'XYZ';
    Hope this helps.

  • Please send me select statement for the below query.....

    FOR i IN 1..9 LOOP
    IF shift(i) IS NULL THEN
    FOR y IN i+1..9 LOOP
    IF shift(y) IS NOT NULL THEN
    shift(i) := shift(y);
    shift(y) := NULL;
    EXIT;
    END IF;
    END LOOP;
    END IF;
    END LOOP;
    please how to write select query to replace loops in above code

    CREATE or REPLACE function MyFun(
    code_1 IN VARCHAR2,
    code_2 IN VARCHAR2,
    code_3 IN VARCHAR2
    )RETURN INTEGER IS
    out_param INTEGER:=0;
    TYPE t_cos IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
    shift t_cos;
    i NUMBER;
    y NUMBER;
    BEGIN
    shift(1) := TRIM(code_1);
    shift(2) := TRIM(code_2);
    shift(3) := TRIM(code_3);
    FOR i IN 1..3 LOOP
    IF shift(i) IS NULL THEN
    FOR y IN i+1..3 LOOP
    IF shift(y) IS NOT NULL THEN
    shift(i) := shift(y);
    shift(y) := NULL;
    EXIT;
    END IF;
    END LOOP;
    END IF;
    END LOOP;
    For i IN 1..3 Loop
    IF substr(shift(i),1,1) = 'E' THEN
    out_param := shift(i);
    EXIT;
    ELSE
    out_param := NULL;
    END IF;
    END LOOP;
    out_param := 1;
    RETURN (out_param);
    END;
    For Ex we have 100 recors this loops i.e For loops executes more than 100 times we need to avoid this thing and replace for loop's and write select stmt on this.
    Edited by: 867554 on Jun 22, 2011 6:31 AM

  • Combine two select statements in one SQL statements

    I have the following two queries that I need to combine into one query, where it updates a single row at the same time.
    SELECT count(*) FROM database.USAGE WHERE SERVICE_TYPE = 'C' AND ACCOUNT = "4837"
    SELECT sum(minutes) FROM database.USAGE WHERE SERVICE_TYPE = 'DA' AND ACCOUNT = "4837"
    I want to insert the values of each select statement into two columns of the same row, as well as insert the account number from the select statement.
    After the query has been executed, the database row will look like this:
    ACCOUNT COUNT SUM
    4837 354 1039202
    I am looking for suggestions on how to:
    - either combine the two into one query
    - simply update each column with the value from each query by updating the row with the account value
    I am a SQL newbie - so I appreciate any assistance.
    Thanks,
    Tony

    Hi, Tony,
    When you're talking about changing the data in tables, "INSERT" means to add a new row, and you'll cause a lot of confusion if you use it to mean something else. So don't say
    "I want to insert the values of each select statement into two columns..."; use some other word, like:
    "I want to put the values of each select statement into two columns ..."
    If you happened to know that those two numbers were 354 and 1039202, you might say:
    UPDATE  table_x
    SET     a_count = 354
    ,       a_sum = 1039202
    WHERE   account = 4837;But you don't know the numbers; you want to have the query figure out what they are.
    In most places where you can use a literal (like 354 or 1039202), you can also use a scalar sub-query, a SELECT statement, enclosed in parentheses, that produces one column and (at most) one row.
    In your case, you can say:
    UPDATE  table_x
    SET     a_count = (SELECT count(*) FROM database.USAGE WHERE SERVICE_TYPE = 'C' AND ACCOUNT = 4837)
    ,       a_sum = (SELECT sum(minutes) FROM database.USAGE WHERE SERVICE_TYPE = 'DA' AND ACCOUNT = 4837
    WHERE   account = 4837;or, to make it more readable:
    UPDATE  table_x
    SET     a_count =
    ( SELECT count (*)
    FROM database.USAGE
    WHERE SERVICE_TYPE = 'C'
    AND ACCOUNT = 4837
    ,       a_sum =
    ( SELECT sum (minutes)
    FROM database.USAGE
    WHERE SERVICE_TYPE = 'DA'
    AND ACCOUNT = 4837
    WHERE   account = 4837;By the way, why are you using double-quotes around 4837? If it's a string, enclose it in single quotes. If it's a number (which I'm assuming in my code), don't enclose it in anything.
    WARNING: scalar sub-queries are somewhat like duct tape: they're extremely useful in certain places, and those places account for about 1% of their use. The other 99% of the time, there's a better way to do things, though the better way may require more expertise.

  • DOCUMENTING SELECT STATEMENT

    Hi All,
    I been working with databases (ORACLE, MSSQLSERVER, SQLANYWARE) for last couple of years. SELECT statement comes into picture very frequently.
    But yet I am unable to find any template, tool or hint to document the SELECT statement, so that other developers can understand its flow and relationships among source files. Every time a source given to developer (other than who actually write it) with SELECT statement, it takes long time to understand.
    Any hint/help would be highly appreciated.
    Regards.

    For 90-some percent of the SQL statements you're likely to come across, this would seem to be an issue of developer training rather than of documentation. If your developers are accostomed to thinking in terms of set-based processing rather than procedural-based programming, the structure of a SQL statement ought to be rather self-explanatory. If there are a lot of DECODE statements or the SQL statement is doing something unusual, putting an explanatory comment nearby might be helpful.
    Of course, this assumes that the developers are reasonably familiar with the data model of the underlying tables. If not, make sure they have the necessary ERD(s) and other documentation.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • Combine select and update into single statement,without bind-variable

    I have a problem, that I think is not possible to solve the way I want to, but I just wanted to check before leaving the idea...
    I am looking for a way to combine the select and the update statement into one single statement. This is what I wan't to achive: select some data, and update the data selected before returning them.
    On this site http://www.psoug.org/reference/update.html I see that the following are possible:
    var bnd1 NUMBER
    var bnd2 VARCHAR2(30)
    var bnd3 NUMBER
    UPDATE employees
    SET job_id ='SA_MAN', salary = salary + 1000,
    department_id = 140
    WHERE last_name = 'Jones'
    RETURNING salary*0.25, last_name, department_id
    INTO :bnd1, :bnd2, :bnd3;
    I need to have this as a single statement, and cannot use bind-variables. So I was hoping that something like this could be possible:
    UPDATE customer c
    SET c.HAS_CREDIT ='1'
    WHERE c.HAS_CREDIT = '0'
    RETURNING c.CUSTOMER_NO, c.FIRSTNAME, c.LASTNAME
    where c.HAS_CREDIT = '1'
    But this doesn't compile, complaining of missing into (ORA-00925: missing INTO keyword). And even though I would like this to be possible because this would solve my current problem, I think it would be very confusing. For instance; would the where clause of the returning part be operating after the update or before?
    Any comments or suggestions on how to get it work in a single statement, or should I just leave this path straight away?

    Hi,
    RETURNING only works with bind variables, see
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/returninginto_clause.htm#sthref3006
    The real problem is that the form of RETURNING clause with bind variables is only valid for single row update or insert statements.
    To update (or insert) multiple rows and return the data, you will need to use
    RETURNING BULK COLLECT INTO clause. See
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2236
    Cheers,
    Colin

  • Problems with Hints in abap code to use an index in a Select statement

    Hi,
    I want to use an especific index in a select statement but I can´t get it. I use de next statement:
    SELECT ltaklgnum ltaktanum ltakvbeln ltaptapos ltapnltyp ltappvqui
           FROM ltak AS ltak INNER JOIN ltap AS ltap
                            ON  ltaktanum = ltaptanum
                            AND ltaklgnum = ltaplgnum
           INTO TABLE l_t_tanum_silo
           WHERE ltap~lgnum EQ ip_lgnum
             AND ltap~pquit EQ ' '
             AND ltak~lgnum EQ ip_lgnum
             AND ltak~kquit EQ ' '
             AND ltak~queue EQ ip_queue
             %_HINTS DB2 ''.
    We have DB2 for Linux Unix and Windows 9.5 as DB system.
    How can I fix this?
    Thanks a lot.
    Regards

    The DB2 for Linux Unix and Windows is coded DB6 for SAP and not DB2
    Look at the following OSS notes
    - [Note 129385 - Database hints in Open SQL|https://service.sap.com/sap/support/notes/129385]
    - [Note 150037 - Database hints in Open SQL for DB6 (DB2 for LUW)|https://service.sap.com/sap/support/notes/150037]
    - [Note 1270314 - DB6: DB2 9.5 Perf. degrad. for queries with INLIST clause|https://service.sap.com/sap/support/notes/1270314]
    - [Note 868888 - DB6: Optimization Guidelines|https://service.sap.com/sap/support/notes/868888]
    You should use a
    SELECT ltak~lgnum ltak~tanum ltak~vbeln ltap~tapos ltap~nltyp ltap~pvqui
      FROM ltak AS ltak INNER JOIN ltap AS ltap
      ON ltak~tanum = ltap~tanum
        AND ltak~lgnum = ltap~lgnum
      INTO TABLE l_t_tanum_silo
      WHERE ltap~lgnum EQ ip_lgnum
        AND ltap~pquit EQ ' '
        AND ltak~lgnum EQ ip_lgnum
        AND ltak~kquit EQ ' '
        AND ltak~queue EQ ip_queue
      %_HINTS DB6 '<IXSCAN TABLE=''LTAP'' INDEX=''"LTAP~M"'' />'.
    In note 868888 there is a sample for a join.
    SELECT A~TABSPACE
    FROM TADB6 AS A
    JOIN IADB6 AS B ON A~TABART = B~TABART
    %_HINTS DB6 '<NLJOIN><IXSCAN TABLE=''IADB6'' />'
            DB6 '<IXSCAN TABLE=''TADB6'' /></NLJOIN>'.
    Regards

  • Database hints in select statement

    Hi all,
    i need to apply the databaser hints for my select statement where i am using for all entries clause .But the issue is that i am getting the dump when i am tring with the same .
    If i use the hint without all entries clause ,it runs fine.
    The query where  i need to apply the hint is :
      SELECT * FROM bsim                                        "n443935
             INTO CORRESPONDING FIELDS OF TABLE g_t_bsim_lean   "n443935
               FOR ALL ENTRIES IN t_bwkey   WHERE  bwkey = t_bwkey-bwkey
                                            AND    matnr IN matnr
                                            AND    bwtar IN bwtar
                                            AND    budat >= datum-low.
    and the DB hint is:
    Addition of database hints for DB6 as per OSS message 649621
      %_HINTS
      DB6 'USE_OPTLEVEL 7'        " Insert CR-1000000473 Tr-D11K934315
      DB6 '&SUBSTITUTE VALUES&'.
    Let me know whats the issue for the dump in for all entries in clause.

    Did you check if [https://service.sap.com/sap/support/notes/1520152|https://service.sap.com/sap/support/notes/1520152] applies?

  • HINTS in Select Statement

    Hi,
    Can anybody explain me why HITS keyword is used with SELECT statement, whats the use of if, How to find the HINTS for a particular table.
    SELECT recn, recnroot, ippers
    INTO CORRESPONDING FIELDS OF TABLE <ITAB1>
    FROM CCIHT_IP
    FOR ALL ENTRIES IN <ITAB2>
    WHERE ippers = <ITAB2>-ippers
    AND valfr LE sy-datum
    AND valto GE sy-datum
    AND iptype = 'INJ'
    %_hints db2 '&max_blocking_factor 500&&max_in_blocking_factor 500&u2019.
    -Rajiv

    Hi,
    Complex database statements or large numbers of secondary indexes that can be very
    similar make it difficult for the database optimizer and the R/3 database interface to process
    most efficiently. In some database systems, you can expressly influence decisions made by
    database optimizer by what are known as hints.
    Ex- %_HINTS ORACLE '&SUBSTITUTE VALUES&'.
    Search with HINTS in SELECT STATEMENT you will get so many ans

  • TDE Issue with UPDATE/SELECT statement

    We just implemented TDE on a table and now our import script is getting errors. The import script has not changed and has been running fine for over a year. The script failed right after applying TDE on the table.
    Oracle 10g Release 2 on Solaris.
    Here are the encrypted colums:
    COLUMN_NAME ENCRYPTION_ALG SALT
    PERSON_ID AES 192 bits key NO
    PERSON_KEY AES 192 bits key NO
    USERNAME AES 192 bits key NO
    FIRST_NAME AES 192 bits key NO
    MIDDLE_NAME AES 192 bits key NO
    LAST_NAME AES 192 bits key NO
    NICKNAME AES 192 bits key NO
    EMAIL_ADDRESS AES 192 bits key NO
    AKO_EMAIL AES 192 bits key NO
    CREATION_DATE AES 192 bits key NO
    Here is the UPDATE/SELECT statement that is failing:
    UPDATE cslmo_framework.users a
           SET ( person_id
               , username
               , first_name
               , middle_name
               , last_name
               , suffix
               , user_status_seq
             = (
                 SELECT person_id
                      , username
                      , first_name
                      , middle_name
                      , last_name
                      , suffix
                      , user_status_seq
                   FROM cslmo.vw_import_employee i
                  WHERE i.person_key = a.person_key
         WHERE EXISTS
                   SELECT 1
                     FROM cslmo.vw_import_employee i
                    WHERE i.person_key = a.person_key
                      AND (    NVL(a.person_id,0)        <> NVL(i.person_id,0)
                            OR NVL(a.username,' ')       <> NVL(i.username,' ')
                            OR NVL(a.first_name,' ')     <> NVL(i.first_name,' ')
                            OR NVL(a.middle_name,' ')    <> NVL(i.middle_name,' ')
                            OR NVL(a.last_name,' ')      <> NVL(i.last_name,' ')
                            OR NVL(a.suffix,' ')         <> NVL(i.suffix,' ')
                            OR NVL(a.user_status_seq,99) <> NVL(i.user_status_seq,99)
    cslmo@awpswebj-dev> exec cslmo.pkg_acpers_import.p_users
    Error importing USERS table.START p_users UPDATE
    Error Message: ORA-01483: invalid length for DATE or NUMBER bind variableI rewrote the procedure using BULK COLLECT and a FORALL statement and that seems to work fine. Here is the new code:
    declare
       bulk_errors EXCEPTION ;
       PRAGMA EXCEPTION_INIT(bulk_errors,-24381) ;
       l_idx      NUMBER ;
       l_err_msg  VARCHAR2(2000) ;
       l_err_code NUMBER ;
       l_update   NUMBER := 0 ;
       l_count    NUMBER := 0 ;
       TYPE person_key_tt
           IS
               TABLE OF cslmo_framework.users.person_key%TYPE
                    INDEX BY BINARY_INTEGER ;
       arr_person_key   person_key_tt ;
       TYPE person_id_tt
           IS
              TABLE OF cslmo_framework.users.person_id%TYPE
                    INDEX BY BINARY_INTEGER ;
       arr_person_id   person_id_tt ;
       TYPE username_tt
          IS
              TABLE OF cslmo_framework.users.username%TYPE
                   INDEX BY BINARY_INTEGER ;
       arr_username   username_tt ;
       TYPE first_name_tt
          IS
             TABLE OF cslmo_framework.users.first_name%TYPE
                  INDEX BY BINARY_INTEGER ;
       arr_first_name   first_name_tt ;
       TYPE middle_name_tt
         IS
             TABLE OF cslmo_framework.users.middle_name%TYPE
                 INDEX BY BINARY_INTEGER ;
       arr_middle_name   middle_name_tt ;
       TYPE last_name_tt
             IS
                TABLE OF cslmo_framework.users.last_name%TYPE
                     INDEX BY BINARY_INTEGER ;
       arr_last_name   last_name_tt ;
       TYPE suffix_tt
             IS
                TABLE OF cslmo_framework.users.suffix%TYPE
                     INDEX BY BINARY_INTEGER ;
       arr_suffix   suffix_tt ;
       TYPE user_status_seq_tt
             IS
                TABLE OF cslmo_framework.users.user_status_seq%TYPE
                     INDEX BY BINARY_INTEGER ;
       arr_user_status_seq   user_status_seq_tt ;
       CURSOR users_upd IS
          SELECT  i.person_key
                 ,i.person_id
                 ,i.username
                 ,i.first_name
                 ,i.middle_name
                 ,i.last_name
                 ,i.suffix
                 ,i.user_status_seq
          FROM   cslmo.vw_import_employee i ,
                 cslmo_framework.users    u
          WHERE  i.person_key = u.person_key ;
    begin
       OPEN users_upd ;
       LOOP
            FETCH   users_upd
             BULK
          COLLECT
             INTO    arr_person_key
                   , arr_person_id
                   , arr_username
                   , arr_first_name
                   , arr_middle_name
                   , arr_last_name
                   , arr_suffix
                   , arr_user_status_seq
            LIMIT         100 ;
            FORALL idx IN 1 ..  arr_person_key.COUNT
                SAVE EXCEPTIONS
                UPDATE cslmo_framework.users u
                  SET
                       person_id                =   arr_person_id(idx)
                     , username                 =   arr_username(idx)
                     , first_name               =   arr_first_name(idx)
                     , middle_name              =   arr_middle_name(idx)
                     , last_name                =   arr_last_name(idx)
                     , suffix                   =   arr_suffix(idx)
                     , user_status_seq          =   arr_user_status_seq(idx)
                 WHERE u.person_key = arr_person_key(idx)
                 AND
                       ( NVL(u.person_id,0) != NVL(arr_person_id(idx),0)
                 OR
                         NVL(u.username,' ') != NVL(arr_username(idx),' ')
                 OR
                         NVL(u.first_name,' ') != NVL(arr_first_name(idx),' ')
                 OR
                         NVL(u.middle_name, ' ') != NVL(arr_middle_name(idx), ' ')
                 OR
                         NVL(u.last_name,' ') != NVL(arr_last_name(idx),' ')
                 OR
                         NVL(u.suffix,' ') != NVL(arr_suffix(idx),' ')
                 OR
                         NVL(u.user_status_seq,99) != NVL(arr_user_status_seq(idx),99)
          l_count := arr_person_key.COUNT ;
          l_update := l_update + l_count ;
          EXIT WHEN users_upd%NOTFOUND ;
       END LOOP ;
       CLOSE users_upd ;
       COMMIT ;
       dbms_output.put_line('updated records: ' || l_update);
       EXCEPTION
          WHEN bulk_errors THEN
               FOR i IN 1 .. sql%BULK_EXCEPTIONS.COUNT
               LOOP
                  l_err_code   :=   sql%BULK_EXCEPTIONS(i).error_code ;
                  l_err_msg    :=   sqlerrm(-l_err_code) ;
                  l_idx        :=   sql%BULK_EXCEPTIONS(i).error_index;
                  dbms_output.put_line('error code: ' || l_err_code);
                  dbms_output.put_line('error msg: ' || l_err_msg);
                  dbms_output.put_line('at index: ' || l_idx);
               END LOOP ;
               ROLLBACK;
               RAISE;
    end ;
    cslmo@awpswebj-dev> @cslmo_users_update
    updated records: 1274There are about 20 or so other procedure in the import script. I don't want to rewrite them.
    Does anyone know why the UPDATE/SELECT is failing? I checked Metalink and could not find anything about this problem.

    This is now an Oracle bug, #9182070 on Metalink.
    TDE (transparent data encryption) does not work when an update/select statement references a remote database.

  • Update with a select statement

    hi experts,
    I need some help again.. :)
    I have an insert query here with a select statement.. Juz wondering how to do it in update?
    insert into newsmail_recipient
            (IP_RECIPIENTID,NF_LISTID,NF_STATUSID,D_CREATED,D_MODIFIED,C_NAME,C_EMAIL,USER_ID,NEWSMAIL_ID)
            select newsmail_recipientid_seq.nextval
              , liste
              , 1
              , sysdate
              , sysdate
              , null
              , null
              , ru.nf_userid
              , null
            from roleuser ru, unit u, userinfo ui
            where u.ip_unitid = ru.nf_unitid
            and u.ip_unitid = unit_id
            and ui.ip_userid = ru.nf_userid
            and ui.nf_statusid = 1
            and n_internal = 0
            and ui.ip_userid not in (select user_id
                                       from newsmail_recipient
                                      where user_id = ui.ip_userid
                                        and nf_listid = liste
                                        and nf_statusid = 1);let me know your thoughts.
    Regards,
    jp

    Hi,
    924864 wrote:
    ... I have an insert query here with a select statement.. Juz wondering how to do it in update?How to do what, exactly?
    MERGE can UPDATE existing rows, and INSERT new rows at the same time. In a MERGE statement, you give a table or a sub-query in the USING clause, and define how rows from that result set match rows in your destination table. If rows match, then you can UPDATE the matching row with values from the sub-query.
    Very often, MERGE is easier to use, and perhaps more efficient, than UPDATE just for changing existing rows. That is, while MERGE can do both INSERT and UPDATE, it doesn't have to . You can tell MERGE just to do one or the other if you wish.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Since you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Update Statement using SELECT statement

    The following select query return 1 record to me
    [code]
    select  deptno , dname, empno , max_date, max(v_num)
      from (select  d.deptno , d.dname , e.empno ,max (ver_date)  over(partition by d.id ,d.no) max_date  ,v_num
                from  emp e ,dept d
              where  e.deptno=d.deptno and e.dname = d.dname and e.empno=1 and d.deptno =3 )
    group by  deptno , dname, empno , max_date  
    [/code]
    Now I need to update the above value to the emp table itself
    In emp table for the empno=1  I need to update the columns mx_Date and v_num columns with the above last 2 columns in the select statement (max_date, max(v_num) )
    How can I write the update statement for this.
    Thank You

    Something like this
    merge into emp e1
    using (
              select deptno
                   , dname
                   , empno
                   , max_date
                   , max(v_num) v_num
                from (
                       select d.deptno
                            , d.dname
                            , e.empno
                            , max (ver_date)  over(partition by d.id , d.no) max_date 
                            , v_num
                         from emp e
                            , dept d
                        where e.deptno = d.deptno
                          and e.dname  = d.dname
                          and e.empno  = 1
                          and d.deptno = 3
               group
                  by deptno
                   , dname
                   , empno
                   , max_date  
          ) e2
       on (
            e1.empno = e2.empno
    when matched then
        update set e1.mx_date = e2.max_date,
                   e1.v_num   = e2.v_num

Maybe you are looking for

  • Wi-fi: No hardware installed after 10.9.3 update

    After updating to Mavericks 10.9.3 my computer will not connect via wifi. I had to go out and purchase a USB to Ethernet. The bluetooth option definitely works. The wifi option in system preferences won't allow me turn it on. Wi-fi is not an option w

  • Issue in Datasource creation Transaction data

    Hi, While creating the Datasource for the Transaction Data , we have info objects custom defined with length NUMC & length4 , but when in the proposal tab when saying the Load example data the data type and length are changing to INT2 and 5 like wise

  • Automatic PO from PR through ME59N

    Dear All, While converting the PR automatically to PO with ME59N, I am getting message "No suitable PR found". Where as the PR contains the open items and the same PR can be converted in to PO thourgh ME57 (manually). Please suggest me what could be

  • How can I use streamtokenizer to parse out metatag?

    everything is in the title I want to identify the author or the title of anURL how can I do?

  • How can I control the size of the af:InputText?

    Hi, How can I control the size of the 'af:InputText' on the UI, without using columns & rows attributes. Even though I am using width & height attributes, the changes are not getting reflected in the UI. Thanks, Rajesh.