Update statement in FORALL

Hi Guys,
I've been staring at this and can't figure it out: If I try to compile this code:
CREATE OR REPLACE PROCEDURE equalElements IS
type TLTopoTable is table of BOUWWERK_WSP%ROWTYPE;
LTopoTable TLTopoTable;
type TLNENTable is table of IMPORT_TABEL%ROWTYPE;
LNENTable TLNENTable;
i NUMBER;
BEGIN
select b.* BULK COLLECT INTO LTopoTable from BOUWWERK_WSP b, IMPORT_TABEL a where
MDSYS.SDO_RELATE(b.lijn_coord, a.lijn_coord, 'mask=equal') = 'TRUE';
FORALL i IN LTopoTable.FIRST..LTopoTable.LAST
update LTopoTable set NENSTATUS = 0;
END;
Oracle keeps telling me that
SQL> show errors;
Errors for PROCEDURE EQUALELEMENTS:
LINE/COL ERROR
20/5 PL/SQL: SQL Statement ignored
20/12 PL/SQL: ORA-00942: table or view does not exist
SQL>
and it points at the update LTopoTable statement. I'm sure it's something obvious that's staring me in the face but I can't see it. According to all the docs and examples I can find this should work ...
TIA,
Stefan

As far as i can see the OP is trying to update a user defined Type and not a database table. Or am i missing something ?
Also why do you need a bulk collect when you can do it in a single sql statement something like
Update (query) set <conditions>. This will work only when you have key preserved conditions. For further details check the following link
http://asktom.oracle.com/pls/asktom/f?p=100:11:1001001121993988::::P11_QUESTION_ID:273215737113
Regards
Raj
Message was edited by: Raj
s.rajaram

