UPDATE statement in procedure

Hi,
I'm having trouble getting my SP to work. I've searched this forum for a similar post, but haven't found it.
Can anyone please let me know what I'm doing wrong here?
Thanks!
CREATE OR REPLACE PROCEDURE updadminproc
(pdate   IN CHANGE_CONTROL_ADMIN.CLOSEDATE%TYPE,
pact   IN CHANGE_CONTROL_ADMIN.ACTIVE%TYPE,
pstat1   IN CHANGE_CONTROL_ADMIN.STATUS1%TYPE,
pstat2   IN CHANGE_CONTROL_ADMIN.STATUS2%TYPE,
padmcomm   IN CHANGE_CONTROL_ADMIN.ADM_NOAPROVE%TYPE)
(cctrlid IN NUMBER)
IS
BEGIN
  -- UPDATE STATEMENT
UPDATE CHANGE_CONTROL_ADMIN
   SET CLOSEDATE = pdate, ACTIVE = pact, STATUS1 = pstat1, STATUS2 = pstat2, ADM_NOAPROVE = padmcomm
   WHERE CHANGE_CTRL_ID = cctrlid;
COMMIT;
END updadminproc;
/Here are the errors I get that it's showing:
LINE/COL ERROR
7/2      PLS-00103: Encountered the symbol "(" when expecting one of the
         following:
         ; is with authid as cluster order using external
         deterministic parallel_enable pipelined
8/2      PLS-00103: Encountered the symbol "IS" when expecting one of the
         following:
         returnMessage was edited by:
user515689

when I change it accordingly as to how you suggest, the procedure (in SQL Plus) gets created just fine, but then I get an Oracle error when calling the SP.
PLS-00306: wrong number or types of arguments in call to 'UPDADMINPROC'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
        at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)Any ideas? Since it reads wrong no. of arguments?
My Java call statement looks like the following:
CallableStatement cstmt = connection.prepareCall("{call updadminproc (?,?,?,?,?)}");
   cstmt.setDate(1,cldt);
   cstmt.setInt(2,actboxval);
   cstmt.setString(3,status1);
   cstmt.setString(4,status2);
   cstmt.setString(5,fincomments);
   cstmt.executeUpdate();I mean, I'm not trying to update the ID no., just associate the record with the ID number (cctrlid).
Thanks.
Ok, I got it....even though not updating the ID # itself, I had to add it to the cstmt object.
As in ....
cstmt.setString(5,fincomments);
cstmt.setInt(6,ctid2);
cstmt.executeUpdate();
Message was edited by:
user515689

