DELETE Statements [SOLVED]

This is simple question.
I have 1 big table. select * from big_table requires a lot of time.
Then I delete some records on big_table. delete from big_table where no > 1000.
Thus the table size has reduced significantly. However when I select again using select statement above. The query still take a long time.
Why?
When I truncate the big_table with drop storage option. Then insert the big_table with records that saved previously. Then it runs quickly.
Question how to use DELETE statements that drop storage? Is DELETE statements doesnt release the storage?
regards n thanks
Message was edited by:
user465837+++eric

No. DELETE does not release storage that is already allocated to a table. It just makes those blocks available on the free list of blocks for that segment.
However, the high water mark for that segment is reset ONLY by the truncate/MOVE commands (DROP also is useful but not always ;)).
Since FTS against such tables is going to scan all the rows below the HWM, it is bound to take time when a table is cleaned up using DELETE command.

Similar Messages

  • Oracle deadlocks on delete statement

    I had a package procedure that deletes from a inline-view. It worked well and didn't create any database locks, looked like this:
    PROCEDURE serverdisconnect(pCode1 NUMERIC, pCode2 NUMERIC) IS
      BEGIN
         DELETE FROM
            SELECT cl.* FROM CurrentLogins cl, Accounts a
            WHERE cl.Code1 = pCode1
            AND cl.Code2 = pCode2
            AND cl.Code = a.code
            AND a.Type = 'lplayer'
            ORDER BY a.code
        COMMIT;
      END serverdisconnect;I slightly changed the procedure to look like following, and deadlocks started to come:
    PROCEDURE ServerDisconnect(pCode1 NUMERIC, pCode2 NUMERIC, pChannelServerCode CurrentLogins.ChannelServerCode%TYPE, pDeleteList OUT cursor_type)
      IS
        vDeleteList sys.ODCINumberList;
      BEGIN
        DELETE FROM
            SELECT cl.* FROM CurrentLogins cl, Accounts a
            WHERE cl.Code1 = pCode1
           AND cl.Code2 = pCode2
           AND cl.Code = a.code
           AND cl.ChannelServerCode = pChannelServerCode
           AND cl.Code = a.code
           AND a.Type = 'lplayer'
        ) RETURNING Code
          BULK COLLECT INTO vDeleteList;
        OPEN pDeleteList FOR
          SELECT * FROM TABLE(vDeleteList);
        COMMIT;
      END ServerDisconnect;As you see the main difference in the delete statement is that i removed "ORDER BY"-clause? Can really such data ordering plays a role with dead locking? Does the data records be always ordered with ORDER-BY-clause same way always to avoid deadlock? Why i started to get deadlock after changing the procedure?
    I have Oracle 10g.

    Yes, typo, i fixed initial post now.
    Delete will be technically done on table CurrentLogins, using that inline-view.
    I will move the Commit to proper place as you suggested.
    but still i don't understand why deadlocks started to occure.
    Maybe really the answer is having "order by" clause, which solves the deadlocks?
    See this link:
    http://www.oracle-base.com/articles/misc/Deadlocks.php
    >
    To resolve the issue, make sure that rows in tables are always locked in the same order.
    >
    Does it says that i always have to have "order by" sentence included into my delete statement?
    Relationships between tables:
    alter table CURRENTLOGINS
      add constraint FK_CURRENTLOGINS_ACCOUNTS foreign key (CODE)
      references ACCOUNTS (CODE);Maybe ORDER-BY really solves deadlocks then, see:
    http://www.dbasupport.com/forums/archive/index.php/t-50438.html
    >
    Add an explicit ORDER BY to the select, and it will probably go away.
    >
    Edited by: CharlesRoos on Sep 9, 2010 6:05 AM

  • Missing privilege - DELETE statement in procedure

    Hello experts,
    I am facing a problem for my procedure. I am not able to active the procedure if I use DELETE statement in the produce. When I use only selects, it is working fine. The SYSTEM user has access to the schema with full rights, including DELETE.
    PROCEDURE "SYSTEM"."DEV_COL.procedures::FI" ( )
      LANGUAGE SQLSCRIPT
      SQL SECURITY INVOKER
      DEFAULT SCHEMA UXX790
      AS
    BEGIN
      Write your procedure logic
    -- SELECT vbeln
    --count(*)
      DELETE
      from vbapold
      where erdat < ADD_days(now(), -1700);
    END;
    Did anybody had the same issue? I run HANA rev70.
    BR
    Tamas

    Hi Tamas
    if this is a repository procedure user _SYS_REPO has to have the DELETE privilege with grant option as well.
    - Lars

  • Delete statement evaluation

    Hi People,
    I have the following delete statement i'm trying to execute. i get ORA-923 error. Please review and comment.
    DELETE FROM INACTIVE_ORDERS IO WHERE IO.REQ_NUM IN (SELECT REQ_NUM SRINI_ARCHIVE_VIEW) OR
    IO.REQ_NUM IN (SELECT REQ_NUM FROM SRINI_CHILD_VIEW);

    Seems like a simple syntax error; should be:
    DELETE FROM INACTIVE_ORDERS IO WHERE IO.REQ_NUM IN (SELECT REQ_NUM FROM SRINI_ARCHIVE_VIEW) OR
    IO.REQ_NUM IN (SELECT REQ_NUM FROM SRINI_CHILD_VIEW);

  • Delete Statement Exception Handling

    Hi guys,
    I have a problem in my procedure. There are 3 parameters that I am passing into the procedure. I am matching these parameters to those in the table to delete one record at a time.
    For example if I would like to delete the record with the values ('900682',3,'29-JUL-2008') as parameters, it deletes the record from the table but then again when I execute it with the same parameters it should show me an error message but it again says 'Deleted the Transcript Request.....' Can you please help me with this?
    PROCEDURE p_delete_szptpsr_1 (p_shttran_id IN saturn.shttran.shttran_id%TYPE,
    p_shttran_seq_no IN saturn.shttran.shttran_seq_no%TYPE,
    p_shttran_request_date IN saturn.shttran.shttran_request_date%TYPE) IS
    BEGIN
    DELETE FROM saturn.shttran
    WHERE shttran.shttran_id = p_shttran_id
    and shttran.shttran_seq_no = p_shttran_seq_no
    and trunc(shttran_request_date) = trunc(p_shttran_request_date);
    DBMS_OUTPUT.PUT_LINE('Deleted the Transcript Request Seq No (' || p_shttran_seq_no || ') of the Student (' || p_shttran_id ||') for the requested date of (' || p_shttran_request_date ||')');
    COMMIT;
    EXCEPTION WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('Error: The supplied Notre Dame Student ID = (' || p_shttran_id ||
    '), Transcript Request No = (' || p_shttran_seq_no || '), Request Date = (' || p_shttran_request_date || ') was not found.');
    END p_delete_szptpsr_1;
    Should I have a SELECT statement to use NO_DATA_FOUND ???

    A DELETE statement that deletes no rows (just like an UPDATE statement that updates no rows) is not an error to Oracle. Oracle won't throw any exception.
    If you want your code to throw an exception, you'll need to write that logic. You could throw a NO_DATA_FOUND exception yourself, i.e.
    IF( SQL%ROWCOUNT = 0 )
    THEN
      RAISE no_data_found;
    END IF;If you are just going to catch the exception, though, you could just embed whatever code you would use to handle the exception in your IF statement, i.e.
    IF( SQL%ROWCOUNT = 0 )
    THEN
      <<do something about the exception>>
    END IF;In your original code, your exception handler is just a DBMS_OUTPUT statement. That is incredibly dangerous in real production code. You are relying on the fact that the client has enabled output, that the client has allocated a large enough buffer, that the user is going to see the message, and that the procedure will never be called from any piece of code that would ever care if it succeeded or failed. There are vanishingly few situations where those are safe things to rely on.
    Justin

  • Delete statement: how to get count of affected rows in a variable

    Hi folks
    I write a proc which deletes data from bunch of table based on data value. i want to produce a report which will have 1 line for each table like:
    Del: Table name : number of rows
    I parse delete statement into variable and use execute immediate. I know I could precede delete by select count(*) using the same criteria. Is there any more effective way to catch output from execution of 'delete' itself to avoid an overhead of running select count(*)?
    Thank you, Gene.

    Gene,
    I thought you said you wanted to have the number of rows deleted. In that case, see Sänjay's example above.
    Btw, is there a particular reason that you are using EXECUTE IMMEDIATE (?)
    To have it in a variable
    declare
       v_rows_deleted  number;
    begin
       delete from emp;
       v_rows_deleted := SQL%ROWCOUNT;
    end ;Regards
    Peter
    Edited by: Peter on Jul 23, 2009 7:48 AM
    Added example

  • How to delete the data from KNVP without using the delete statement

    Hello friends,
    I have a requirement that I have to delete the data from KNVP table without using any delete statement. For it I have to use the Standard BAPI or any standard program.
    Can you please tell me the name of the standard program or BAPI to delete the data .
    Thanks in Advance
    Kuldeep

    Hello Raymond,
    I have use the function 'CUSTOMER_UPDATE' in which I only gives the data in T_XKNVP table only but still the data is not get deleting. Please see the code below.
    =============================================================
    REPORT  ZK_TEST2                                .
    data :
        I_KNA1     LIKE     KNA1,
        I_KNB1     LIKE     KNB1,
        I_KNVV     LIKE     KNVV,
        I_YKNA1     LIKE     KNA1,
        I_YKNB1     LIKE     KNB1.
    Data :
    T_XKNAS       LIKE     FKNAS occurs 0,
    T_XKNB5     LIKE     FKNB5 occurs 0,
    T_XKNBK     LIKE     FKNBK occurs 0,
    T_XKNVA     LIKE     FKNVA occurs 0,
    T_XKNVD     LIKE     FKNVD occurs 0,
    T_XKNVI     LIKE     FKNVI occurs 0,
    T_XKNVK     LIKE     FKNVK occurs 0,
    T_XKNVL     LIKE     FKNVL occurs 0,
    T_XKNVP     LIKE     FKNVP occurs 0 with header line,
    T_XKNVS     LIKE     FKNVS occurs 0,
    T_XKNEX     LIKE     FKNEX occurs 0,
    T_XKNZA     LIKE     FKNZA occurs 0,
    T_YKNAS     LIKE     FKNAS occurs 0,
    T_YKNB5     LIKE     FKNB5 occurs 0,
    T_YKNBK     LIKE     FKNBK occurs 0,
    T_YKNVA     LIKE     FKNVA occurs 0,
    T_YKNVD     LIKE     FKNVD occurs 0,
    T_YKNVI     LIKE     FKNVI occurs 0,
    T_YKNVK     LIKE     FKNVK occurs 0,
    T_YKNVL     LIKE     FKNVL occurs 0,
    T_YKNVP     LIKE     FKNVP  occurs 0 with header line,
    T_YKNVS     LIKE     FKNVS occurs 0,
    T_YKNEX     LIKE     FKNEX occurs 0,
    T_YKNZA     LIKE     FKNZA occurs 0.
    T_XKNVP-KUNNR     =     '7000002648'     .
    *T_XKNVP-VKORG     =     '0001'     .
    *T_XKNVP-VTWEG     =     '01'     .
    *T_XKNVP-SPART     =     '01'     .
    T_XKNVP-KZ      =     'D'     .
    append T_XKNVP to T_XKNVP.
    CALL FUNCTION 'CUSTOMER_UPDATE'
      EXPORTING
        I_KNA1        = I_KNA1
        I_KNB1        = I_KNB1
        I_KNVV        = I_KNVV
        I_YKNA1       = I_YKNA1
        I_YKNB1       = I_YKNB1
      TABLES
        T_XKNAS       = T_XKNAS
        T_XKNB5       = T_XKNB5
        T_XKNBK       = T_XKNBK
        T_XKNVA       = T_XKNVA
        T_XKNVD       = T_XKNVD
        T_XKNVI       = T_XKNVI
        T_XKNVK       = T_XKNVK
        T_XKNVL       = T_XKNVL
        T_XKNVP       = T_XKNVP
        T_XKNVS       = T_XKNVS
        T_XKNEX       = T_XKNEX
        T_XKNZA       = T_XKNZA
        T_YKNAS       = T_YKNAS
        T_YKNB5       = T_YKNB5
        T_YKNBK       = T_YKNBK
        T_YKNVA       = T_YKNVA
        T_YKNVD       = T_YKNVD
        T_YKNVI       = T_YKNVI
        T_YKNVK       = T_YKNVK
        T_YKNVL       = T_YKNVL
        T_YKNVP       = T_YKNVP
        T_YKNVS       = T_YKNVS
        T_YKNEX       = T_YKNEX
        T_YKNZA       = T_YKNZA
    =============================================================

  • Delete Statement is not working correctly

    Hello,
    The following delete statement is not working correctly.
    If I press delete it will delete everything in the category table
    I don't know whats wrong with it.
    ----delete row from category if there is not infrastructure to support------
    IF :P12_DFCY_SEQNO4 IS NOT NULL AND :P12_DFCY_CATG_C = '7' THEN
    DELETE FROM DFCY_CATG
    WHERE NOT EXISTS(SELECT I.DFCY_SEQNO
    FROM DFCY_CATG C, DFCY_CATG_INFRSTRCTR I
    WHERE C.DFCY_SEQNO = I.DFCY_SEQNO
    AND :P12_DFCY_SEQNO4 = I.DFCY_SEQNO);
    end if;
    Thanks
    Mary

    Hi,
    IF :P12_DFCY_SEQNO4 IS NOT NULL AND :P12_DFCY_CATG_C = '7' THEN
    DELETE FROM DFCY_CATG
    WHERE NOT EXISTS(SELECT I.DFCY_SEQNO
    FROM DFCY_CATG C, DFCY_CATG_INFRSTRCTR I
    WHERE C.DFCY_SEQNO = I.DFCY_SEQNO
    AND :P12_DFCY_SEQNO4 = I.DFCY_SEQNO);
    end if;So, if P12_DFCY_SEQNO4 does not exist, then I would expect all records to be deleted because the NOT EXISTS() function would just return TRUE for every record on the table. Somewhere in the statement, I would expect to see something that links between the table being deleted from and the NOT EXISTS() data or, perhaps, using the P12_DFCY_CATG_C value as a filter?
    Andy

  • Delete statement is not working.

    Hi,
    find the code. Here the delete statement is not working and i am getting sy-subrc = 4. although ,
    xe1edp10-idnkd = 34596 and dint_edidd -sdata = 34596.
    please help me ...
    loop at dekek_x.
    loop at dint_edidd where segnam = 'E1EDP10'.
    if dekek_x-stpin = 1 .
    CLEAR xe1edp10.
      MOVE dint_edidd-sdata TO xe1edp10.
    delete dint_edidd where sdata = xe1edp10-idnkd.
    endif.
    endloop.

    1st thing..
    i tried this :
    tables: edidd, e1edp10.
    edidd-sdata = '315934 EA 017'.
    WRITE edidd-sdata.
    move edidd-sdata to e1edp10.
    IF edidd-sdata = e1edp10-idnkd.
    WRITE: e1edp10-idnkd.
    else.
      WRITE: 'nothing'.
    ENDIF.
    output
    >315934 EA 017
    >315934 EA 017
    2nd thing,.
    your loop inside loop doesnt make any sense as they are not related any where.
    3rd thing:
    the fields are not type compatible.. this might be the reason for wrong delete statement..
    and 1 more clarification:
    TABLES: edidd, e1edp10.
    DATA :it TYPE TABLE OF edidd WITH HEADER LINE.
    edidd-sdata = '315934 EA 017'.
    WRITE edidd-sdata.
    APPEND edidd TO it.
    edidd-sdata = '315934 EA 018'.
    APPEND edidd TO it.
    LOOP AT it." where segnam = 'E1EDP10'.
      CLEAR e1edp10.
      MOVE it-sdata TO e1edp10.
      DELETE it WHERE sdata = e1edp10-idnkd.
    ENDLOOP.
    in this also delete is working perfectly fine... you run and check..

  • Delete statement that uses a sub-select with the statement in the cursor

    Hi all,
    How to write write a delete statement that uses a sub-select with the statement in the cursor?
    CURSOR excluded_dates IS         
           SELECT TO_TIMESTAMP(report_parameter_value, in_date_format_mask)
          INTO my_current_date_time
          FROM report_parameters
         WHERE report_parameters.report_parameter_id    = in_report_parameter_id
           AND report_parameters.report_parameter_group = 'DATE_TIME'
           AND report_parameters.report_parameter_name  = 'EXCLUDED_DATE';
    OPEN excluded_dates;
      LOOP
        FETCH excluded_dates INTO my_excluded_date;
        EXIT WHEN excluded_dates%NOTFOUND;
        DELETE FROM edr_rpt_tmp_inclusion_table
        WHERE TO_CHAR(date_time, 'mm/dd/yyyy') = TO_CHAR(my_excluded_date, 'mm/dd/yyyy');
      END LOOP;
      CLOSE excluded_dates;Thanks

    Hi,
    In such case I think is better to create a view an perform the delete using it. Example (using HR schema):
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL> create or replace view v_employees as select * from employees where first_name like 'J%';
    View created
    SQL> select * from v_employees;
    EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE   JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
            110 John                 Chen                      JCHEN                     515.124.4269         28/09/1997  FI_ACCOUNT    8200,00                       108           100
            112 Jose Manuel          Urman                     JMURMAN                   515.124.4469         07/03/1998  FI_ACCOUNT    7800,00                       108           100
            125 Julia                Nayer                     JNAYER                    650.124.1214         16/07/1997  ST_CLERK      3200,00                       120            50
            127 James                Landry                    JLANDRY                   650.124.1334         14/01/1999  ST_CLERK      2400,00                       120            50
            131 James                Marlow                    JAMRLOW                   650.124.7234         16/02/1997  ST_CLERK      2500,00                       121            50
            133 Jason                Mallin                    JMALLIN                   650.127.1934         14/06/1996  ST_CLERK      3300,00                       122            50
            139 John                 Seo                       JSEO                      650.121.2019         12/02/1998  ST_CLERK      2700,00                       123            50
            140 Joshua               Patel                     JPATEL                    650.121.1834         06/04/1998  ST_CLERK      2500,00                       123            50
            145 John                 Russell                   JRUSSEL                   011.44.1344.429268   01/10/1996  SA_MAN       14000,00           0,40        100            80
            156 Janette              King                      JKING                     011.44.1345.429268   30/01/1996  SA_REP       10000,00           0,35        146            80
            176 Jonathon             Taylor                    JTAYLOR                   011.44.1644.429265   24/03/1998  SA_REP        8600,00           0,20        149            80
            177 Jack                 Livingston                JLIVINGS                  011.44.1644.429264   23/04/1998  SA_REP        8400,00           0,20        149            80
            181 Jean                 Fleaur                    JFLEAUR                   650.507.9877         23/02/1998  SH_CLERK      3100,00                       120            50
            186 Julia                Dellinger                 JDELLING                  650.509.3876         24/06/1998  SH_CLERK      3400,00                       121            50
            189 Jennifer             Dilly                     JDILLY                    650.505.2876         13/08/1997  SH_CLERK      3600,00                       122            50
            200 Jennifer             Whalen                    JWHALEN                   515.123.4444         17/09/1987  AD_ASST       4400,00                       101            10
    16 rows selected
    SQL> delete from v_employees where hire_date >= to_date('01/06/1998', 'dd/mm/yyyy');
    2 rows deleted
    SQL> regards,

  • Looping delete statement where table name is coming from another table

    Hi All,
    We have to write code to delete records from active tables of WDSO.We have 5 DSO  so inspite of writing delete statement for each table we want to put all table names into one table and then loop through it .but we are getting error when we are refering that table field which has active table name.error is :
    "dictionary structure or table is either not active or does not exist "
    As per my understanding in a delete /select /insert /update statement we need to put table name (whose field we are refering ) it can't be replaced by a variable .
    ex: v_table = 'EMPLOYEE' .
    DELETE FROMv_table WHERE EMP_NAME = 'ABDC' .
    is wrong and it must be like
    ex : DELETE FROM EMPLOYEE WHERE EMP_NAME = 'ABDC' .
    but we want to make our code dynamic .
    Can you please suggest a way so that we can read the table names from another table and delete data based on some selection fom those tables .
    I tried variants ,perform etc and even searched FM for the same but not found a solution .Your help will be greatly appreciated .
    Thanks in advance .
    Regards,
    Jaya

    Hi,
    You can change your statement as follows:
    DELETE FROM (v_table) WHERE EMP_NAME = 'ABDC' .
    However, I would not recommend this. There is a standard function module RSAN_ODS_DATA_DELETE which allows selective deletion - that should be a safer way to do this. You can

  • Converting a delete statement using VPD policies and context

    Hello,
    I'm trying to convert a delete statement in a update statement using VPD policies and context.
    +/* Supose the user 'user1' already exists. This is an application user */+
    conn user1/pwd
    create table user1.test_a (
    id                number(4),
    description       varchar2(100),
    deleted           number(1)
    +);+
    alter table user1.test_a add constraint test_a_pk primary key (id);
    insert into user1.test_a (1, 'abc', 0);
    insert into user1.test_a (2, 'def', 0);
    commit;
    I'd like to convert each physical deletion into a logical deletion: statements like "delete from user1.test_a where id = 1" must be converted into "update user1.test_a set deleted = 1 where id = 1".
    I've found the following way: I will create a policy to avoid physical deletion. Additionally, the policy function should update the deletion flag too.
    conn user1/pwd
    +/* Create context package */+
    create or replace package user1.pkg_security_context is
    procedure p_set_ctx(
    i_test_a_id      in   user1.test_a.id   %type
    +);+
    end;
    +/+
    create or replace package body user1.pkg_security_context is
    procedure p_set_ctx (
    i_test_a_id      in   user1.test_a.id   %type
    +) is+
    begin
    dbms_session.set_context( 'user1_ctx', 'test_a_id', i_test_a_id );
    end;
    end;
    +/+
    show errors
    +/* Create trigger to set the context before deletion */+
    create or replace trigger user1.test_a_bef_trg
    before delete on user1.test_a
    for each row
    declare
    pragma autonomous_transaction;
    begin
    -- only commits the preceding update, not the delete that fired the trigger.
    commit;
    user1.pkg_security_context.p_set_ctx( :old.id );
    end;
    +/+
    show errors
    create context user1_ctx using user1.pkg_security_context;
    +/* Policy function */+
    create or replace function user1.f_policy_chk_dels (
    object_schema in   varchar2,
    object_name   in   varchar2
    +) return varchar2+
    is
    out_string                 varchar2(400)   default '1=2 ';
    +/*+
    * out_string is the return value.
    *  - 'WHERE 1=2' means 'nothing to access'
    begin
    if ( loc_logged_usr_authorized > 0 ) then
    +/*+
    * Set the flag deleted to 1
    update user1.test_a set deleted = 1 where id = sys_context( 'user1_ctx', 'test_a_id' );
    out_string := out_string || 'or 1=1 ';
    end if;
    return out_string;
    end;
    +/+
    show errors
    +/*+
    * Create policy
    begin
    dbms_rls.add_policy(
    object_schema   => 'user1'                   ,
    object_name     => 'test_a'                  ,
    policy_name     => 'policy_chk_dels'         ,
    function_schema => 'user1'                   , -- function schema
    policy_function => 'f_policy_chk_dels'       , -- policy function
    statement_types => 'DELETE'
    +);+
    end;
    +/+
    When I try to delete a record of the table test_a:
    conn user1/pwd
    SQL> delete from ilogdia.oplsimulaciones sim       where sim.id = 9999;
    +0 rows deleted+
    No rows has been deleted, but the update stmt does not work. That means, the "deleted" flag has not been updated.
    Any ideas?
    Thank you in advance.
    Marco A. Serrano
    Edited by: albrotar on Oct 15, 2012 8:42 AM
    Edited by: albrotar on Oct 15, 2012 8:42 AM
    Edited by: albrotar on Oct 15, 2012 8:43 AM

    The policy function is applied once per statement execution. The policy function executes first and the UPDATE statement, presumably, updates no rows because the context is not yet populated. The row-level populates the context (I'm assuming that your session can even see context values populated by an autonomous transaction-- I would guess it could but I'd have to test that) after the UPDATE statement is already complete. The COMMIT in the row-level trigger is also pointless-- it only applies to changes made by the current autonomous transaction, of which there are none-- it cannot apply to changes made in other autonomous transactions. Declaring the row-level trigger to use autonomous transactions doesn't seem to accomplish anything other than to open the question of whether the values set in the context by the autonomous transaction are visible in the caller's transaction.
    Even if this, somehow, did work, using autonomous transactions would be a very bad idea since Oracle is free to roll-back a partially executed statement (and the work done by its triggers) and re-execute it. Oracle does that with some regularity to maintain write consistency.
    Justin

  • Verification on delete statement

    Hi
    i need a verification on delete statement and am trying to execute this delete using prepareStatement and through parameter passing
    the code is given below.plz do let me know the problem with the statement
    =============================================================
    public int delete(String tableName,String empName){
              int n=0;
              System.out.println("Starting!!!delete");
              try{
                   /*stmnt=con.createStatement();
                   stmnt.executeUpdate("delete from Employees where Name= 'jaggu'");*/
                   stmt=con.prepareStatement("delete from ? where Name = ? ");
                   stmt.setString(1, tableName);
                   stmt.setString(2, empName);
                   n=stmt.executeUpdate();
              System.out.println("Deletion Done!!!");
              }catch(Exception e){
                   System.out.println("Error on deletion :"+e);
              return n;
    ===========================================================
    the error being displayed is:
    Error on deletion :java.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' where Name = ''' at line 1"
    PLZ DO LET ME KNOW WHAT IS WRONG HERE!!!

    yes tat was the problem and now i got it rectified.. for more dynamisation u can use the following code. If so u can delete any row based on the column value from any table...plz tell whether its looking fine or not:
         public int delete(String tableName,String empName){
              int n=0;
              System.out.println("Starting!!!delete");
              try{
                   stmt=con.prepareStatement("delete from "+tableName+" where name = ?");
                   stmt.setString(1, empName);
                   n=stmt.executeUpdate();
              System.out.println("Deletion Done!!!");
              }catch(Exception e){
                   System.out.println("Error on deletion :"+e);
              return n;
         }

  • Problem with delete statement

    Hi there, I have created this code below.  The select statement works, however the delete statement does not work.
    DECLARE
    @CategoryASVARCHAR(255)
    DECLARE
    @NameASVARCHAR(255)
    DECLARE
    @Name1ASVARCHAR(255)
    DECLARE
    @ParentTypeAsint
    SET
    @Category='General
    Building Data'
    SET
    @Name='Purchase
    Date'
    SET
    @Name1='Purchase
    Cost'
    Set
    @ParentType=20
    Select
    *fromtbAttributeValueA
    Join
    tbAttributeTemplateDefinitionLinkATDLONATDL.AttributeTemplateDefinitionLinkID=A.AttributeTemplateDefinitionLinkID
    Join
    tbAttributeTemplateDefinitionATDONATD.AttributeTemplateDefinitionID=ATDL.AttributeTemplateDefinitionID
    JOIN
    tbAttributeSetSONS.AttributeSetID=ATDL.LinkedParentID
    Where
    S.ParentType=@ParentType
    AND
    S.Name=@Category
    AND
    ([email protected]=@Name1)
    AND
    A.Value=0
    delete
    fromtbAttributeValueA
    Join
    tbAttributeTemplateDefinitionLinkATDLONATDL.AttributeTemplateDefinitionLinkID=AttributeTemplateDefinitionLinkID
    Join
    tbAttributeTemplateDefinitionATDONATD.AttributeTemplateDefinitionID=ATDL.AttributeTemplateDefinitionID
    JOIN
    tbAttributeSetSONS.AttributeSetID=ATDL.LinkedParentID
    Where
    S.ParentType=@ParentType
    AND
    S.Name=@Category
    AND
    ([email protected]=@Name1)
    AND
    A.Value=0
    The delete statement fails on the first join.     Incorrect Syntax near 'A'.  What am I doing wrong?  As I have only changed the select * to delete.  So therefore does this mean I need to put the delete statement into a
    sql sub query? Or is there another way of doing this?

    Try this:
    DELETE FROM tbAttributeValue
    FROM tbAttributeTemplateDefinitionLink ATDL
    JOIN tbAttributeValue t
    ON ATDL.AttributeTemplateDefinitionLinkID = t. AttributeTemplateDefinitionLinkID
    JOIN tbAttributeTemplateDefinition ATD
    ON ATD.AttributeTemplateDefinitionID = ATDL.AttributeTemplateDefinitionID
    JOIN tbAttributeSet S
    ON S.AttributeSetID = ATDL.LinkedParentID
    WHERE S.ParentType = @ParentType
    AND S.NAME = @Category
    AND ( ATD.NAME = @Name
    OR ATD.NAME = @Name1 )
    AND A.Value = 0

  • Help on delete statement

    hi
    I need to maintain records in a table1 only latest 2 records .
    remaining i nee to delete
    can any one help me out in delete statement
    Table1 contains below columns
    empno deptno lastupdatedate

    The below query will delete all the rows except the 2 latest record -
    DELETE TABLE1
    WHERE (EMPNO, DEPTNO, LASTUPDATEDATE) NOT IN (
    SELECT EMPNO, DEPTNO, LASTUPDATEDATE
    FROM (SELECT EMPNO, DEPTNO, LASTUPDATEDATE
    FROM TABLE1
    ORDER BY LASTUPDATEDATE DESC)
    WHERE ROWNUM <= 2);
    There is similar thread already answered for this. You can refer the below link -
    Performing Top-N Analysis

Maybe you are looking for

  • Remote_user not passed in reverse proxy

    Hi Team, Our webserver is ARR enables.Trying to setup the reverse proxy but  using urlrewrite.Request reaches the backend server but the Request header Remote_user is empty.Any workaround to pass the value to the Backend server. Do i need to build a

  • I need to know when a bookmark, I bookmarked was created...

    How can I tell when I bookmarked, a certain bookmark? I want to find out the specfic time I bookmarked a page can I do this? Thanks

  • Printed documentation does not display some images in PDF

    Some of the images in my printed documentation do not display in my PDF. The majority of the images display fine, but a few are missing. There is a gap where the image is supposed to appear, but no image displays. Am using RoboHelp 6.0 for HTML

  • Managing File Sharing via WGM

    I can't see a way to do this, but I thought I might as well ask... Is it possible to manage Sharing preferences from WGM? I want to ensure that users cannot turn on personal file sharing, but they have a need to be able to access the preference pane

  • FM To Find Opening Stock

    Is There Any FM To Find Opening Stock in Given Date