Similar Messages

  • Optimize single update statement

    Hi all, I've got a table with about 50 millions of rows (a spatial network...) and I have to issue an update statement without any where condition.
    The statement is: UPDATE NODE SET ACTIVE='Y';
    Which is the most efficient way to do this?
    A single UPDATE statement, the forall loop or an incremental FOR loop with partial commit (each 1000 rows i.e.)?
    Thanks
    Lorenzo

    Or a single MERGE statement.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6407993912330#57387981485901
    You'd test with a subset before to see what performs fastest, ofcourse...

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

  • Forall in update statement

    Hi
    I have this procedure in may oracle 9.2. but it show me this error message in the forall statement.-
    Error: PLS-00382: wrong type in expression.
    why ???
    ==============================0
    PROCEDURE pr_com_upd_prim_carg
    -- MODIFICATION HISTORY
    -- Person Date Comments
    -- diazh 22/09/06
    v_mon_carg cargas_credito.mon_carg%TYPE;
    v_fec_carg cargas_credito.fec_carg%TYPE;
    v_num_line tmp_comi_liq.num_line%TYPE;
    v_num_cont tmp_comi_liq.num_cont%TYPE;
    v_cant_cuotas_perc comi_def_linea.cant_cuotas_perc%TYPE;
    v_existe VARCHAR2 (1);
    -- Declare program variables as shown above
    CURSOR c_recarg
    IS
    SELECT --dl.num_line, dl.num_cont, dl.cant_cuotas_perc
    FROM comi_def_linea dl
    WHERE dl.cod_estado = 'APROB' AND dl.cod_clco = 'PREPA' AND dl.fec_prim_carga IS NULL;
    type t_recarg is table of comi_def_linea%rowtype index by binary_integer;
    v_recarg t_recarg;
    BEGIN
    p_usuario := p_user;
    p_periodo := TO_CHAR (p_fec_ini, 'YYYYMM');
    pr_inserta_ctrl (3, 'PR_COM_UPD_PRIM_CARG');
    printlg ('PR_COM_UPD_PRIM_CARG... Iniciado ', v_logfile);
    printlg ('PR_COM_UPD_PRIM_CARG... Iniciado conteo de registros en cargas_credito ',
    v_logfile);
    BEGIN
    SELECT DISTINCT '1'
    INTO v_existe
    FROM cargas_credito
    WHERE fec_carg > (p_fec_ini - (1 / (3600 * 24))) AND fec_carg < (p_fec_fin + 1);
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    WHEN OTHERS
    THEN
    printlg ('PR_COM_UPD_PRIM_CARG(1): Error ' || SQLERRM, v_logfile);
    END;
    printlg ('PR_COM_UPD_PRIM_CARG... Finalizado conteo de registros en cargas_credito ',
    v_logfile
    OPEN c_recarg;
    loop
    FETCH c_recarg
    bulk collect into v_recarg limit 500;
    exit when c_recarg%notfound;
    for i in v_recarg.first .. v_recarg.last loop
    IF v_recarg(i).cant_cuotas_perc = 0
    THEN
    pr_retorna_prim_carga (v_recarg(i).num_line, v_recarg(i).num_cont, v_existe/*esta es una variable cualquiera*/, v_recag(i).fec_prim_carga, v_recarg(i).mto_prim_carga);
    END IF;
    end loop;
    forall i in v_recarg.first .. v_recarg.last
    update comi_def_linea
    SET fec_prim_carga = v_recarg(i),
    mto_prim_carga = v_recarg(i)
    WHERE num_line = v_recarg(i) AND num_cont = v_recarg(i);
    v_recarg.delete;
    END LOOP;
    CLOSE c_recarg;
    COMMIT;
    EXCEPTION
    WHEN OTHERS
    THEN
    printlg ( 'PR_COM_UPD_PRIM_CARG(3): Error '
    || SQLERRM
    || ' '
    || 'procesando linea '
    || v_num_line
    || '-'
    || v_num_cont,
    v_logfile
    END; -- PR_COM_UPD_PRIM_CARG

    The type is a row type so for update statement you have to refer to column.
    v_recar(i).num_cont.
    pl/sql table type(i).columname That wouldn't work either (at least in 9iR2):
    DECLARE
       TYPE emp_type IS TABLE OF emp%ROWTYPE
          INDEX BY BINARY_INTEGER;
       emp_tab   emp_type;
    BEGIN
       FORALL i IN 1 .. emp_tab.LAST
          UPDATE emp
             SET sal = emp_tab (i).sal
           WHERE empno = emp_tab (i).empno;
    END;
    Error at line 4
    ORA-06550: line 9, column 20:
    PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
    ORA-06550: line 9, column 20:
    PLS-00382: expression is of wrong type
    ORA-06550: line 10, column 22:
    PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
    ORA-06550: line 10, column 22:
    PLS-00382: expression is of wrong type
    ORA-06550: line 9, column 20:
    PL/SQL: ORA-22806: not an object or REF
    ORA-06550: line 8, column 7:
    PL/SQL: SQL StatemenMessage was edited by:
    michaels

  • Update statement cascade

    How can I easily update foreignkeys ?
    When I 'm trying to update some keys in table a for example, I get the foreignkey error (ORA-02292: integrity constraint ).
    Is there a way to create a procedure to do this?
    tnx in advance

    A: update statement cascade

    An example of update cascade trigger.
    Original is written in Japanese language (OTN Japan)
    http://otn.oracle.co.jp/forum/thread.jspa?threadID=35000705&tstart=0
    Example of questions (Homework?):
    create table dept2 as select * from scott.dept;
    alter table dept2 add (constraint pk_dept2 primary key (deptno));
    create table emp2 as select * from scott.emp;
    alter table emp2
      add (constraint pk_emp2 primary key (empno));
    alter table emp2
      add (constraint fk_emp2_dept2 foreign key (deptno)
                references dept2(deptno) on delete cascade);
    insert into emp2(empno,ename,deptno) values (9999,'NO DEPTNO',null);I have two tables above defined and added one data.
    I want to update emp2.deptno automatically on updating dept2.deptno.
    For example, on updating with 'update dept2 set deptno=35 where deptno=30',
    I want to update only following 6 rows, but don't want to update the row on empno=9999,deptno is null.
    SQL> select deptno,empno,ename from emp2 where deptno=30;
        DEPTNO      EMPNO ENAME
            30       7499 ALLEN
            30       7521 WARD
            30       7654 MARTIN
            30       7698 BLAKE
            30       7844 TURNER
            30       7900 JAMES
    6 rows selected.Additionally, I want to accomplish it on whether deferrable or not.
    Answer Example:
    create or replace
    package emp2_pack
    is
      type type_table_emp is table of emp2.empno%type index by binary_integer;
      upd_value type_table_emp;
    end;
    create or replace
    trigger trg_dept2_before_upd
    before update of deptno on dept2
    for each row
    begin
      update emp2 e
         set deptno = null
        where e.deptno = :old.deptno
      returning empno
      bulk collect into emp2_pack.upd_value;
    end;
    create or replace
    trigger trg_dept2_after_upd
    after update of deptno on dept2
    for each row
    begin
      forall p_empno in emp2_pack.upd_value.first..emp2_pack.upd_value.last
         update emp2 e set e.deptno = :new.deptno
          wher... [Show more]

    Read other 3 answers

  • How to tune the Update statement for 20 million rows

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

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

  • Decode function in Update statement

    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!

    882300 wrote:
    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!If you really really really want to update the entire table, the syntax would be...
    UPDATE book_trans
       SET
          pastdue_fees  = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);I took out all the single quotes. If you actually have a string column and you're storing entirely numbers in it then it should be declared as a NUMBER column and not a character (varchar2) column.
    ALWAYS use the proper data type, it'll save you a ton of headaches in the future.
    Also, since you're new to the forum, please read the FAQ so you learn the etiquette and what not.
    http://wikis.sun.com/display/Forums/Forums+FAQ

  • Unable to execute an update statement using CallableStatement

    Hi there,
    I'm trying to run an update statement from JUnit using java.sql.CallableStatement and oracle.jbo.server.DBTransaction.
            String updateSql =
                "update footable set barcol=TO_DATE('12-SEP-09','dd-MM-yy') where bazcol = 505";
            try {
                statement =
                        applnModule.getDBTransaction().createCallableStatement(updateSql,
                                                                               2);
                int executeUpdate = statement.executeUpdate();
                AppsLogger.write(this,
                                 "# records UPDATED ------------------>" + executeUpdate,
                                 AppsLogger.SEVERE);
            } catch (SQLException s) {
                s.printStackTrace();
                Assert.fail("Encountered SQL Exception: " + s);
            } finally {
                try {
                    if (statement != null)
                        statement.close();
                } catch (SQLException s) {
            }Below is the exception I get when I run the above code. There is no problem with the SQL - it works fine from SQLDeveloper.
    java.lang.AssertionError: Encountered SQL Exception: java.sql.SQLDataException: ORA-01858: a non-numeric character was found where a numeric was expected
         org.junit.Assert.fail(Assert.java:91)
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:597)
         org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
         org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:105)
         org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86)
         org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)
         org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
         org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
         oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.invokeTestMethod(AtfJUnit4JTestCaseClassRunner.java:362)
         oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.runMethods(AtfJUnit4JTestCaseClassRunner.java:272)
         oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner$1.run(AtfJUnit4JTestCaseClassRunner.java:265)
         org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
         org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
         oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.run(AtfJUnit4JTestCaseClassRunner.java:262)Edited by: 911023 on Oct 2, 2012 11:28 AM
    Edited by: 911023 on Oct 2, 2012 11:30 AM

    Using case statement.
    UPDATE gor_gold_post
       SET hoov_flag = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 304
                                   OR
                                   (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
                                AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
                           THEN 1
                           ELSE 99
                         END,
           b49n      = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 121.6
                             OR
                             (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
                                AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
                           THEN 1
                           ELSE 99
                         END
    WHERE tariff_code IN (169, 135, 136);Note: Code not tested.

  • Is their any limit on the number of column updates in a update statement!

    Hello All,
    Is their any limit on the number of columns to set in a single update statement.+
    am using oracle 11g .
    example :-
    UPDATE FMLY SET as_comp1 = v_as_comp1 , as_comp2 = v_as_comp2, as_comp3 = v_as_comp3, as_comp4 = v_as_comp4 , as_comp5 = v_as_comp5 ,      perslt18 = v_perslt18 , persot64  = v_persot64  , fam_size = v_fam_size , numchild = total_children , C_AGE1 = v_c_age1,  C_AGE2 = v_c_age2,  C_AGE3 = v_c_age3,  C_AGE4 = v_c_age4 WHERE FAMID = fmly_famid(i) ;
    and also is it good practice to issue single update or multiple updates ?
    example for the above update i can have multiple statements like .. does the performance matters if so which is good
    UPDATE FMLY SET as_comp1 = v_as_comp1 , as_comp2 = v_as_comp2, as_comp3 = v_as_comp3, as_comp4 = v_as_comp4 , as_comp5 = v_as_comp5
    WHERE FAMID = fmly_famid(i) ;
    UPDATE FMLY SET perslt18 = v_perslt18 , persot64 = v_persot64 , fam_size = v_fam_size
    WHERE FAMID = fmly_famid(i) ;
    UPDATE FMLY SET numchild = total_children WHERE FAMID = fmly_famid(i) ;
    UPDATE FMLY SET C_AGE1 = v_c_age1, C_AGE2 = v_c_age2, C_AGE3 = v_c_age3, C_AGE4 = v_c_age4 WHERE FAMID = fmly_famid(i) ;
    thanks/kumar
    Edited by: kumar73 on Sep 25, 2010 8:38 AM

    If you can do it in a single SQL statement then you should do that.
    Here's a mantra that I found to work out pretty good:
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:73891904732164

  • Error while schedulingg update stat in db13

    Dear Experts,
    Please look into my issue we are facing an error while scheduling update statistics in db13 and I tried to open detailed log
    It is given
    SXPG_COMMAND_EXECUTE failed for BRTOOLS - Reason: program_start_error: For More Information, See SYS
    Please help me how to solve this my error
    Regards

    Hi,
    Check the owner for BRBACKUP, BRARCHIVE, and BRCONNECT in kernel,
    these files should be with SIDADM, if not change the owner to SIDADM and rerun the update stats.
    and also Refer the note 446172
    Regards,
    Ram

  • How do I pass multiple values from a text box to an update statement

    I hope this does not sound to lame. I am trying to update multiple values Like this:
    Code|| Computer Desc || Computer Price || Computer Name
    SEL1 || Apple macbook || 1564 || Apple Macbook Basic
    SEL2 || Dell 630 || 1470 || Dell Latitude
    I want to change all six values at once in one update statement based on the Code, I can't find a good tutorial/example to help me.
    Can anyone point me in the right direction?
    Thanks so much,
    Laura

    You can do conditional updates with decode or case statements e.g.
    SQL> create table t as
      2  select 'SEL1' as code, 'Apple macbook' as comp_desc, 1564 as comp_price, 'Apple Maxbook Basic' as comp_name from dual union
      3  select 'SEL2', 'Dell 630', 1470, 'Dell Latitude' from dual
      4  /
    Table created.
    SQL>
    SQL> update t
      2  set comp_desc = CASE code WHEN 'SEL1' THEN 'Test1' Else 'Test2' END,
      3      comp_price = CASE code WHEN 'SEL1' THEN 1234 Else 2345 END,
      4      comp_name = CASE code WHEN 'SEL1' THEN 'Test1 Name' Else 'Test2 Name' END
      5  /
    2 rows updated.
    SQL>
    SQL> select * from t
      2  /
    CODE COMP_DESC     COMP_PRICE COMP_NAME
    SEL1 Test1               1234 Test1 Name
    SEL2 Test2               2345 Test2 Name
    SQL>

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

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

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

  • Running an update statement on two dependent attributes

    Dear All,
    I have a repair_job table that contains values for work_cost, parts_cost and total_cost which is the sum of the work and parts cost values. I want to run an update statement that doubles the work cost and, naturally, updates the value of total cost as well. I tried to run it as:
    update repair_job
    set work_cost = 2 * work_cost, total_cost = work_cost + parts_cost
    where licence in (
    select licence from car
    where year = to_char(sysdate,'YYYY')
    thinking that because the update of work_cost is first on the list, the updated value of total cost would be correct. It seems however that the update of total cost happens first and then the work cost is been updated; not sure what the reason is for that and it happens no matter what the order is in the update statement.
    I know that I can do it in two separate statements, or use a trigger or PL/SQL to do it but I am curious as to why it has this behaviour. Also, is there a way to do it in a single SQL statement - i.e. forcing the update of the work_cost attribute first and then that of total_cost?
    I look forward to hearing from you soon.
    Regards,
    George

    Welcome to the forum!
    >
    thinking that because the update of work_cost is first on the list, the updated value of total cost would be correct. It seems however that the update of total cost happens first and then the work cost is been updated; not sure what the reason is for that and it happens no matter what the order is in the update statement.
    I know that I can do it in two separate statements, or use a trigger or PL/SQL to do it but I am curious as to why it has this behaviour. Also, is there a way to do it in a single SQL statement - i.e. forcing the update of the work_cost attribute first and then that of total_cost?
    >
    The update to all columns of the row happen at the same time - there is no order involved.
    You don't need two statements but you do need to do the updates based on the current value of the columns.
    set work_cost = 2 * work_cost, total_cost = 2 * work_cost + parts_cost----------
    In addition to sb92075's comments in 11 g you could also just define a virtual column for total_cost and then just query it like you do now.
    total_cost   NUMBER GENERATED ALWAYS AS (work_cost + parts_cost) VIRTUAL,See this Oracle-base article for an example
    http://www.oracle-base.com/articles/11g/virtual-columns-11gr1.php
    Edited to supplement sb92075's reply by mentioning virtual columns

  • How can i use multiple row subquery in update statement

    Hai All
    I using group function in my update statement.. and i need to update more rows so i need to use multiple row
    subquery pls tell me how to use multiple row subquery in update statement
    For example
    while i am using this like this i got an error
    update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
    barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
    Pls tell me how to use with example
    Thanks & regards
    Srikkanth.M

    Hai Man
    Thanks for ur response Let me clear what i need
    First step Fetch the records as text file and stores into table T1
    and the next step is i have seperated the text using substring and stores in different columns of a table
    There are two shifts 0815 to 1645 and 1200 and 2000
    Here I rep IN and O rep OUT
    Empno date time inout
    001 01-01-10 0815 I
    002 01-01-10 0815 I
    003 01-01-10 0818 I
    001 01-01-10 1100 0
    001 01-01-10 1130 I
    002 01-01-10 1145 0
    002 01-01-10 1215 I
    004 01-01-10 1200 I
    005 01-01-10 1215 I
    004 01-01-10 1315 O
    004 01-01-10 1345 I
    001 01-01-10 1645 0
    002 01-01-10 1715 0
    003 01-01-10 1718 0
    004 01-01-10 2010 0
    005 01-01-10 2015 0
    This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
    T2 contains like this
    Empno Intime Intrin Introut Outtime Date
    001 0815 1100 1130 1645 01-01-10
    002 0815 1145 1215 1715 01-01-10
    003 0818 1718 01-01-10
    004 1200 1315 1345 2010 01-01-10
    005 1215 2015 01-01-10
    This what i am trying to do man but i have little bit problems Pls give some solution with good example
    And my coding is
    declare
         emp_code varchar2(25);
    in_time varchar2(25);
    out_time varchar2(25);
    Cursor P1 is
    Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    From temp_att
    group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    ORDER BY enpno,pdate,ptime;
    begin
         for r2 in p1 loop
    declare
    bar_code varchar2(25);
    begin
    select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
    For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
    if r2.inout ='O' then
    update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
    end if;
    end loop;     
    exception
         when no_data_found then
         if r2.inout ='I' then
                   insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
         end if;
    end;
    end loop;
    commit;     
         end;
    Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
    and how can i use it in the update statement
    Thanks In Advance
    Srikkanth.M

  • How to use the updated value in the same update statement

    Hello,
    I just wonder how to use the updated new value of other column in the same udpate statement. I am using Oracle 11.2, and want to update the two columns with one update statement as following:
    create table tb_test (id number(5), tot number(5), mon_tot number(5));
    update tb_test set (tot = 15, mon_tot = tot *15) where id = 1;
    ...I would like to update both tot and mon_tot column, the value of mon_tot shall be determinted by the new value of tot.
    Thanks,
    Edited by: 939569 on 1-Feb-2013 7:00 AM

    Edit: example added
    SQL> create table tb_test
      2  ( id number(5)
      3  , tot number(5)
      4  , mon_tot number generated always as (tot*15) virtual
      5  );
    Table created.
    SQL> insert into tb_test (id, tot) values (1, 5);
    1 row created.
    SQL> select * from tb_test;
            ID        TOT    MON_TOT
             1          5         75
    1 row selected.
    SQL> update tb_test
      2  set    tot = 15
      3  where  id = 1;
    1 row updated.
    SQL> select * from tb_test;
            ID        TOT    MON_TOT
             1         15        225
    1 row selected.

Maybe you are looking for

  • I REALLY need help W/ my New Ip 4. Music Note Link, takes me right to the store, and keeps telling me, all my music has been downloaded, but I can't find it anywhere.... HELP!!!

    I upgraded my Original Iphone to an Iphone 4, and am having issues syncing my Music, It asked me, if I wanted to set up my phone as a NEW Iphone, or use the last sync. I figured, using the last sync would simply move everything over. NOT, so much. I

  • Long text not apearing on contract

    Hi SAP Gurus, Can anybody please help me with this scenario. The long text appears on the PO but does not appear on contract. When i say long text it refers to the Basic text in the additional data part of the Basic data tab. Whatever text we maintai

  • Thread view: could the Legend be moved up?

    When viewing a thread, there is a significant amount of empty space on the right. This is due to the Legend occupying a full column alongside all posts, even though the Legend is probably shorter than the first post alone. A lot of the posts here con

  • Cannot Save or Print

    I have a 2008 white macbook running Mac OSX 10.6.8. The computer had been working relatively well until this week. I am all of a sudden unable to save a document in any program. The programs crash when trying to save. I also cannot print anymore. Whe

  • Can't go to next song usgin the wheel?

    Hi: I just bought a new Nano yesterday. For some reason when I click on the right side of the wheel it goes back to the beginning of the song, same thing when I click left. I can only get to another song with "Shake to shuffle" or via Cover Flow. Is