SQL - Rollback and Commit

Hi,
What exactly does Rollback do?  I know that COMMIT applies the changes to the database system.  The thing is, I've read that until commit is applied, the database in permanent storage is unchanged.  So what exactly does a ROLLBACK
"roll back"?  Does it rollback the changes made to the data tables that have been loaded into RAM?
Thanks
Joe

So what you're saying is that even though I'm in transaction mode and haven't done a commit or rollback, the database on the hard disk can still be affected by the transaction.
So when I do a COMMIT, then all remaining changes in memory are applied to the database and when I ROLLBACK, any changes done both to the database and the tables in RAM are undone?
Do I understand this right?
Thanks!
Yes, when you are in a transaction and you make a change to a database page, before SQL makes that change, it, of course, must have that page in memory.  The change is then made in memory.  But if there is a lot of memory pressure, that page in
memory can be written to disk even though the transaction is still open. 
When you do a commit, the rows are unlocked and available to other processes, but if the changed rows are in memory and not yet written to disk, they are not necessarily immediately written to disk.  They may stay in memory and be written to disk at
a later time.  They will be written back to disk either when SQL needs that memory for something else, or SQL has some unused I/O time that is not needed for other processes, or a CHECKPOINT occurs.  In essence, a checkpoint forces all committed
changes (CORRECTION -thanks Shanky_621 - all changes (whether committed or not (the rules for tempdb are a little different)) to be written to disk.  You may want to see
http://technet.microsoft.com/en-us/library/ms189573.aspx for a description of checkpoints.
What is guaranteed to be written to disk when you do a commit is the log records needed to reproduce the change.  And if an uncommitted change is written to disk, that change is also logged before it is written to the database.
The reason for that is when your system unexpectedly crashes, there can be uncommitted changes that have been written to disk and committed changes that were in memory and not on disk.  If this happens, the next time you bring up SQL Server it examines
the log.  Any uncommitted change that got written to disk is reversed and any committed change which was never written to disk is applied to the disk.  That allows SQL Server to insure that every committed change is on the disk and only committed
changes are on disk.
All of this is, of course, complex.  But there is a reason for it.  Usually, the bottleneck in database systems is the disk I/O system.  So SQL server has a lot of complex algorithms to make disk I/O as efficient as possible.  The good
news is that in most cases you can ignore all of this.  Most of it you have no control over.  There are some things you can tweak.  The primary one is the amount of memory you let SQL Server use.  Also, you can change the CHECKPOINT interval
(which essentially lets you make tradeoffs between how efficient normal processing is vs the length of time it can take to recover after a system failure.  But the default value for CHECKPOINT interval works fine in most cases.
Tom

Similar Messages

  • PL/SQL CLOB and comma seperated list

    Hi,
    i´am beginner!
    I have a table with a clob field with a comma separeted list. The content can be '', '44' or '44,55...' as an example.
    So how can i get the values in clob and search another table?
    Something like...
    select clob from table1
    each clob
    select * from table2
    where table2.id = (clob value)
    ... do somtheing further
    Thank you,
    Jochen

    Ok... it depends...
    If you know your CLOB is going to hold a list of values that are less than 4000 characters, you can simply treat the CLOB as a VARCHAR2 and perform one of the many techniques for splitting that string to give a varying IN list...
    e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  select *
      2  from emp
      3  where ename in (
      4    with t as (select '&input_string' as txt from dual)
      5    select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
      6    from t
      7    connect by level <= length(regexp_replace(txt,'[^,]*'))+1
      8*   )
    SQL> /
    Enter value for input_string: SCOTT,JAMES
    old   4:   with t as (select '&input_string' as txt from dual)
    new   4:   with t as (select 'SCOTT,JAMES' as txt from dual)
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7788 SCOTT      ANALYST         7566 19-04-1987 00:00:00       3000                    20
          7900 JAMES      CLERK           7698 03-12-1981 00:00:00        950                    30
    SQL>(or alternatively read here: http://tkyte.blogspot.com/2006/06/varying-in-lists.html)
    If it's going to exceed the SQL VARCHAR2 limit of 4000 characters then you would most likely need to create a Pipelined function to split your CLOB into it's component values and return each one, thus allowing you to treat the results as a table of their own... e.g.
    Note: this example is for a pipelined function that splits a varchar2 string, but you could adapt it to use the DBMS_LOB package to split a CLOB in the same manner...
    SQL> CREATE OR REPLACE TYPE split_tbl IS TABLE OF VARCHAR2(4000);
      2  /
    Type created.
    SQL> CREATE OR REPLACE FUNCTION split (p_list VARCHAR2, p_delim VARCHAR2:=' ') RETURN SPLIT_TBL PIPELINED IS
      2      l_idx    PLS_INTEGER;
      3      l_list   VARCHAR2(4000) := p_list;
      4      l_value  VARCHAR2(4000);
      5    BEGIN
      6      LOOP
      7        l_idx := INSTR(l_list, p_delim);
      8        IF l_idx > 0 THEN
      9          PIPE ROW(SUBSTR(l_list, 1, l_idx-1));
    10          l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
    11        ELSE
    12          PIPE ROW(l_list);
    13          EXIT;
    14        END IF;
    15      END LOOP;
    16      RETURN;
    17    END SPLIT;
    18  /
    Function created.
    SQL> SELECT column_value
      2  FROM TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    COLUMN_VALUE
    FRED
    JIM
    BOB
    TED
    MARK
    SQL> create table mytable (val VARCHAR2(20));
    Table created.
    SQL> insert into mytable
      2  select column_value
      3  from TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    5 rows created.
    SQL> select * from mytable;
    VAL
    FRED
    JIM
    BOB
    TED
    MARK
    SQL>... and once you can treat the values like a table it's just a case of using it like you would any table of values i.e. join on it or use it in an IN statment with a subselect etc.

  • Oracle SQL Developer and commit

    I have the auto commit in SQL Worksheet unchecked and disconnect a worksheet with open transaction and the data is commited !!
    I have to set another option??
    When I close the SQL Developer no questions if I'm sure to close or i want to perform a commit (like toad).
    Thanks.

    you may want to try this forum:
    SQL Developer

  • SQL loader and commit

    Hi,
    I am trying to execute a sql loader script that populates many tables. The order of the tables in the script is very important because the table of the last table has a constraint with the first table of the script. So I need that sqlloader executes a commit after the filling of the first tables because if sql loader executes the script simply as it is written the last tables launches an error because the constraint is violated (the last table sees the first one empty).
    How can I force a commit after a filling in sql loader?
    The sctructure of the tables was not defined by me so I must not modify it (constraint included).
    Thanks, bye bye.

    Hi,
    If you have to enable/disable manually the constraints you can execute:
    DECLARE
      v_ds_action VARCHAR2(7);
    BEGIN
      v_ds_action := 'DISABLE';
        FOR reg IN (SELECT * FROM user_constraints uc WHERE uc.constraint_type = 'R') LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE ' || reg.table_name || ' ' ||
                          v_ds_action || '  CONSTRAINT ' || reg.constraint_name;
      END LOOP;
      FOR reg IN (SELECT * FROM user_constraints uc WHERE uc.constraint_type = 'C') LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE ' || reg.table_name || ' ' ||
                          v_ds_action || '  CONSTRAINT ' || reg.constraint_name;
      END LOOP;
    FOR reg IN (SELECT * FROM user_constraints uc WHERE uc.constraint_type = 'U') LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE ' || reg.table_name || ' ' ||
                          v_ds_action || '  CONSTRAINT ' || reg.constraint_name;
      END LOOP;
      FOR reg IN (SELECT * FROM user_constraints uc WHERE uc.constraint_type = 'P') LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE ' || reg.table_name || ' ' ||
                          v_ds_action || '  CONSTRAINT ' || reg.constraint_name;
      END LOOP;
    END;
    DECLARE
      v_ds_action VARCHAR2(7);
    BEGIN
      v_ds_action := 'ENABLE';
      FOR reg IN (SELECT * FROM user_constraints uc WHERE uc.constraint_type = 'P') LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE ' || reg.table_name || ' ' ||
                          v_ds_action || '  CONSTRAINT ' || reg.constraint_name;
      END LOOP;
      FOR reg IN (SELECT * FROM user_constraints uc WHERE uc.constraint_type = 'U') LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE ' || reg.table_name || ' ' ||
                          v_ds_action || '  CONSTRAINT ' || reg.constraint_name;
      END LOOP;
      FOR reg IN (SELECT * FROM user_constraints uc WHERE uc.constraint_type = 'C') LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE ' || reg.table_name || ' ' ||
                          v_ds_action || '  CONSTRAINT ' || reg.constraint_name;
      END LOOP;
      FOR reg IN (SELECT * FROM user_constraints uc WHERE uc.constraint_type = 'R') LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE ' || reg.table_name || ' ' ||
                          v_ds_action || '  CONSTRAINT ' || reg.constraint_name;
      END LOOP;
    END;
    /Regards,

  • Commit / Rollback  AND  ERROS when to use BULK COLLECT

    Hi
    Where can I to put commit when to use bulk collect for to insert or update ?,
    How many records I to must to commit ?
    declare
    TYPE t_cd_estrutura_comercial IS TABLE OF t_ec_pessoa_perfil_ciclo.cd_estrutura_comercial%TYPE   INDEX BY PLS_INTEGER;
    TYPE t_cd_tipo_estrutura_comercial IS TABLE OF t_ec_pessoa_perfil_ciclo.cd_tipo_estrutura_comercial%TYPE  INDEX BY PLS_INTEGER;
    TYPE t_nm_ciclo_operacional IS TABLE OF  t_ec_pessoa_perfil_ciclo.nm_ciclo_operacional%TYPE   INDEX BY PLS_INTEGER;
    TYPE t_cd_consultora IS TABLE OF t_ec_pessoa_perfil_ciclo.cd_consultora%TYPE  INDEX BY PLS_INTEGER;
    TYPE t_cd_perfil IS TABLE OF t_ec_pessoa_perfil_ciclo.cd_perfil%TYPE  INDEX BY PLS_INTEGER;
    TYPE t_cd_indicador IS TABLE OF t_ec_pessoa_perfil_ciclo.cd_indicador%TYPE  INDEX BY PLS_INTEGER;
    TYPE t_vl_indicador IS TABLE OF t_ec_pessoa_perfil_ciclo.vl_indicador%TYPE  INDEX BY PLS_INTEGER;
    TYPE t_dt_ultima_atualizacao IS TABLE OF t_ec_pessoa_perfil_ciclo.dt_ultima_atualizacao%TYPE   INDEX BY PLS_INTEGER;
    v_cd_estrutura_comercial t_cd_estrutura_comercial;
    v_cd_tipo_estrutura_comercial t_cd_tipo_estrutura_comercial;
    v_nm_ciclo_operacional t_nm_ciclo_operacional;
    v_cd_consultora t_cd_consultora;
    v_cd_perfil t_cd_perfil;
    v_cd_indicador t_cd_indicador;
    v_vl_indicador t_vl_indicador;
    v_dt_ultima_atualizacao t_dt_ultima_atualizacao;
    V_CURSOR  SYS_REFCURSOR;
    n  pls_integer :=0;
    begin
      ---open v_cursor 
      pkg_scnob_batch_indicadores.abre_cursor(275,v_cursor);
       LOOP
       FETCH V_CURSOR   BULK COLLECT INTO
         v_cd_estrutura_comercial,
         v_cd_tipo_estrutura_comercial,
         v_nm_ciclo_operacional,
         v_cd_consultora,
         v_cd_perfil,
         v_cd_indicador,
         v_vl_indicador,
         v_dt_ultima_atualizacao  LIMIT 1000;
           FORALL i IN 1 .. v_cd_estrutura_comercial.COUNT
              MERGE
                 INTO T_EC_PESSOA_PERFIL_CICLO tgt
                 USING ( SELECT v_cd_estrutura_comercial(i) cd_estrutura_comercial,                           
                          v_cd_tipo_estrutura_comercial(i) cd_tipo_estrutura_comercial,                      
                         v_nm_ciclo_operacional(i) nm_ciclo_operacional,                             
                         v_cd_consultora(i) cd_consultora,                                    
                         v_cd_perfil(i)    cd_perfil,                                       
                         v_cd_indicador(i) cd_indicador,                                     
                         v_vl_indicador(i) vl_indicador,                                     
                         v_dt_ultima_atualizacao(i) dt_ultima_atualizacao FROM  dual ) src
                 ON   (   src.CD_ESTRUTURA_COMERCIAL            = TGT.CD_ESTRUTURA_COMERCIAL        
                          AND src.CD_TIPO_ESTRUTURA_COMERCIAL   = TGT.CD_TIPO_ESTRUTURA_COMERCIAL   
                          AND src.NM_CICLO_OPERACIONAL          = TGT.NM_CICLO_OPERACIONAL          
                          AND src.CD_CONSULTORA                 = TGT.CD_CONSULTORA                 
                          AND src.CD_PERFIL                     = TGT.CD_PERFIL                     
                          AND  src.CD_INDICADOR                 = TGT.CD_INDICADOR  )
              WHEN MATCHED
              THEN
                UPDATE
                 SET TGT.VL_INDICADOR  = src.VL_INDICADOR ,                             
                     TGT.DT_ULTIMA_ATUALIZACAO  = src.DT_ULTIMA_ATUALIZACAO                     
              WHEN NOT MATCHED
              THEN
                 INSERT (tgt.CD_ESTRUTURA_COMERCIAL,                           
                         tgt.CD_TIPO_ESTRUTURA_COMERCIAL,                      
                         tgt.NM_CICLO_OPERACIONAL,                             
                         tgt.CD_CONSULTORA,                                    
                         tgt.CD_PERFIL ,                                       
                         tgt.CD_INDICADOR,                                     
                         tgt.VL_INDICADOR,                                     
                         tgt.DT_ULTIMA_ATUALIZACAO)                            
                 VALUES (src.CD_ESTRUTURA_COMERCIAL,                           
                         src.CD_TIPO_ESTRUTURA_COMERCIAL,                      
                         src.NM_CICLO_OPERACIONAL,                             
                         src.CD_CONSULTORA,                                    
                         src.CD_PERFIL ,                                       
                         src.CD_INDICADOR,                                     
                         src.VL_INDICADOR,                                     
                         src.DT_ULTIMA_ATUALIZACAO) ;
               -- Did I to must commit here ?     
               --         commit;
           n := n + SQL%ROWCOUNT;
        EXIT WHEN  V_CURSOR%NOTFOUND; 
      END LOOP; 
    exception
       when others then
           rollback;  -- and log errors
    end;

    There is a lot of questions like this
    Actually there no precise max of records to be committed
    The COMMIT

  • Are the Pl/sql procedure and function atomic by themself

    i want to ask a question does oracle pl/sql procedure and function support Atomicity for the database by themself , or they became atomic incase we call them using begin -- end;

    You appear to be discussing transaction scope which is completely independent of PL/SQL blocks like procedures or how you call procedures. It's all in where commits (or rollbacks) are issued.
    If you have a procedure like this
    CREATE PROCEDURE p1
    AS
    BEGIN
      INSERT INTO some_table( key, value ) VALUES( 1, 'Foo' );
      INSERT INTO some_table( key, value ) VALUES( 1, 'Bar' );
    END;where the first statement succeeds and the second statement fails as a result of a duplicate key, there will still be a Foo row in the table but the procedure will have thrown an exception. The caller of the procedure may choose to commit or rollback the change-- that will determine whether the first statement's results are made permanent. If you have a procedure like this,
    CREATE PROCEDURE p1
    AS
    BEGIN
      INSERT INTO some_table( key, value ) VALUES( 1, 'Foo' );
      commit;
      INSERT INTO some_table( key, value ) VALUES( 1, 'Bar' );
    END;the commit will make the first insert permanent regardless of whether the second statement fails no matter what the calling code does (that's one reason that putting commits in stored procedures is generally a bad idea-- the caller is in a much better position to know what other uncommitted work has been done and whether it is safe to commit.
    Justin

  • Problem with sqlldr and commit

    Hi,
    i have a problem with sqlldr and commit.
    I have a simple table with one colum [ col_id number(6) not null ]. The column "col_id" is primary key in the table. I have one file with 100.000 records ( number from 0 to 99.999 ).
    I want load the file in the table with sqlldr ( sql*loader ) but i want commit only if all records are loaded. If one record is discarded i want discarded all record of file.
    The proble is that in coventional path the commit is on 64 row but if i want the same records of file isn't possible and in direct path sqlldr disable primary key :(
    There are a solutions?
    Thanks
    I'm for the bad English

    This is my table:
    DROP TABLE TEST_SQLLOADER;
    CREATE TABLE TEST_SQLLOADER
    (     COL_ID NUMBER NOT NULL,
         CONSTRAINT TEST_SQLLOADER_PK PRIMARY KEY (COL_ID)
    This is my ctlfile ( test_sql_loader.ctl )
    OPTIONS
    DIRECT=false
    ,DISCARDMAX=1
    ,ERRORS=0
    ,ROWS=100000
    load data
    infile './test_sql_loader.csv'
    append
    into table TEST_SQLLOADER
    fields terminated by "," optionally enclosed by '"'
    ( col_id )
    test_sql_loader.csv
    0
    1
    2
    3
    99999
    i run sqlloader
    sqlldr xxx/yyy@orcl control=test_sql_loader.ctl log=test_sql_loader.log
    output on the screen
    Commit point reached - logical record count 92256
    Commit point reached - logical record count 93248
    Commit point reached - logical record count 94240
    Commit point reached - logical record count 95232
    Commit point reached - logical record count 96224
    Commit point reached - logical record count 97216
    Commit point reached - logical record count 98208
    Commit point reached - logical record count 99200
    Commit point reached - logical record count 100000
    Logfile
    SQL*Loader: Release 11.2.0.1.0 - Production on Sat Oct 3 14:50:17 2009
    Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
    Control File: test_sql_loader.ctl
    Data File: ./test_sql_loader.csv
    Bad File: test_sql_loader.bad
    Discard File: none specified
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 0
    Bind array: 100000 rows, maximum of 256000 bytes
    Continuation: none specified
    Path used: Conventional
    Table TEST_SQLLOADER, loaded from every logical record.
    Insert option in effect for this table: APPEND
    Column Name Position Len Term Encl Datatype
    COL_ID FIRST * , O(") CHARACTER
    value used for ROWS parameter changed from 100000 to 992
    Table TEST_SQLLOADER:
    100000 Rows successfully loaded.
    0 Rows not loaded due to data errors.
    0 Rows not loaded because all WHEN clauses were failed.
    0 Rows not loaded because all fields were null.
    Space allocated for bind array: 255936 bytes(992 rows)
    Read buffer bytes: 1048576
    Total logical records skipped: 0
    Total logical records read: 100000
    Total logical records rejected: 0
    Total logical records discarded: 0
    Run began on Sat Oct 03 14:50:17 2009
    Run ended on Sat Oct 03 14:50:18 2009
    Elapsed time was: 00:00:01.09
    CPU time was: 00:00:00.06
    The commit is on 992 row
    if i have error on 993 record i have commit on first 992 row :(
    Edited by: inter1908 on 3-ott-2009 15.00

  • SQL Loader and APEX

    Is it possible to use the SQL Loader within APEX? I want to have a table updated from a csv file... normally I would use the WWV_FLOW_FILES table, but with this file it mixes tabs and commas within the data, so creating a reliable upload script is getting to be a complete nightmare. I'd like to leverage the sql loader so I can specify the delimiter, optional quotes etc. The file will be in the same location on the file system so a scheduled, automated process would be perfect.
    If so, does anyone know of a tutorial that might help me out?

    I really hate computers. I do. I should know by now that it would of course install properly once support is engaged.
    It installed properly just now. I was installing to get the error message to send to you. No changes were made yesterday, it's the same schema, same options for installing. I didn't restart any services or reboot the server.
    It just works now.
    I've been working with computers since 1982 and their capacity for knowing when support people are around continues to astonish me.
    I am getting 'no data found' but I was really only installing it to get the error message, so I may have skipped a step.
    Thanks all for the prompt replies.

  • JClient: after INSERT and COMMIT does not show the primary textfield value

    1. In my JClient master-detail form: When I insert a new record, enter data, and commit the changes... the master-panel's primarykey textfield is BLANK, when it should show the new auto-incremented number from the MySQL database. I have to close and open the form again to refresh that field again.
    2. In order to properly save new records in the detail-panel, I have to insert and save the above master-panel first. Is this the way JCLient handle master-detail forms?
    Thanks.

    Hi. Thanks for sharing your advice.
    Re my problem,
    if we have to refresh data by requery,i suggest you should use the way below:
    private JUNavigationBar navBar = new JUNavigationBar(true,false,true,false,true);
    navBar.setModel(JUNavigationBar.createPanelBinding(panelBinding, navBar));
    // after insert ,call this method
    navBar.doAction(navBar.BUTTON_EXECUTE);Tried this out but my textfield still won't get refreshed. Here is the code I came up with:
        private JUNavigationBar navBar = new JUNavigationBar() {
                public void doAction(int button) {
                    if (button == JUNavigationBar.BUTTON_INSERT) {
                        super.doAction(button);
                        navBar.doAction(navBar.BUTTON_EXECUTE);
                        return;
                    super.doAction(button);
            };Re your problem,
    I am developing application with JDev + MySQL,encounted another problem,
    how can i get the primary key supported by auto_increment column after insert?
    i constructed a vo whose sql statement is
    select last_insert_id() as last_id to get the value of auto_increment column.
    i found it can't get the right value unless commit the transaction.
    Would u please tell me your way?Based on what I experienced, we dont have to do the SELECT statement above. MySQL does auto-increment the primarykey but the JClient form just cant show it immediately, unless we close and re-open the form.
    What did I do to refresh the primarykey during insert? Please note that I got this solution accidentally coz I'm still a newbie in Java.
    A user want to add a record:
    1. He presses the Insert button.
    2. He enters data into a component (ex. textfield)
    3. The component's action-performed event is fired, and the following code is run:
            DCJboDataControl dc = (DCJboDataControl)panelBinding.getDataControl();
            ApplicationModule am = dc.getApplicationModule();
            Transaction tr = am.getTransaction();
            dc.commitTransaction();
            ViewObject vo = am.findViewObject("TblaccountsView1");
            vo.executeQuery();
            vo.last();It simply commits the transaction, goes to last (new) transaction, and lets the user continue his data encoding.
    Hope it helps and I hope theres an even better way to do this.

  • Advice on SQL Logs and Backups

    Hi All,
    I've been trying to understand SQL backups and I'm getting a bit stuck in one area - the log files.
    I find they're getting quite big and as such filling up my drives. I'm guessing that the best way to handle this is to truncate them every so often - as the data is in the live DB I'm assuming that the log files should be small.
    Q1 - I do daily full backups on my DB's via a maintenance plan so is it safe to say that the log files can be truncated daily?
    Q2 - How do I go about truncating the logs? I tried a backup of them but I'm not sure what to do next.
    Thanks for any help.
    Tom

      This can cause fragmentation and performance issues. Truncating the log is what happens when you take a backup.
    Prashanth,
    Shrinking log file does not causes fragmentation ( if you shrink data file it does cause) but your are correct that Shrinking log fiel should not be made every day practice.After shrinking when log file tries to grow it has to ask OS to allocate it space
    which if done frequently ( on slower disk) can cause performance issue.
    Tom,
    >>I do daily full backups on my DB's via a maintenance plan so is it safe to say that the log files can be truncated daily?
    A:NO only transaction log truncates log file ( or marks it reusable).So you have to take transaction log backup frequently( hope your DB is in full recovery).If your DB is in simple recovery automatic truncation happens and SQL server takes care of it after
    checkpoint or when log grows 70 % of it size.
    >>Q2 - How do I go about truncating the logs? I tried a backup of them but I'm not sure what to do next.
    Again answer is simple take transaction log backup frequently or according to your RPO and RTO
    PS: Sometimes when there is long running transaction like huge delete operation,index rebuild of huge database log might grow even frequent transaction log backup is there this is by design because unless transaction finishes or commits logs cannot be truncated
    so if you face it look for open transaction and wait for it to commit.
    Hope this helps
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Rollback and Scheduling in Database?

    If we use the Timestamp Ordering for concurrency control in following scheduling:
    http://oi59.tinypic.com/260361k.jpg
    My note says T2,T3,T5 is Run and T4,T5 is Rollback. I think it's false. any expert could help us? (i.e, in this schedule which of the Transaction Rollback and which one Is Done?

    ISolation Level is not defined. would you please a default setting and consider more hint for me? why some rollback in this senario ?
    default is read committed isolation. you are not helping us and yourself by not posting the details.
    please post actual sql statements.. you can replace actual table names/column names to dummy names...
    in forums, people(answerers) already do some sort of half guesses  to interpret on question - on what might be issue(s).  you can help us and yourself by providing more details and sql statements...
    Hope it Helps!!

  • Begin and Commit Transactions

    I would like to use the begin and commit transaction in stored procedures in T-SQL. I wanted to know if I can put it around a few statements at once and so if there is an error in one of them none of the above statements will save and the procedure will
    terminate. Will this work with just a begin transaction before all the statements and a commit transaction at the end of all the statements and if there is an error nothing will save, or is there more to it?
    thank you
    Debra has a question

    Add also SET XACT_ABORT ON statement in your procedure.
    I suggest you to read this very interesting article Structured
    Error Handling Mechanism in SQL Server 2012, it should tell you everything you need to know.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • SQL%FOUND and SQL%NOTFOUND

    Hi,
    My friend asked me this question.
    Why we hav these two attributes?SQL%FOUND and SQL%NOTFOUND
    One will always be the opposite of the other.So one will suffice our need, no?
    Thanks..

    declare
         print varchar2(32);
    begin
         delete
         from scott.emp
         where empno = 1000;
         if ( SQL%FOUND ) then
              print := 'found';
         else
              print := 'not_found';
         end if;
         if ( SQL%NOTFOUND ) then
              print := print||' and not_found';
         else
              print := print||' and found';
         end if;
         dbms_output.put_line(print);
         delete
         from scott.emp;
         if ( SQL%FOUND ) then
              print := 'found';
         else
              print := 'not_found';
         end if;
         if ( SQL%NOTFOUND ) then
              print := print||' and not_found';
         else
              print := print||' and found';
         end if;
         dbms_output.put_line(print);
         delete
         from scott.emp;
         if ( SQL%FOUND ) then
              print := 'found';
         else
              print := 'not_found';
         end if;
         if ( SQL%NOTFOUND ) then
              print := print||' and not_found';
         else
              print := print||' and found';
         end if;
         dbms_output.put_line(print);
         rollback;
    end;
    not_found and not_found
    found and found
    not_found and not_foundIt seesm that one is allways the opposite of the ather one. There are no exception.
    Bye Alessandro

  • Passing arrays through multiple PL/SQL procedures and functions

    I am maintaining a large PL/SQL application. There is a main procedure that is initially called which subsequently passes information to other PL/SQL functions and procedures. In the end an error code and string is passed to PUT_LINE so it can be displayed. What I would like to be able to do is have an array that stores an error code and string for each error that it comes upon during going through each of the procedures and functions. This would involve passing these codes and strings from function to function within the pl/sql application. What would be the best way to implement this and is it possible to pass arrrays or records to other PL/SQL functions? Thanks.

    Here is one simulation ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:00.20
    satyaki>
    satyaki>
    satyaki>create or replace type n_array is table of number;
      2  /
    Type created.
    Elapsed: 00:00:07.10
    satyaki>
    satyaki>CREATE OR REPLACE PROCEDURE Get_Array(array_in IN n_array,
      2                                        array_out OUT n_array)  
      3  IS
      4  BEGIN 
      5    array_out := n_array(); 
      6    FOR i IN 1..array_in.count 
      7    LOOP 
      8      array_out.extend; 
      9      array_out(i) := array_in(i) * 2; 
    10    END LOOP;
    11  END Get_Array;
    12  /
    Procedure created.
    Elapsed: 00:00:00.89
    satyaki>
    satyaki>
    satyaki>Create or Replace Procedure Set_Array(myArray IN n_array)
      2  is  
      3    i   number(10);  
      4    rec emp%rowtype;  
      5    w n_array:=n_array(1200,3200);
      6    bucket n_array := n_array();
      7  Begin
      8    Get_Array(w,bucket);  
      9   
    10    for i in 1..myArray.count  
    11    loop 
    12      select *  
    13      into rec 
    14      from emp 
    15      where empno = myArray(i); 
    16      dbms_output.put_line('Employee No:'||rec.empno||' Name:'||rec.ename);
    17      for j in 1..bucket.count
    18      loop
    19        dbms_output.put_line('Commission Sub Type: '||bucket(j));
    20      end loop;
    21    end loop; 
    22  End Set_Array;
    23  /
    Procedure created.
    Elapsed: 00:00:01.33
    satyaki>
    satyaki>
    satyaki>select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          9999 SATYAKI    SLS             7698 02-NOV-08      55000       3455         10
          7777 SOURAV     SLS                  14-SEP-08      45000       3400         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       4450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       7000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
    13 rows selected.
    Elapsed: 00:00:00.28
    satyaki>
    satyaki>declare
      2    v n_array:=n_array(9999,7777);  
      3  begin  
      4    Set_Array(v);  
      5  end;
      6  /
    Employee No:9999 Name:SATYAKI
    Commission Sub Type: 2400
    Commission Sub Type: 6400
    Employee No:7777 Name:SOURAV
    Commission Sub Type: 2400
    Commission Sub Type: 6400
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.15
    satyaki>
    satyaki>Regards.
    Satyaki De.

  • Rollback and UNDO

    Hi,
    I'm confuse about Rollback and Undo concepts, can some one explain it to me please?
    Felipe :)

    This is a copy of a previous post I made some time ago:
    There might be confusion while undo and rollback segment terms are used interchangeably in db world. It is due to the compatibility issue of oracle.
    Undo
    Oracle Database must have a method of maintaining information that is used to roll back, or undo, changes to the database. Such information consists of records of the actions of transactions, primarily before they are committed. These records are collectively referred to as undo.
    Undo records are used to:
    * Roll back transactions when a ROLLBACK statement is issued
    * Recover the database
    * Provide read consistency
    * Analyze data as of an earlier point in time by using Flashback Query
    When a ROLLBACK statement is issued, undo records are used to undo changes that were made to the database by the uncommitted transaction. During database recovery, undo records are used to undo any uncommitted changes applied from the redo log to the datafiles. Undo records provide read consistency by maintaining the before image of the data for users who are accessing the data at the same time that another user is changing it.
    Undo vs Rollback
    Earlier releases of Oracle Database used rollback segments to store undo. Oracle9i introduced automatic undo management, which simplifies undo space management by eliminating the complexities associated with rollback segment management. Oracle strongly recommends (Oracle 9i and on words) to use undo tablespace (automatic undo management) to manage undo rather than rollback segments.
    To see the undo management mode and other undo related information of database-
    SQL> show parameter undo
    NAME TYPE VALUE
    undo_management string AUTO
    undo_retention integer 900
    undo_tablespace string UNDOTBS1
    Since the advent of Oracle9i, less time-consuming and suggested way is—using Automatic Undo Management—in which Oracle Database creates and manages rollback segments (now called “undo segments”) in a special-purpose undo tablespace. Unlike with rollback segments, we don’t need to create or manage individual undo segments—Oracle Database does that for you when you create the undo tablespace. All transactions in an instance share a single undo tablespace. Any executing transaction can consume free space in the undo tablespace, and when the transaction completes, its undo space is freed (depending on how it’s been sized and a few other factors, like undo retention). Thus, space for undo segments is dynamically allocated, consumed, freed, and reused—all under the control of Oracle Database, rather than manual management by someone.
    Switching Rollback to Undo
    1. We have to create an Undo tablespace. Oracle provides a function (10g and up) that provides information on how to size new undo tablespace based on the configuration and usage of the rollback segments in the system.
    DECLARE
    utbsiz_in_MB NUMBER;
    BEGIN
    utbsiz_in_MB ;= DBMS_UNDO_ADV.RBU_MIGRATION;
    end;
    CREATE UNDO TABLESPACE UNDOTBS
    DATAFILE ‘/oradata/dbf/undotbs_1.dbf’
    SIZE 100M AUTOEXTEND ON NEXT 10M
    MAXSIZE UNLIMITED RETENTION NOGUARANTEE;
    Note: In undo tablespace creation, “SEGMENT SPACE MANAGEMENT AUTO” can not be set
    2.Change system parameters
    SQL> alter system set undo_retention=900 scope=both;
    SQL> alter system set undo_tablespace=UNDOTBS scope=both;
    SQL> alter system set undo_management=AUTO scope=spfile;
    SQL> shutdown immediate
    SQL> startup
    UNDO_MANAGEMENT is a static parameter. So database needs to be restarted.
    Reference: 10gR2 Administration Guide and Concepts
    Regards,
    Francisco Munoz Alvarez

Maybe you are looking for