Similar Messages

  • About update statement in procedure

    I have one table usersubscription (userid,newsletterid,deleted)
    I got one string from user e.g. ('1,2,3') and userid = 14
    I wrote proceduer that will insert this records in to usersubscription table;
    userid newsletterid deleted
    14 1 n
    14 2 n
    14 3 n
    default value of deleted column is 'n'.
    my procedure is as follows;
    CREATE OR REPLACE PROCEDURE usersubscription_procd1 (vuserid in number, vnewsletterid IN VARCHAR2)
    AS
    I NUMBER;
    J NUMBER;
    VAL VARCHAR2(100);
    BEGIN
    I := 1;
    J := 1;
    WHILE INSTR(vnewsletterid,',',I) != 0 LOOP
    VAL := SUBSTR(vnewsletterid,I,INSTR(vnewsletterid,',',I)-J);
    I := INSTR(vnewsletterid,',',I)+1;
    J := I;
    INSERT INTO usersubscription (usersubcriptionid,userid,newsletterid)
    VALUES (usersubscription_seq.nextval,vuserid,VAL);
    END LOOP;
    VAL := SUBSTR(vnewsletterid,I,LENGTH(vnewsletterid));
    INSERT INTO usersubscription (usersubcriptionid,userid,newsletterid)
    VALUES (usersubscription_seq.nextval,vuserid,VAL);
    END;
    Now one requirement is that when new string comes for same userid e.g.('1,4,5') userid = 14
    then the deleted column for 2 and 3 newsletterid changes to 'y';
    please tell me the solution.
    Prathamesh.

    Read my suggestion into your other post : Re: how to add the update statement in this procedure?
    And please, for more readable forum, do not post twice the same subject, use reply button (or edit) to discuss.
    Nicolas.

  • Deadlocks with simple UPDATE statement

    I have in a C# program a dictionary and in SQL Server a stored procedure with a simple UPDATE statement. I process the dictionary in parallel. For each entry in my dictionary I call this stored procedure and I am getting deadlocks.
    This is the UPDATE statement:
    ALTER PROCEDURE [dbo].[UpdateImages]
    @ICRTCode nvarchar(max),
    @ICRTImage nvarchar(max)
    AS
    BEGIN
    UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE() WHERE IDICRT = @ICRTCode
    END
    Can someone give me a hint as to why this would cause deadlocks? There are no other processes writing to this table. This is a table in a staging database.

    http://blogs.msdn.com/bartd/archive/2006/09/09/747119.aspx
    http://blogs.msdn.com/bartd/archive/2006/09/25/770928.aspx
    Try change the statement a little bit
    UPDATE Images SET processed = '1', Image = @ICRTImage, ProcessDate = GETDATE()
    FROM
    Images
    WITH (TABLOCK) WHERE IDICRT = @ICRTCode
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to use Update Statement in ODI Procedure

    Hi,
    How can I use an update statement inside an ODI procedure.
    Thanks

    Hi,
    You do not need the BEGIN and END. ODI procedures are free text, so you can simply write your update statement, as you would in toad/sql developer etc etc. Just make sure you set the Technology and the logical schema. It is how ever best practice to also use the API:
    <%=odiRef.getSchemaName("YOUR_LOGICAL_SCHEMA_NAME", "D")%>. to prefix tables. This way, you select data from different schema's in the same instance (as long a your user has the correct privs).
    Cheers
    Bos
    Edited by: Bos on Jun 22, 2011 3:09 PM

  • Update statement in a procedure

    update pol_notification a
    set obj_id = v_presv_client_id
    where a.obj_id=v_client_id and a.obj_type='client' ;
    update pol_notification a
    set obj_id = v_address_id
    where a.obj_id=v_address_id and a.obj_type='address' ;
    I am using these two update statements in one procedure but the tables are not being updated.
    Any reason for that. Am i using the right statements?

    Here is the procedure.....
    CREATE OR REPLACE PROCEDURE SP_LOAD_CLIDUPDATA( )
         BEGIN
    DECLARE v_client_id integer ;
    DECLARE v_presv_client_id integer ;
    DECLARE v_processed_client_id integer;
         DECLARE v_address_id integer;
    DECLARE V_NUMBER integer;
    DECLARE v_counter integer DEFAULT 0;
    DECLARE cur_update CURSOR FOR
    SELECT client_id,presv_client_id,nvl(processed_client_id,0),nvl(address_id,0)
    FROM cli_dup_data ;
    DECLARE cur_num CURSOR FOR
    SELECT count(*) FROM cli_dup_data ;
    open cur_num;
    fetch cur_num into V_NUMBER;
    close cur_num;
    OPEN cur_update;
    loop
    IF v_counter = V_NUMBER THEN
    end loop;
    END IF;
    FETCH cur_update INTO v_client_id,v_presv_client_id,v_processed_client_id,v_address_id;     
    if v_client_id = 0 then
    COMMIT; --Commit transactions at batch level only
    ELSE
    If v_processed_client_id <> v_client_id then -- client_id is already processed
                   update pol_notification a set obj_id = v_presv_client_id --Update client_id
         where a.obj_id=v_client_id and a.obj_type='client';
         update pol_notification a set obj_id = v_address_id -- Update address_id
         where a.obj_id=v_address_id and a.obj_type='address';
    update pol_notify_history b set obj_id=v_presv_client_id,
    client_seq_nbr_i = 1
    where b.obj_id = v_client_id and b.obj_type='client';
    update pol_notify_history b set obj_id = v_address_id
    where b.obj_id = v_client_id and b.obj_type = 'address';
    update pol_int_name set client_id = v_presv_client_id --Update client_id
         where client_id=v_client_id;
         update cli_dup_data set processed_client_id=v_client_id --Keep a record of updated client_id in processed_client_id
         where client_id=v_client_id;
    end if;
              END IF;
    set v_counter = v_counter+1;
    END loop ;
    CLOSE cur_update;

  • Executing a Variable in a Stored Procedure containing an Update Statement

    Hi,
    I have created a Stored Procedure, it has one input parameter. Inside the Stored Procedure there are 5 other variables are declared, based on the input parameter 4 of these variables are populated.
    Fifth variable is a a concatenation of text and some of these variables and creates a dynamic Update Statement. Once it is created I want to execute this variable but it is not executing.
    Could someone please help me in knowing how to execute a variable within a stored procedure that contains an update statement.
    Thanks for your help.
    Thanks
    Vineesh
    vineesh1701

    If you have set up the variable so that it contains a valid sql update, it should work.  For example, see below, which does do an update
    use tempdb
    go
    Create Table #Test(i int);
    Insert #Test(i) Values(1);
    go
    Create Procedure TestProc As
    Begin
    Declare @SQL nvarchar(250);
    Set @SQL = 'Update #Test Set i = 2';
    --Print @SQL;
    Exec sp_executesql @SQL;
    End
    go
    Exec TestProc
    -- Test Result
    Select * From #Test;
    go
    Drop Procedure TestProc;
    go
    Drop Table #Test;
    One thing I would recommend while testing is that you print out or select the variable that contains the dynamic sql.  (Like the above code where I have a print statement.  That lets you see exactly what you are executing and if there is any problem
    with the update command. 
    As Naomi said, to get anything more than general help, you will probably have to show us your code and the parameter values you are passing when you execute the stored proc.
    Tom

  • Where clause in UPDATE statement is ignored

    I have the following procedure that updates a field in a table. The only problem is that all rows in the table are updated like the update statement doesn't have a where clause. When I hard code the number (733) in the where clause it works as expected. Even if I don't alias the table name it still updates all rows in the table. Any ideas?
    DECLARE
    extlinkid CONSTANT NUMBER := 733;
    newURL CONSTANT VARCHAR2(250) := 'mailto:[email protected]';
    BEGIN
    UPDATE SCHEMA.TABLE A
    SET A.URL = newURL
    WHERE (A.EXTLINKID = extlinkid);
    commit;
    END;

    Oracle is resolving your variable extlinkid as the column in the table, so your UPDATE statement is equivalent to:
    UPDATE schema.table a
    SET a.url = newurl
    WHERE (a.extlinkid = a.extlinkid);Which, of course, matches every record in the table. You need to change the name of your variable to something that is not a column name.
    TTFN
    John

  • Problem in Update statement using Execute Immediate

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

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

  • JDBC Sender Adapter, Update statement

    Hi ALL,
               I have a JDBC to proxy scenario. We have stored procedure in the database that executess and sends the data to SAP.
    Also the same store procedure updates the field Status_ID to distinguish between read and unread records. Status_ID acts as a Flag.
    Now because the Stored procedure itself does what 'Update SQL Statement' in sender JDBC adapter does, what shall I put in 'Update SQL Statement' as it is not needed, but it's a mandatory field??
    XIer
    Message was edited by:
            XIer

    Do you need that update in the sender jdbc adaptor to do anything....?
    Dint think so..
    Change your update statement to update Status_ID if its not updated..and if the sql procedure has run already then its not going to be updated ..as it already is.......
    Regards
    Ravi Raman

  • Updation in stored procedure

    Hi ,
    I have a stored procedure in which one part updates a table.If atleast one row is affected then I want to do some processing .How can I get the information after the update statement is fired , that at least one row in the table is affected?
    Regards,
    Rahul

    we can use 'sql%rowcount' to check number of rows processed

  • Dynamic UPDATE statement with parameters for column names.

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

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

  • 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

  • Skipping update statement

    i am using 'For Update' statement to lock a record in a table and then updating that table through another update statement, like this in a procedure in my Developer Suite 9i application:-
    1)SELECT TOTAL_OUTSTANDING INTO TEMP_OUTSTANDING FROM PPBS_DISTRIBUTOR_MASTER where distributor_id=:rh.distributor_id
         FOR UPDATE OF TOTAL_OUTSTANDING NOWAIT;
    2)UPDATE PPBS_distributor_master set total_outstanding = total_outstanding - to_number(:RH.instrument_amount)
                        where distributor_id = :RH.distributor_id;
    This update in the 2nd statement is skipping sometimes. I have heard that a post-update trigger fires always even if this statement in the procedure is skipping. Can i put these 2 statements in a block level 'post-update' trigger and be assured that the 'Update' statement will fire always. Please help in solving the doubt as it is urgent.
    Regards.

    Excuse me, to avoid confusion, my previous note should be read as:
    I) Put your 1) FOR satatement in block's on-lock trigger;
    II) Put your 2) in block's on-update trigger;
    Don't put your 1) and 2) in one procedure!

  • Problem with update statement

    Hi, i have the following data
    document_seq_num, Country, LE, SOB
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    i want an update statement for every change in the document sequnce with the other combination..
    the seqence number should change.
    i tried to write a rank over partion and and sequence but when i am trying to update, this is always updating
    90000000 in first run, as it is in loop for all records it is updating the same. i want an
    increment to the sequence for every change in document_seq_num
    Can any one help me to correct this procedure
    create or replace PROCEDURE test is
    cursor cur_voc_ref
    IS SELECT a.document_seq_num,
    a.country, a.LE, a.SOB, 2009, Rank() over (partition by
    a.country, a.LE, a.SOB
    order by a.document_seq_num, a.country, a.LE, a.SOB)
    from (select distinct document_seq_num,
    country, LE, SOB,period_name
    from temp_tab
    where country= 'NL'
    and LE= '000320'
    and SOB=13
    order by SOB,LE,document_seq_num) a
    where
    a.country= 'NL'
    and a.LE= '000320'
    and a.SOB=13
    and substr(a.period_name,5,6) =substr(2009,3,4);
    v_base number;
    BEGIN
    FOR c_rec IN cur_voc_ref
    LOOP
    BEGIN
    select nvl(max(ggtsi.reference), substr(2009,3,2)*1000000) into v_base
    from temp_tab ggtsi;
    update temp_tab
    set reference= v_base
    where document_seq_num= c_rec.document_seq_num
    and country=c_rec.country
    and le=c_rec.le
    and sob=c_rec.sob;
    commit;
    END;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line( 'Exception in opening balance insert ' || SQLCODE || ' ' || SQLERRM );
    END;

    user11289444 wrote:
    Hi, i have the following data
    document_seq_num, Country, LE, SOB
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    i want an update statement for every change in the document sequnce with the other combination..
    the seqence number should change.
    i tried to write a rank over partion and and sequence but when i am trying to update, this is always updating
    90000000 in first run, as it is in loop for all records it is updating the same. i want an
    increment to the sequence for every change in document_seq_num
    Can any one help me to correct this procedure
    create or replace PROCEDURE test is
    cursor cur_voc_ref
    IS SELECT a.document_seq_num,
    a.country, a.LE, a.SOB, 2009, Rank() over (partition by
    a.country, a.LE, a.SOB
    order by a.document_seq_num, a.country, a.LE, a.SOB)
    from (select distinct document_seq_num,
    country, LE, SOB,period_name
    from temp_tab
    where country= 'NL'
    and LE= '000320'
    and SOB=13
    order by SOB,LE,document_seq_num) a
    where
    a.country= 'NL'
    and a.LE= '000320'
    and a.SOB=13
    and substr(a.period_name,5,6) =substr(2009,3,4);
    v_base number;
    BEGIN
    FOR c_rec IN cur_voc_ref
    LOOP
    BEGIN
    select nvl(max(ggtsi.reference), substr(2009,3,2)*1000000) into v_base
    from temp_tab ggtsi;
    update temp_tab
    set reference= v_base
    where document_seq_num= c_rec.document_seq_num
    and country=c_rec.country
    and le=c_rec.le
    and sob=c_rec.sob;
    commit;
    END;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line( 'Exception in opening balance insert ' || SQLCODE || ' ' || SQLERRM );
    END;Hi,
    I suggest you to add a column to preserve current RANK value for all rows, <preserve_rank> for example, and
    when you add the new rows you will update your <preserve_rank> but you must pay attention to have the same value for
    document_seq_num, with other words you may insert yours rows in a batch like this:
    -- first update preserve_rank with RANK function
    declare
    v_doc_seq_num numeric;
    begin
    v_doc_seq_num:=33100040;
    -- note !!!
    -- put all into a valid sql command
    -- and apply execute immediate
    insert into temp_tab(document_seq_num, country, le, sob,Period_name)values(v_doc_seq_num, 'NL', '000320', 13,'APR-09');
    insert into temp_tab(document_seq_num, country, le, sob,Period_name)values(v_doc_seq_num, 'NL', '000320', 13,'APR-09');
    insert into temp_tab(document_seq_num, country, le, sob,Period_name)values(v_doc_seq_num, 'NL', '000320', 13,'APR-09');
    -- update preserve_rank
    update temp_tab x  set x.preserve_rank = (Select max(preserve_rank) from temp_tab y
                                              where y.document_seq_num=v_doc_seq_num) old_rank + 1)
    where (prserve_rank is null) and x.document_seq_num=v_doc_seq_num;
    end;  I know it's a lost a memory but the trigger is the last solution who can give us a nightmare.
    Regards,
    Ion
    Edited by: user111444777 on Sep 25, 2009 11:12 AM
    Edited by: user111444777 on Sep 25, 2009 11:35 AM

  • 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

