SCN_TO_TIMESTAMP

Hi,
in 10g R2 , how can I use SCN_TO_TIMESTAMP to have a timestape for a given SCN (without using it in a select ) ?
Suppose I have just SCN which is 234567 and I want to know to which timestamp it correspond. How do I use SCN_TO_TIMESTAMP ?
Thank you.

Thank you.
But nothing is displayed :
SQL> DECLARE
  2             v_timestamp     TIMESTAMP;
  3              v_scn           NUMBER;
  4      BEGIN
  5              /* Setup */
  6              v_scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER;
  7
  8              v_timestamp := SCN_TO_TIMESTAMP(245044501);
  9
10             DBMS_OUTPUT.PUT_LINE(v_timestamp);
11     END;
12     /
PL/SQL procedure successfully completed.
SQL>
SQL> DECLARE
  2             v_timestamp     TIMESTAMP;
  3              v_scn           NUMBER;
  4      BEGIN
  5              /* Setup */
  6              v_scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER;
  7
  8              v_timestamp := SCN_TO_TIMESTAMP(v_scn);
  9
10             DBMS_OUTPUT.PUT_LINE(v_timestamp);
11     END;
12     /
PL/SQL procedure successfully completed.

Similar Messages

  • SCN_TO_TIMESTAMP and TIMESTAMP_TO_SCN Behaviour

    Dear all,
    I'm trying to understand how both SCN_TO_TIMESTAMP and TIMESTAMP_TO_SCN work by executing the following:
    SQL> select scn_to_timestamp(ora_rowscn) test, last_name from employees where la
    st_name='King';
    TEST                 LAST_NAME
    16-DEC-10 01.34.23.0 King
    00000000 PM
    16-DEC-10 01.34.23.0 King
    00000000 PM
    SQL> select ora_rowscn, last_name from employees where last_name='King';
    ORA_ROWSCN LAST_NAME
        559374 King
        559374 King
    SQL> select timestamp_to_scn('16-DEC-10 01.34.23.000000000 PM') from dual;
    TIMESTAMP_TO_SCN('16-DEC-1001.34.23.000000000PM')
                                               559370why doesn't the last query resulting 559374 but instead 559370?
    best regards,
    valerie

    Hi,
    From the documentation :
    SCN_TO_TIMESTAMP takes as an argument a number that evaluates to a system
    change number (SCN), and returns the approximate timestamp associated with that
    SCN.The important word being approximate.
    You cannot rely on it to be as precise as a systimestamp.
    timestamp_to_scn(scn_to_timestamp(SCN)) == SCN is FALSE
    (even if it might happen to be true sometime...)

  • Scn_to_timestamp and timestamp_to_scn

    Hello,
    I have such strange(?) behaviour in my database
    SQL> select to_timestamp('09.10.2008','dd.mm.yyyy') from dual;
    08/10/09 00:00:00,000000000
    SQL> select timestamp_to_scn(to_timestamp('09.10.2008','dd.mm.yyyy')) from dual;
    612168
    SQL> select scn_to_timestamp(612168) from dual;
    08/10/08 16:19:02,000000000
    I thought that since timestamp_to_scn returns an SCN for the given timestamp, scn_to_timestamp returns the same timestamp for that SCN, but it doesn't. Is it because there's no hour in the timestamp? When I enter a timestamp in 'dd.mm.yyyy hh24:mi:ss' format everything is as it should be.
    Regards,
    Olimpia

    SCN_TO_TIMESTAMP give the timestamp of the given SCN.
    TIMESTAMP_TO_SCN give the highest SCN below the given timestamp.
    Here an example :
    SQL> select scn_to_timestamp(2025400+rownum) tm, timestamp_to_scn(scn_to_timestamp(2025400+rownum)) scn
      2  from   dual
      3  connect by level<=5;
    TM                                                                                 SCN
    09-OCT-08 07.59.16.000000000 PM                                                2025401
    09-OCT-08 07.59.19.000000000 PM                                                2025402
    09-OCT-08 07.59.22.000000000 PM                                                2025403
    09-OCT-08 07.59.25.000000000 PM                                                2025404
    09-OCT-08 07.59.28.000000000 PM                                                2025405Have a look to the last two rows, 3 seconds difference.
    Let's try to see what SCN is given by the a timestamp equal to the last minus one second :
    SQL> select timestamp_to_scn(to_timestamp('09-OCT-08 07.59.27 PM','DD-MON-YY HH12.MI.SS PM')) from dual;
    TIMESTAMP_TO_SCN(TO_TIMESTAMP('09-OCT-0807.59.27PM','DD-MON-YYHH12.MI.SSPM'))
                                                                          2025404It is the second last, the highest SCN below the given timestamp.
    Ok, let's confirm the date given by that SCN:
    SQL> select scn_to_timestamp(2025404) from dual;
    SCN_TO_TIMESTAMP(2025404)
    09-OCT-08 07.59.25.000000000 PMThis is the good one.
    HTH,
    Nicolas.

  • How SCN_TO_TIMESTAMP works?

    I want to get the timestamp of when my row is get updated.
    I am having two records in the table.
    I had updated a one record only using ID.
    Now i am selecting the record when it is updated using the below query.
    SELECT SCN_TO_TIMESTAMP (ORA_ROWSCN)FROM emptable where id=101;
    925472 24-JAN-08 07.23.36.000000000 PM
    But other not updated records also have the same SCN_TO_TIMESTAMP
    SELECT SCN_TO_TIMESTAMP (ORA_ROWSCN)FROM emptable where id=100;
    925472 24-JAN-08 07.23.36.000000000 PM
    Is it is correct? How can i get last udated record
    Thanks

    Generally the SCN is stored for a block, not for each record in the block.
    You can use ROWDEPENDENCIES to track the SCN for each record.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#sthref7718
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14226/repplan.htm#sthref1011
    Really, it would be better to add your own date/timestamp column rather than rely on the Oracle SCN.

  • Scn_to_timestamp(DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER)

    Hi all,
    11.2.0.1
    I read in the docs that there is a function that tagged each row in a table a unique row identifier called scn_to timestamp.
    This is similar to rowid but its sequential. I tried the following command:
    select scn_to_timestamp(DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER) from   EMP  where rownum<101;
    SCN_TO_TIMESTAMP(DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER)
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    21-OCT-13 10.26.46.000000000 AM
    100 rows selected.
    Why are they all duplicate in timestamp? How can I select the next batch excluding the first batch I selected?
    Please help....
    Thanks a lot,
    zxy

    Thanks Al, Justin, Tsh
    You are really all bright boys
    But there is still duplicates how do I select the next batch of 100 without including the first batch? Thanks a lot.
      1* SELECT SCN_TO_TIMESTAMP(ORA_ROWSCN) FROM EMP where rownum<101
    21-OCT-13 07.21.45.000000000 AM
    21-OCT-13 07.21.45.000000000 AM
    21-OCT-13 07.21.45.000000000 AM
    21-OCT-13 07.21.45.000000000 AM
    21-OCT-13 07.21.45.000000000 AM
    21-OCT-13 07.23.00.000000000 AM
    21-OCT-13 07.23.00.000000000 AM
    21-OCT-13 07.23.00.000000000 AM
    21-OCT-13 07.23.00.000000000 AM
    21-OCT-13 07.23.00.000000000 AM
    21-OCT-13 07.23.00.000000000 AM
    21-OCT-13 07.24.27.000000000 AM
    21-OCT-13 07.24.27.000000000 AM
    21-OCT-13 07.24.27.000000000 AM
    21-OCT-13 07.24.27.000000000 AM
    21-OCT-13 07.24.27.000000000 AM
    21-OCT-13 07.25.48.000000000 AM
    21-OCT-13 07.25.48.000000000 AM
    21-OCT-13 07.25.48.000000000 AM
    21-OCT-13 07.25.48.000000000 AM
    21-OCT-13 07.25.48.000000000 AM
    21-OCT-13 07.25.48.000000000 AM
    21-OCT-13 07.02.50.000000000 AM
    21-OCT-13 07.02.50.000000000 AM
    21-OCT-13 07.02.50.000000000 AM
    21-OCT-13 07.02.50.000000000 AM
    21-OCT-13 07.02.50.000000000 AM
    21-OCT-13 07.04.47.000000000 AM
    21-OCT-13 07.04.47.000000000 AM
    21-OCT-13 07.04.47.000000000 AM
    21-OCT-13 07.04.47.000000000 AM
    21-OCT-13 07.04.47.000000000 AM
    21-OCT-13 07.06.26.000000000 AM
    21-OCT-13 07.06.26.000000000 AM
    21-OCT-13 07.06.26.000000000 AM
    21-OCT-13 07.06.26.000000000 AM
    21-OCT-13 07.06.26.000000000 AM
    21-OCT-13 07.06.26.000000000 AM
    21-OCT-13 07.08.03.000000000 AM
    21-OCT-13 07.08.03.000000000 AM
    21-OCT-13 07.08.03.000000000 AM
    21-OCT-13 07.08.03.000000000 AM
    21-OCT-13 07.08.03.000000000 AM
    21-OCT-13 07.09.30.000000000 AM
    21-OCT-13 07.09.30.000000000 AM
    21-OCT-13 07.09.30.000000000 AM
    21-OCT-13 07.09.30.000000000 AM
    21-OCT-13 07.09.30.000000000 AM
    21-OCT-13 07.09.30.000000000 AM
    21-OCT-13 07.11.06.000000000 AM
    21-OCT-13 07.11.06.000000000 AM
    21-OCT-13 07.11.06.000000000 AM
    21-OCT-13 07.11.06.000000000 AM
    21-OCT-13 07.11.06.000000000 AM
    21-OCT-13 07.12.30.000000000 AM
    21-OCT-13 07.12.30.000000000 AM
    21-OCT-13 07.12.30.000000000 AM
    21-OCT-13 07.12.30.000000000 AM
    21-OCT-13 07.12.30.000000000 AM
    21-OCT-13 07.14.12.000000000 AM
    21-OCT-13 07.14.12.000000000 AM
    21-OCT-13 07.14.12.000000000 AM
    21-OCT-13 07.14.12.000000000 AM
    21-OCT-13 07.14.12.000000000 AM
    21-OCT-13 07.14.12.000000000 AM
    21-OCT-13 07.15.45.000000000 AM
    21-OCT-13 07.15.45.000000000 AM
    21-OCT-13 07.15.45.000000000 AM
    21-OCT-13 07.15.45.000000000 AM
    21-OCT-13 07.15.45.000000000 AM
    21-OCT-13 07.17.12.000000000 AM
    21-OCT-13 07.17.12.000000000 AM
    21-OCT-13 07.17.12.000000000 AM
    21-OCT-13 07.17.12.000000000 AM
    21-OCT-13 07.17.12.000000000 AM
    21-OCT-13 07.17.12.000000000 AM
    21-OCT-13 07.18.33.000000000 AM
    21-OCT-13 07.18.33.000000000 AM
    21-OCT-13 07.18.33.000000000 AM
    21-OCT-13 07.18.33.000000000 AM
    21-OCT-13 07.18.33.000000000 AM
    21-OCT-13 07.18.33.000000000 AM
    21-OCT-13 07.20.06.000000000 AM
    21-OCT-13 07.20.06.000000000 AM
    21-OCT-13 07.20.06.000000000 AM
    21-OCT-13 07.20.06.000000000 AM
    21-OCT-13 07.20.06.000000000 AM
    21-OCT-13 07.21.48.000000000 AM
    21-OCT-13 07.21.48.000000000 AM
    21-OCT-13 07.21.48.000000000 AM
    21-OCT-13 07.21.48.000000000 AM
    21-OCT-13 07.21.48.000000000 AM
    21-OCT-13 07.21.48.000000000 AM
    21-OCT-13 07.23.06.000000000 AM
    21-OCT-13 07.23.06.000000000 AM
    21-OCT-13 07.23.06.000000000 AM
    21-OCT-13 07.23.06.000000000 AM
    21-OCT-13 07.23.06.000000000 AM
    21-OCT-13 07.24.33.000000000 AM
    21-OCT-13 07.24.33.000000000 AM
    100 rows selected.
    SQL>

  • How can I determine what is the minimum SCN number I need to restore up to.

    Say if I have a full database backup, I know I have file inconsistency, but I want to know what is the minimum time or SCN number a need to roll forward to in order to be able to open the database?
    For example: I do a database restore.
    restore database ;
    RMAN> sql 'alter database open read only';
    sql statement: alter database open read only
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03009: failure of sql command on default channel at 03/16/2009 15:00:04
    RMAN-11003: failure during parse/execution of SQL statement: alter database open read only
    ORA-16004: backup database requires recovery
    ORA-01194: file 1 needs more recovery to be consistent
    ORA-01110: data file 1: '/u01/oradata/p1/system01.dbf'
    I need need to apply archive log files. All references I find for ORA-00194 state the solution is to "apply more logs until the file is consistent " But "HOW MANY LOGS", or more apporaite up to what time or SCN? How does one determine what TIME or SCN is required to get all file consistent?
    I thought this query might provide the answer, but it doesn't
    select max(checkpoint_change#)
    from v$datafile_header
    MAX(CHECKPOINT_CHANGE#)
    7985876903
    --It applies a bit more redo, but not enough to make my datafiles consistent.
    recover database until SCN=7985876903 ;
    Starting recover at 03/16/09 15:04:54
    using channel ORA_DISK_1
    using channel ORA_DISK_2
    using channel ORA_DISK_3
    using channel ORA_DISK_4
    using channel ORA_DISK_5
    using channel ORA_DISK_6
    using channel ORA_DISK_7
    using channel ORA_DISK_8
    starting media recovery
    channel ORA_DISK_1: starting archive log restore to default destination
    channel ORA_DISK_1: restoring archive log
    archive log thread=1 sequence=18436
    channel ORA_DISK_1: reading from backup piece /temp-oracle/backup/hot/p1/20090315/hourly.arch_P1_47353_681538638_1
    channel ORA_DISK_1: restored backup piece 1
    piece handle=/temp-oracle/backup/hot/p1/20090315/hourly.arch_P1_47353_681538638_1 tag=TAG20090315T041716
    channel ORA_DISK_1: restore complete, elapsed time: 00:02:26
    archive log filename=/u01/app/oracle/flash_recovery_area/P1/archivelog/2009_03_16/o1_mf_1_18436_4vxd81yc_.arc thread=1 se quence=18436
    Oracle Error:
    ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
    ORA-01194: file 1 needs more recovery to be consistent
    ORA-01110: data file 1: '/u01/oradata/p1/system01.dbf'
    I've discover I need to apply archive logs until this query reports all datafiles as FUZZY=NO , but this only works by guessing at some time periord to roll forward to, then checking the FUZZY column, and try again. Is there a way to know, I have to roll forward to a specific SNC in order for all my datafiles to be consistent?
    select file#
         , status
         , checkpoint_change#
         , checkpoint_time
         , FUZZY
         , RECOVER
    ,LAST_DEALLOC_SCN
    from v$datafile_header
    order by checkpoint_time
    Thanks,
    Jason

    The minimum point in time is the time when the last backup piece for datafiles in that backup was completed.
    Your alert.log should show the redo log sequence number at that time.
    You can query V$ARCHIVED_LOG and get the FIRST_CHANGE# of the first archivedlog generated after that backup piece completed.
    A
    LIST BACKUP;in RMAN should also show you the SCNs at the time of the backups.
    You can also query SCN_TO_TIMESTAMP -- eg
    select timestamp_to_scn(to_timestamp('15-MAR-09 09:24:01','DD-MON-RR HH24:MI:SS')) from dual;will return an approximation of the SCN.
    Hemant K Chitale
    http://hemantoracledba.blogspot.com
    Edited by: Hemant K Chitale on Mar 17, 2009 9:41 AM
    added the LIST BACKUP command from RMAN.

  • How to i determine what a 10.10.00 memory error means on a laserjet 3600

    Printer: HP 3600n
    Error message: 10.10.00 memory error
    What is this error and what can be done to resolve it.

    The minimum point in time is the time when the last backup piece for datafiles in that backup was completed.
    Your alert.log should show the redo log sequence number at that time.
    You can query V$ARCHIVED_LOG and get the FIRST_CHANGE# of the first archivedlog generated after that backup piece completed.
    A
    LIST BACKUP;in RMAN should also show you the SCNs at the time of the backups.
    You can also query SCN_TO_TIMESTAMP -- eg
    select timestamp_to_scn(to_timestamp('15-MAR-09 09:24:01','DD-MON-RR HH24:MI:SS')) from dual;will return an approximation of the SCN.
    Hemant K Chitale
    http://hemantoracledba.blogspot.com
    Edited by: Hemant K Chitale on Mar 17, 2009 9:41 AM
    added the LIST BACKUP command from RMAN.

  • How to find out the rows inserted between a time period.

    Hi,
    Please help me to solve this.
    Table - emp.
    Colmns - empno(Primary Key),ename, mgr
    How to find out the rows inserted between a time period.
    For eg:- Between 02-Oct-2006 1 PM and 03-Oct-2006 2 PM.
    regards,
    Mathew.

    Hi,
    Maybe work:
    For each row, ORA_ROWSCN returns the conservative upper bound system change number (SCN) of the most recent change to the row. This pseudocolumn is useful for determining approximately when a row was last updated. It is not absolutely precise, because Oracle tracks SCNs by transaction committed for the block in which the row resides
    e.g.:
    SGMS@ORACLE10> create table test(cod number);
    Table created.
    SGMS@ORACLE10> insert into test values (1);
    1 row created.
    SGMS@ORACLE10> insert into test values (2);
    1 row created.
    SGMS@ORACLE10> commit;
    Commit complete.
    SGMS@ORACLE10> insert into test values (3);
    1 row created.
    SGMS@ORACLE10> commit;
    Commit complete.
    SGMS@ORACLE10> select SCN_TO_TIMESTAMP(ora_rowscn),ora_rowscn,cod from test;
    SCN_TO_TIMESTAMP(ORA_ROWSCN)       ORA_ROWSCN        COD
    06/11/06 08:56:56,000000000         727707205          1
    06/11/06 08:56:56,000000000         727707205          2
    06/11/06 08:57:05,000000000         727707210          3Cheers

  • How to get the date of the last transaction in a mounted standby database?

    Hello,
    Could you tell me how to get the date of the last transaction recorded in a MOUNTED standby database?
    The following query doesn't work...because the database is not open...
    select scn_to_timestamp(current_scn) from v$database;
    Thanks

    Hi,
    You should be able to run the following command in mounted mode on standby database.
    select current_scn from v$database;
    then run the following to convert it to timestamp.
    select scn_to_timestamp(99999999) from dual; *<-- Replace here the SCN value you got above. This needs to be run on the primary database due to standby database in mount mode.*
    Alternatively you can also check at the alert.log file to find the last scn which has been applied.
    Regards
    Edited by: skvaish1 on Jan 19, 2010 11:15 AM

  • Error in Flashback Query

    while trying to execute flashback query i am getting an error
    CREATE TABLE flashback_query_test (
    id NUMBER(10)
    desc flashback_query_test
    SELECT current_scn, TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS') FROM v$database;
    INSERT INTO flashback_query_test (id) VALUES (1)
    COMMIT;
    SELECT COUNT(*) FROM flashback_query_test
    SQL> SELECT COUNT(*)
    2 FROM
    3 flashback_query_test
    4 AS OF
    5 TIMESTAMP TO_TIMESTAMP('2010-02-01 16:58:43', 'YYYY-MM-DD HH24:MI:SS');
    flashback_query_test
    ERROR at line 3:
    ORA-01466: unable to read data - table definition has changed
    pls help me out!................

    The SCN to TIMESTAMP conversion only has a granularity of approximately 3 seconds if I remember correctly. So my guess is that you are getting this error because you are trying to flashback to the same time that the table was created putting you in that 3 second window of SCN to TIMESTAMP ambiguity.
    You can see this ambiguity by using the SCN_TO_TIMESTAMP or TIMESTAMP_TO_SCN functions as shown below:
    SQL> COLUMN TSTAMP NEW_VALUE T;
    SQL> SELECT CURRENT_SCN, TO_CHAR(SYSTIMESTAMP,'YYYY-MM-DD HH24:MI:SS') AS TSTAMP FROM V$DATABASE;
             CURRENT_SCN TSTAMP
           9080346377361 2010-02-01 07:13:12
    SQL> SELECT TIMESTAMP_TO_SCN(TO_TIMESTAMP('&T','YYYY-MM-DD HH24:MI:SS')) FROM DUAL;
    old   1: SELECT TIMESTAMP_TO_SCN(TO_TIMESTAMP('&T','YYYY-MM-DD HH24:MI:SS')) FROM DUAL
    new   1: SELECT TIMESTAMP_TO_SCN(TO_TIMESTAMP('2010-02-01 07:13:12','YYYY-MM-DD HH24:MI:SS')) FROM DUAL
    TIMESTAMP_TO_SCN(TO_TIMESTAMP('2010-02-0107:13:12','YYYY-MM-DDHH24:MI:SS'))
                                                                  9080346377360See how the SCNs are different?
    Now if you allow some time to pass between table creation and INSERT, you should be able to get the results as shown:
    SQL> CREATE TABLE FLASHBACK_QUERY_TEST(id NUMBER(10));
    Table created.
    SQL> EXEC DBMS_LOCK.SLEEP(3);
    PL/SQL procedure successfully completed.
    SQL> COLUMN TSTAMP NEW_VALUE T;
    SQL> SELECT CURRENT_SCN, TO_CHAR(SYSTIMESTAMP,'YYYY-MM-DD HH24:MI:SS') AS TSTAMP FROM V$DATABASE;
             CURRENT_SCN TSTAMP
           9080346377430 2010-02-01 07:15:30
    SQL> INSERT INTO FLASHBACK_QUERY_TEST(ID) VALUES(1);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> SELECT COUNT(*) FROM FLASHBACK_QUERY_TEST;
                COUNT(*)
                       1
    SQL> SELECT COUNT(*) FROM FLASHBACK_QUERY_TEST AS OF TIMESTAMP TO_TIMESTAMP('&T','YYYY-MM-DD HH24:MI:SS');
    old   1: SELECT COUNT(*) FROM FLASHBACK_QUERY_TEST AS OF TIMESTAMP TO_TIMESTAMP('&T','YYYY-MM-DD HH24:MI:SS')
    new   1: SELECT COUNT(*) FROM FLASHBACK_QUERY_TEST AS OF TIMESTAMP TO_TIMESTAMP('2010-02-01 07:15:30','YYYY-MM-DD HH24:MI:SS')
                COUNT(*)
                       0HTH!

  • Oracle EE 11.2.0.2 RMAN Duplicate interesting issue - is it a bug?

    Hi,
    Oracle EE 11.2.0.2 RHEL 5.7 x86 64-bit RACOne Node database (3 - nodes).
    I was working on a process to refresh out test environment with prod database backup from tape and i have done it many times. Most of our environment is in 10gR2 and have few on 11.2.0.2 RACOne Node databases. The recovery basics in Oracle world is to use archive log sequence + 1 (provided we know before hand the backups metadata) and it works as expected until 10g but with 11.2.0.2 RMAN duplicate, i stumbled upon an issue where RMAN is trying to restore an older controlfile auto backup and then rolling forward from there. Its easy to explain with an example..
    1) I have an archivelog backup, say sequence 20 to 30 on Feb 22nd @ 10pm and a controlfile autobackup at this time c-20120222
    2) I have a FULL backup + archive log until sequence 50 on Feb 23nd@ 6pm and a controlfile autobackup at this time  c-20120223
    3) I am using RMAN duplicate to refresh UAT with Feb 23rd backup and use "set until sequence 51 thread 1"I am using following RMAN commands to do the duplicate on UAT server (executed on UAT server)
    rman target sys/***@PROD_DB  auxiliary /
    RMAN> run
    2> {
    3> allocate auxiliary channel c1 device type disk;
    4> allocate auxiliary channel c2 device type disk;
    5> allocate auxiliary channel c3 device type disk;
    6> set until sequence 51 thread 1;
    7> duplicate target database to UAT_DB;
    8> }RMAN duplicate automates all that we do manually but the recovery mechanism is same. In the above scenario, it connects to target database, gets the backup metadata and restores controlfile from c-20120223 , restores the datafiles and recovers till sequence 50 . This has been the scenario until 10g in every RMAN duplicate process i have tried and is expected from Oracle.
    Issue:
    In 11gR2 (11.2.0.2), for the same duplicate scenario above, it is restoring the controlfile from autobackup c-20120222 and restoring the datafiles from Feb 23rd backup, recovering till sequence 50 and doing the duplicate process. The thing to note here is that the controlfile autobackup c-20120222 does not have any record of the FULL backup that occured on Feb 23 rd and since RMAN duplicate is having a connection to target database, it knows the backup metadata and hence it is able to complete the recovery.
    For clarification, Thread 1 & 2 of RAC One Node is not an issue here for sure. Did anyone experience this issue? Any insight into this would be greatly appreciated.
    Thanks,
    Shiva

    AJ,
    I have already tried that scenario, i renamed the c-20120222 and kicked off the same duplicate process but it failed and it kept on "fail-over to previous backup" which is expected. The thing is, RMAN look's for the control file autobackups from newest to oldest (unless you gave a point in time) and duplicate command is not doing it.
    Tycho,
    I agree there are new features but to support them a change in recovery mechanism is something i would disagree that Oracle would do. Active Duplication is not based on backups, so that is out of question here. For backup-based duplication, we can try with connections to target or targetless, catalog or catalogless or none. I have already given an example with the target (same with target + catalog) and i expect the same behavior with only catalog connection. Now, i have tested the example without connecting to target or catalog and below are my observations...
    For the same backups i mentioned in the very first email, i got the following info....
    rman target /
    Recovery Manager: Release 11.2.0.2.0 - Production on Fri Feb 24 12:35:54 2012
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    connected to target database: RMANTEST (DBID=3789692530)
    RMAN> list backup of archivelog sequence 95;
    using target database control file instead of recovery catalog
    List of Backup Sets
    ===================
    BS Key  Size       Device Type Elapsed Time Completion Time
    11      2.50K      DISK        00:00:00     23-FEB-12 18:05:40
            BP Key: 11   Status: AVAILABLE  Compressed: YES  Tag: TAG20120222T094240
            Piece Name: /u01/app/oracle/exp/rmantest_stl/full_backup/rmantest_stl_0bn3upkg_1_1.arch
      List of Archived Logs in backup set 11
      Thrd Seq     Low SCN    Low Time           Next SCN   Next Time
      1    95      346280     23-FEB-12 18:05:10 346302     23-FEB-12 18:05:30I got the scn_to_timestamp for the NEXT_SCN of sequence 95, which should correpond tothe "Next Time" that is the timestamp for the Archive log sequence 96.
    SQL> select scn_to_timestamp(346302) as timestamp from dual;
    TIMESTAMP
    23-FEB-12 18.05.30.000000000 PMNow, i gave the following for targetless & catalogless duplication...
    rman auxiliary /
    RMAN> run
    2> {
    3> set until time "to_date('23-FEB-12 18:05:30','DD-MON-YY HH24:MI:SS')";
    4> duplicate database to rman01s backup location '/u01/app/oracle/exp/rmantest_stl';
    5> }RESULT: Same ISSUE but this time IT FAILED with the error i expected. It went ahead and restored the c-20120222 autobackup control file and tried to restore the datafiles but, as we
    know, this control file autobackup does not have record of Feb 23rd + archive log backup, so it FAILS. This is exactly what i told in my first email.
    Error Log File:
    contents of Memory Script:
       sql clone "alter system set  control_files =
      ''+RMAN01D_DATA/rman01s_stl1/controlfile/current.270.776081841'', ''+RMAN01D_RECO/rman01s_stl1/controlfile/current.263.776081841'' comment=
    ''Set by RMAN'' scope=spfile";
       sql clone "alter system set  db_name =
    ''RMANTEST'' comment=
    ''Modified by RMAN duplicate'' scope=spfile";
       shutdown clone immediate;
       startup clone force nomount
       restore clone primary controlfile from  '/u01/app/oracle/exp/rmantest_stl/c-20120222';
       alter clone database mount;
    Errors in memory script
    RMAN-03015: error occurred in stored script Memory Script
    RMAN-06136: ORACLE error from auxiliary database: ORA-01507: database not mounted
    ORA-06512: at "SYS.X$DBMS_RCVMAN", line 13371
    ORA-06512: at line 1
    RMAN-03015: error occurred in stored script Memory Script
    RMAN-06026: some targets not found - aborting restore
    RMAN-06023: no backup or copy of datafile 5 found to restore
    RMAN-06023: no backup or copy of datafile 4 found to restore
    RMAN-06023: no backup or copy of datafile 3 found to restore
    RMAN-06023: no backup or copy of datafile 2 found to restore
    RMAN-06023: no backup or copy of datafile 1 found to restore
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of Duplicate Db command at 02/24/2012 10:18:04
    RMAN-05501: aborting duplication of target databaseSo, my next test was not to give any Point In Time, that is just issue the duplicate without SET UNIL clause and this time, and this time it behaved, it restored the control file from c-20120223 and completed the duplicate process. So what does this tell us? We cannot do a POINT IN TIME duplicate using RMAN DUPLICATE????
    rman auxiliary /
    RMAN> run
    2> {
    3> duplicate database to rman01s backup location '/u01/app/oracle/exp/rmantest_stl';
    4> }
    contents of Memory Script:
       sql clone "alter system set  control_files =
      ''+RMAN01D_DATA/rman01s_stl1/controlfile/current.270.776089489'', ''+RMAN01D_RECO/rman01s_stl1/controlfile/current.263.776089489'' comment=
    ''Set by RMAN'' scope=spfile";
       sql clone "alter system set  db_name =
    ''RMANTEST'' comment=
    ''Modified by RMAN duplicate'' scope=spfile";
       shutdown clone immediate;
       startup clone force nomount
       restore clone primary controlfile from  '/u01/app/oracle/exp/rmantest_stl/c-20120223';
       alter clone database mount;
    }Just checking if anyone stumbled upon these findings. An Oracle SR is already in place, so just waiting for an update from them.
    Thanks,
    Shiva

  • How to see inserted rows using load csv data

    Hey all...
    I am using apex 3.1 and I want to know how can I see non failed rows when I insert data from an CSV file.
    the failed rows that I can see are the the ones that shows in the next case: Uploading data that already exists and having a primary key violation. But what I really want to see is the description of the rows that had been succesfully loaded, not just a number of succesfully loaded rows.
    Thanks in advance.
    Luis.

    Try some thing like this
    select  Field, Filed2, ORA_ROWSCN, SCN_TO_TIMESTAMP(ORA_ROWSCN)  from Table Name
    You will get the recent  date of  insert/update of record

  • To know the exact timing

    hi all,
    1)How can i know that
    in a oracle 10g table when i modified a row or deleted a row and which row i have inserted when
    i want to know the particular time.
    can it is possiable if possiable then tell me how.
    2)what is the difference between raise_application_error and raise ?
    3) Is there any difference between oracle 9i merge command and 10g merge command ?

    Here is a cool tidbit of information from .....
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns007.htm#sthref825
    ORA_ROWSCN Pseudocolumn For each row, ORA_ROWSCN returns the conservative upper bound system change number (SCN) of the most recent change to the row. This pseudocolumn is useful for determining approximately when a row was last updated. It is not absolutely precise, because Oracle tracks SCNs by transaction committed for the block in which the row resides. You can obtain a more fine-grained approximation of the SCN by creating your tables with row-level dependency tracking. Please refer to CREATE TABLE ... NOROWDEPENDENCIES | ROWDEPENDENCIES for more information on row-level dependency tracking.
    And then from ....
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_flashback.htm#sthref1467
    ORA_ROWSCN is a pseudocolumn of any table that is not fixed or external. It represents the SCN of the most recent change to a given row, that is, the latest COMMIT operation for the row. For example:
    SELECT ora_rowscn, last_name, salary
    FROM employees
    WHERE employee_id = 7788;
    ORA_ROWSCN    NAME    SALARY
    *202553 Fudd 3000*
    The latest COMMIT operation for the row took place at approximately SCN 202553. You can use function SCN_TO_TIMESTAMP to convert an SCN, like ORA_ROWSCN, to the corresponding TIMESTAMP value.
    See what you can find when you search the documentation?
    Regards
    Tim

  • ORAROW_SCN keeps changing unexpectedly

    Hello
    I am facing a strange behaviour for the ORAROW_SCN.
    This is the scenario:
    1. We created a copy of a database using datapump to a new Exadata box.
    2. After creating the copy, we query the database for the latest ORAROW_SCN (We rely on this number to load data into a DW)
    3. Latest ORAROW_SCN for every table in the new database keeps changing, even when not DMLs are being executed in the database.
    So, lets say I have the "customers" table with 7,817,414 records
    If I execute the following query:
    select ora_rowscn, scn_to_timestamp(ora_rowscn), count(*)
    from customers
    group by ora_rowscn, scn_to_timestamp(ora_rowscn)
    order by 1 DESC
    The latest ORAROW_SCN keeps changing, like this: (Every line is the result of executing the query after a few minutes)
    ora_rowscn scn_to_timestamp count
    ========================================
    24526487045 10/12/2012 12:00:56.000000000 PM 7,586,482
    24543886062 10/12/2012 4:00:06.000000000 PM 7,586,482
    24543886064 10/12/2012 4:00:06.000000000 PM 7,586,482
    It happens for every table in the new database.
    So, if we are not updating or inserting rows, what else could be happening that is making the ORAROW_SCN to change continually?
    Thanks,
    Andrew

    Hi,
    Same day when you posted this question, i created a table for test in my 11.2 express edition database and after 3 days, I don't see any change ORA_ROWSCN
    select ora_rowscn, scn_to_timestamp(ora_rowscn), count(*)
    from test
    group by ora_rowscn, scn_to_timestamp(ora_rowscn)
    order by 1 DESC
    ORA_ROWSCN SCN_TO_TIMESTAMP(ORA_ROWSCN)                                                  COUNT(*)
       6057143 10-DEC-12 03.25.44.000000000 PM                                                     99
       6057095 10-DEC-12 03.24.35.000000000 PM                                                   1779Before putting database in read only mode, you can also test it by creating a test table and by inserting some dummy values and monitor it..
    Salman

  • Find time when DB went down (nothing in alert log).

    hello all,
    is there any way to tell when the DB went down. Yesterday we had some outage in our datacenter and it took down one of our servers. And this morning i started the DB and they went up fine with no problem. But is there any way to find out when the DB went down (there was nothing written in the alert log)...and our sysadmin is on Vac...and the management wants me to find out when the server/database went down...does oracle record this thing any place in the DB besides the alert log ?? we are on 10.2.0.3 on hp-ux. We can look at the OS to find this out, but as mentioned our sysadmin is out and dont have access to root...

    Hello user630084,
    Pls try this. I had to check the same on one of our client boxes without unix access and I used the below to find. it worked for me.
    (10.2.0.4 version)
    SELECT SCN_TO_TIMESTAMP(TIMESTAMP_TO_SCN(startup_time)) "DB Shutdown Time" , startup_time "DB Startup Time" FROM v$instance
    Hope this works for u aswell.
    Krishna

Maybe you are looking for

  • Is there a way to create shared iTunes playlists with iCloud?

    For instance, if I were to create a playlist called "Playlist X" on my Macbook Pro, is there a way for iCloud to put that same playlist in my iMac's iTunes library? And if I were to add a song to the playlist on the iMac, could it appear in the playl

  • Unable to find data visualization component in JDEV 11g Preview 4

    we have installed jdev11g preview 4 and we are unable to find ADF data visualization component. Is there anyway we could add this component. Thanks in Advance Sabir

  • How do I get Snow Leopard to display 256 color?

    I am attempting to run the applications Fallout and Fallout 2 on my 13" screen MacBook Pro, and each of these requires 8-bit color support. When I open the application, a normally colored small window appears for a couple of seconds, plays some music

  • AddEventListener afterOpen to Document

    The CS3 scripting guide specifically mentions that you can use the "afterOpen" event on either an Application or Document object. I seem unable to bind to the afterOpen event on a document, however. What I am trying to do is detect certain files bein

  • Printing from InDesign - black lines

    Good afternoon all, I've started using InDesign CS6 at work to produce advertising catalogues. I've hit a bit of a wall when I print it and would like a bit of help to try and solve my issue(s). I have a booklet set up to print 4 pages of A4 on to do