Maybe you are looking for

  • How to reload the screen when changing languages in JavaFX 2?

    I'm beginner with javaFX and i need to change language of the screen. but i have no idea how to reload the screen when the language was changed. The application have a button where have the language available. I want just refresh screen when the user

  • Why is macbook pro running very slow?

    Hi! Could someone tell me why my macbook pro is so slow recently? During exams its really distrubing to having forced pauses. Thanks for your support! I ve just done the EtreCheck: Hardware Information:           MacBook Pro (13-inch, Mid 2010)     

  • [Solved] Python: Creating AUR package, binary can't find python module

    I'm building a PKGBUILD for PyLotRO for the AUR and I'm using a Debian package.  I tried just copying the content of the data.tar.gz to the filesystem assuming the directory structure is the same for the packages but apparently it is not.  At least I

  • How to change merge to update

    in this statement change merge to update plz help me MERGE INTO CORM_QWD_QUOTE_WUTASK A USING (SELECT * FROM CORM_QMD_QUOTEMAT) B ON ( ( A.QWD_ORDER_OU = B.QMD_ORDER_OU AND A.QWD_ORDER_NO = B.QMD_ORDER_NO AND A.QWD_AMEND_NO = B.QMD_AMEND_NO AND A.QWD

  • Centering items in the Navigation Menu

    I have a multi page web site that was created in iWeb08. On some of the pages all the items are properly centered... on others they are right justified and in some browsers they wrap to a third line. How can I edit or format them so they are all the