Finding SCN for Oracle Database by Date and time

Oracle provides the function TIMESTAMP_TO_SCN to determine the database SCN number for a given time. This is very useful in performing multiple Oracle Administrative tasks. This procedure explains the use of this function to extract SCN.

1. Logon to Oracle Database server as the Oracle software owner and start SQLPLUS.

[root@linux2 etc]# su – oracle
Last login: Thu Jun 1 09:25:23 EST 2017 on pts/1
[oracle@linux2 ~]$
[oracle@linux2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 1 13:47:01 2017

Copyright (c) 1982, 2014, Oracle. All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL>

2. Determine Oracle SCN one hour ago by specifying sysdate-1/24

SQL> select timestamp_to_scn(sysdate-1/24) from dual;

TIMESTAMP_TO_SCN(SYSDATE-1/24)
——————————
5062307

SQL>

3. Determine Oracle SCN 1 day ago by specifying sysdate-1

SQL> select timestamp_to_scn(sysdate-1) from dual;

TIMESTAMP_TO_SCN(SYSDATE-1)
—————————
4975332

SQL>

4. Determine Oracle SCN 1 week ago by specifying sysdate-7

SQL> select timestamp_to_scn(sysdate-7) from dual;

TIMESTAMP_TO_SCN(SYSDATE-7)
—————————
4696226

SQL>

5. Determine Oracle SCN by specific date time by using the to_date() function with appropriate date mask.

SQL> select timestamp_to_scn(to_date(’25-MAY-2017 06:30:00′,’DD-MON-YYYY HH24:MI_SS’)) from dual;

TIMESTAMP_TO_SCN(TO_DATE(’25-MAY-201706:30:00′,’DD-MON-YYYYHH24:MI_SS’))
————————————————————————
4696226

SQL>

6. This completes the use of the function TIMESTAMP_TO_SCN.

Larry Catt
OCP

Executing SQL script from command line or executable shell script

You can call into SQLPLUS to execute SQL script from any shell script. This procedure shows how to structure your statements to LINUX environment for call into SQLPLUS from shell script.

1. Logon to your LINUX server as a user with access to SQLPLUS.
2. Use VI to create a executable file. Replace the connection string with appropriate username/password@SID values. Additionally, change the script you which to execute in this example we are executing “utlrp.sql”.

sqlplus sys/password@orcl as sysdba < < EOF @?/rdbms/admin/utlrp.sql exit; EOF

Larry Catt
OCP

Executing Oracle Script as a LINUX or UNIX background process

There are multiple situations where you have to execute processes in your Oracle environment as a daemon or background process of your OS. This procedure describes the use of “NOHUP” to begin the execution of a background process. In this example we are executing the Oracle 12c upgrade script ‘preupgrd.sql’ on an OEL (Oracle Enterprise Linux) platform.

1. Logon to your OEL server as the oracle software owner.

root@mylinux#su – oracle
oracle@mylinux#

2. Change directory to the location of your script file.

oracle@mylinux#cd /opt/app/oracle/product/12.1.0.2/rdbms/admin/
oracle@mylinux#

3. At the OS prompt execute the NOHUP command passing in a sqlplus connection string and the script name to be executed following by a terminating ampersand sign ‘&’.

nohup sqlplus sys/password as sysdba @./preupgrd.sql &

oracle@mylinux#nohup sqlplus sys/password as sysdba @./preupgrd.sql &
[1] 7260
oracle@mylinux#nohup: ignoring input and appending output to `nohup.out’

oracle@mylinux#

4. The (nohup) command will produce a log file in the local directory named nohup.out which records all terminal output from the daemon.

oracle@mylinux#cat nohup.out
SQL*Plus: Release 11.2.0.4.0 Production on Sat Mar 26 17:28:19 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Loading Pre-Upgrade Package…

SQL>

5. You can also see the processing with the system process command (ps) as shown below.

oracle@mylinux#ps -ef|grep nohup
oracle 9707 9268 0 18:11 pts/0 00:00:00 grep nohup
[1]+ Exit 1 nohup sqlplus sys/password as sysdba @./preupgrd.sql
oracle@mylinux#

6. This completes executing an Oracle script as a LINUX or UNIX background process.

Larry J. Catt, OCP

Change time zone of Oracle RDBMS on Linux OS

This procedure demonstrates the method to change the time zone setting of an Oracle RDBMS installed on a Linux server.   NOTE:  Oracle RDBMS by default take the time of the OS which they are installed on.   Due to the number and variations LINUX distributions, this procedure may not work on all LINUX installs.   This procedure was performed on Oracle Enterprise Linux 7.2  (OEL 7.2).

 

  1. Logon to your Linux server as root.

 

[larry@linux2 ~]$ sudo su

[sudo] password for larry:

[root@linux2 larry]#

 

  1. Change user to Oracle software owner and logon to SQLPLUS.

 

[root@linux2 etc]# su – oracle

Last login: Wed Nov 30 16:36:03 UTC 2016 on pts/1

[oracle@linux2 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Wed Nov 30 16:38:13 2016

 

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SQL>

 

  1. Show the current date and time zone for the Oracle database with command: select systimestamp from dual;

 

SQL> select systimestamp from dual;

 

SYSTIMESTAMP

—————————————————————————

30-NOV-16 04.40.33.575810 PM +00:00

 

SQL>

 

  1. Exit out of SQLPLUS and change user to root.

 

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

[oracle@linux2 ~]$ su –

Password:

Last login: Wed Nov 30 16:38:00 UTC 2016 on pts/1

[root@linux2 ~]#

 

  1. Change to directory /etc

 

[root@linux2 ~]# cd /etc

[root@linux2 etc]#

 

  1. Display the currently set system time with command date.

 

[root@linux2 etc]# date

Wed Nov 30 12:39:08 UTC 2016

[root@linux2 etc]#

 

  1. List the current setting to link /etc/localtime and remove link /etc/localtime, using the “rm –f” command.

 

[root@linux2 etc]# ls -l localtime

lrwxrwxrwx. 1 root root 23 Nov 30 14:22 localtime -> /usr/share/zoneinfo/UTC

[root@linux2 etc]# rm -rf localtime

[root@linux2 etc]#

 

  1. Create new link to directory /usr/share/zoneinfo/<your time zone> with you correct timezone.  In this example we are changing to EST.

 

ln -s /usr/share/zoneinfo/EST localtime

 

 

[root@linux2 etc]# ls -l localtime

lrwxrwxrwx. 1 root root 23 Nov 30 09:23 localtime -> /usr/share/zoneinfo/EST

[root@linux2 etc]#

 

  1. Execute linux date command to see new timezone.

 

[root@linux2 etc]# date

Wed Nov 30 11:43:59 EST 2016

[root@linux2 etc]#

 

  1. Logon as the oracle software owner and logon to SQLPLUS.

[root@linux2 etc]# su – oracle

Last login: Wed Nov 30 11:41:44 EST 2016 on pts/1

[oracle@linux2 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Wed Nov 30 11:45:13 2016

 

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SQL>

 

 

  1. To verify the new timezone update has been completed, execute the SQL statement: select systimestamp from dual;

 

SQL> select systimestamp from dual;

 

SYSTIMESTAMP

—————————————————————————

30-NOV-16 11.46.25.722487 AM -05:00

 

SQL>

 

 

  1. This completes update of timezone for Oracle RDBMS on a Linux platform.

 

 

Larry Catt

OCP

 

Oracle 12c – User Oracle Data Pump enhancements

Transportable Feature:

 

Data Pump has full transportable export option while performing full database backup with the transportable export flag set to TRANSPORTABLE=ALWAYS along with the FULL parameter.  This causes two types of movement methods to be used:  Non-Transportable tablespace – Used for SYSTEM and SYSAUX which cannot be transported and have metadata and data moved using direct-path and external tables; and Transportable tablespaces – Only metadata is placed in dump file, data is moved when the data files are copied to target database.   This new data pump features can be used for moving non-CDB databases into PDB or PDB into PDB.  This can reduce the time by avoiding data being unloaded and reloaded and indexes do not have to be recreated.  The full transport is idea for moving database to new computer.

 

Restrictions of full transportable exports:

  1. DATAFUMP_EXP_FULL_DATABASE privilege is required.
  2. Default tablespace of user performing export cannot be one of the transportable tablespaces.
  3. If tables or columns being transported are encrypted, the encrypted password must be provided using the parameter ENCRYPTION_PASSWORD.
  4. If encryption is used on source and target database, OS must have same endianness.
  5. If source and target have different endianness, you must convert before convert data before transporting.
  6. Full transportable export is not restart able.
  7. All objects must have all their storage in segments in administrative non-transportable tablespaces or in user-defined transportable tables. Data cannot be in both kinds of tablespaces.

 

Compression feature:

  1. Compression on import – new option for impdp and DBMS_DATAPUMP package which allows for compression changes during import operations. TRANSFORM parameter of impdp has new TABLE_COMPRESSION_CLAUSE when set to NONE, the table gets default tablespace compression or set to valid compression type will compress on import.
  2. Compression on export – new option for expdp and DBMS_DATAPUMP package to control the degree of compression into file. COMPRESSION clause can be used for entire operation, data, metadata, or no compression.  By default only metadata is compressed.

 

 

Export View as a table:

EXPDP now exports views as a table rather than the view definition.  This allows the impdp utility to import the view data as a table.

 

LOGTIME:

New clause LOGTIME allows messages during export and import to be timestamped. The LOGTIME lause values are:

  1. NONE – no timestamps
  2. STATUS – timestamps on status messages.
  3. ALL – timestamps on all messages.

 

 

Audit Commands:

 

Data Pump operations can now be audited by creating audit policy on component action DATAPUMP.  IE

 

SQL> create audit policy audit_data_pump actions component=datapump all;

Audit policy created.

SQL> audit policy audit_data_pump by scott;

Audit succeeded.

SQL>

 

No Logging Options:

New option DISABLE_ARCHIVE_LOGGING for TRANSFORM parameter in impdp and DBMS_DATAPUMP package, allows for disabling of redo logging when loading data into tables and indexes.  DBA should take full RMAN backup after completion.   Redo is still taken for create and alter statements except create index.

 

Security:

ENCRYPT_PWD_PROMPT parameter has been added to expdp and impdp which tells data pump to prompt for password during operations.

SecureFiles LOB as Default – new option for impdp and DBMS_DATAPUMP package requires all LOB to be created as SecureFiles LOBS.   By default LOBs are recreated as exported.

 

 

Larry Catt

OCP

Allowing SCP on Linux 7

Attempting to transfer files from one server Linux1 to Linux2 results in error: Linux2 sshd not started.

[oracle@linux1 STAGE]$ scp * oracle@10.2.0.155:/u01/STAGE/*
ssh: connect to host 10.2.0.155 port 22: Connection refused
lost connection
[oracle@linux1 STAGE]$
1. Logon as the root user to linux2 server.

[larry@linux2 ~]$ su –
Password:
Last login: Wed Sep 14 10:26:34 EDT 2016 on pts/1
[root@linux2 ~]#

2. Attempt to start the SSH service with command: service sshd start

[root@linux2 ~]# service sshd start
Redirecting to /bin/systemctl start sshd.service
[root@linux2 ~]#

3. Check the status of sshd service with command: service sshd status

[root@linux2 ~]# service sshd status
Redirecting to /bin/systemctl status sshd.service
? sshd.service – OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2016-09-14 10:23:36 EDT; 16min ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 1283 (sshd)
CGroup: /system.slice/sshd.service
??1283 /usr/sbin/sshd -D

Sep 14 10:23:36 linux2.localdomain systemd[1]: Started OpenSSH server daemon.
Sep 14 10:23:36 linux2.localdomain systemd[1]: Starting OpenSSH server daemon…
Sep 14 10:23:36 linux2.localdomain sshd[1283]: Server listening on 0.0.0.0 p….
Sep 14 10:23:36 linux2.localdomain sshd[1283]: Server listening on :: port 22.
Sep 14 10:25:45 linux2.localdomain sshd[3639]: pam_unix(sshd:auth): authenti…y
Sep 14 10:25:47 linux2.localdomain sshd[3639]: Failed password for larry fro…2
Sep 14 10:25:50 linux2.localdomain sshd[3639]: Accepted password for larry f…2
Sep 14 10:39:50 linux2.localdomain systemd[1]: Started OpenSSH server daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@linux2 ~]#

4. Re-attempt the transfer from linux1 server.

[oracle@linux1 STAGE]$ scp * oracle@10.2.0.155:/u01/STAGE/.
oracle@10.2.0.155’s password:
fmw_12.2.1.1.0_infrastructure_Disk1_1of1.zip 100% 1490MB 99.3MB/s 00:15
fmw_12.2.1.1.0_infrastructure.jar 100% 1490MB 99.4MB/s 00:15
fmw_12211_readme.htm 100% 19KB 19.1KB/s 00:00
fmw.rsp 100% 1996 2.0KB/s 00:00
jdk1.7.0_79: not a regular file
jdk-7u79-linux-x64.tar.gz 100% 146MB 146.4MB/s 00:01
[oracle@linux1 STAGE]$
This completes failure of SCP transfer from stopped SSHD processes.
Larry Catt
OCP

Change time zone of Linux Server

This procedure demonstrates the method to change the Time Zone of a typical Linux server.   NOTE:  Due to the number and variations LINUX distributions, this procedure may not work on all LINUX installs.   This procedure was performed on Oracle Enterprise Linux 7.2  (OEL 7.2).

 

  1. Logon to your Linux server as root.

 

[larry@linux2 ~]$ sudo su –

[sudo] password for larry:

Last login: Thu Nov  3 11:02:19 EDT 2016 on pts/1

[root@linux2 ~]#

 

 

  1. Change to directory /etc

 

[root@linux2 ~]# cd /etc

[root@linux2 etc]#

 

  1. Display the currently set system time with command date.

 

[root@linux2 etc]# date

Wed Nov 30 12:39:08 UTC 2016

[root@linux2 etc]#

 

  1. List the current setting to link /etc/localtime and remove link /etc/localtime, using the “rm –f” command.

 

[root@linux2 etc]# ls -l localtime

lrwxrwxrwx. 1 root root 23 Nov 30 14:22 localtime -> /usr/share/zoneinfo/UTC

[root@linux2 etc]# rm -rf localtime

[root@linux2 etc]#

 

  1. Create new link to directory /usr/share/zoneinfo/<your time zone> with you correct timezone.  In this example we are changing to EST.

 

ln -s /usr/share/zoneinfo/EST localtime

 

 

[root@linux2 etc]# ls -l localtime

lrwxrwxrwx. 1 root root 23 Nov 30 09:23 localtime -> /usr/share/zoneinfo/EST

[root@linux2 etc]#

 

  1. Execute linux date command to see new timezone.

 

[root@linux2 etc]# date

Wed Nov 30 09:25:40 EST 2016

[root@linux2 etc]#

 

  1. This completes changing the time zone on Linux server.

 

Larry Catt

OCP

 

Oracle 12c – User privilege analysis

Oracle 12c gives the ability to perform a user privilege analysis to bounce against granted privileges.   This allows you to reduce granted privilege down to what the individual user actually needs and no more.   This article gives a procedure to perform User privilege analysis.

 

 

  1. Logon oracle server as the oracle software owner than logon to sqlplus with sysdba privilegs. If this is done by none privileged user account, the user must have the CAPTURE_ADMIN role granted.

 

[root@linux2 ~]# su – oracle

Last login: Thu Dec 15 07:50:00 EST 2016 on pts/1

Enter database to use:

1 – ORCL

2 – CDB1

Option >

1

[oracle@linux2 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Thu Dec 15 13:05:59 2016

 

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

 

SQL>

 

 

 

  1. Define the privilege analysis policy with the CREATE_CAPTURE procedure of DBMS_PRIVILEGE_CAPTURE package. This example below will capture all privileges used.

 

BEGIN

DBMS_PRIVILEGE_CAPTURE.CREATE_CAPTURE(

        name         => ‘user_priv_capture’,

        description  => ‘Capture the privileges by user test’,

        type         => DBMS_PRIVILEGE_CAPTURE.G_DATABASE);

END;

/

  1. Enable the privilege analysis policy.

 

SQL> EXEC DBMS_PRIVILEGE_CAPTURE.ENABLE_CAPTURE (‘user_priv_capture’);

 

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Logon as the user test and perform DML processing.

 

SQL> connect test/test

Connected.

 

SQL>  insert into test.test_times(pers_id, first_name) values(99,’test’);

 

1 row created.

 

SQL> commit;

 

Commit complete.

 

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

[oracle@linux2 ~]$

 

 

  1. Logon as sysdba and disable the privilege analysis policy’s recording of privilege use.

 

[oracle@linux2 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Thu Dec 15 13:25:29 2016

 

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

 

SQL> EXEC DBMS_PRIVILEGE_CAPTURE.DISABLE_CAPTURE (‘user_priv_capture’);

 

PL/SQL procedure successfully completed.

 

SQL>

  1. Generate privilege analysis results.

 

SQL> EXEC DBMS_PRIVILEGE_CAPTURE.GENERATE_RESULT (‘user_priv_capture’);

 

PL/SQL procedure successfully completed.

 

SQL>

 

  1. Query the table dba_used_privs to see privileges used during the capture period.

 

SQL> column username format a12

column sys_priv format a15

column object_owner format a10

column object_name format a25

set pagesize 500

SELECT username, sys_priv, object_owner, object_name FROM dba_used_privs WHERE capture = ‘user_priv_capture’;

SQL> SQL> SQL> SQL> SQL>

USERNAME     SYS_PRIV        OBJECT_OWN OBJECT_NAME

———— ————— ———- ————————-

TEST         CREATE SESSION

TEST                               SYS        USER_TABLES

APEX_040200                  SYS        DBMS_OUTPUT

TEST         CREATE SESSION

TEST         CREATE SESSION

TEST         CREATE SESSION

TEST         CREATE SESSION

TEST                               SYS        DUAL

APEX_040200                  SYS        DBMS_OUTPUT

TEST         CREATE SESSION

TEST         CREATE SESSION

TEST         CREATE SESSION

TEST                               SYS        DUAL

APEX_040200                  SYS        DEFAULT_JOB_CLASS

TEST         CREATE SESSION

TEST                               SYSTEM     PRODUCT_PRIVS

TEST                               SYS        DBMS_APPLICATION_INFO

 

17 rows selected.

 

SQL>

  1. Optionally, drop the privilege analysis policy.

 

EXEC DBMS_PRIVILEGE_CAPTURE.DROP_CAPTURE (‘user_priv_capture’);

 

Larry Catt

OCP

Oracle 12c – Secure file LOBs

In Oracle 12c SecureFiles is now the default storage of LOB when the COMPATIBLE parameter is set to 12.1 or higher.  SecureFiles gives better performance than BasicFiles for unstructured objects.  The following enhancements have been made to SecureFiles:

 

  1. PDML Operations – parallel DML operations for non-partitioned tables containing SecureFile LOB columns, table cannot contain BasicFile LOB columns. Operations which can use parallelism include:
    1. insert
    2. insert as select
    3. create table as select
    4. delete
    5. update
    6. merger (conditional update and insert)
    7. multi-table insert
    8. SQL*Loader
    9. Import/Export
  2. LogMiner – LogMiner now fully supports SecureFiles LOBs (deduplication of SecureFile LOB SecureFile Database File System (DBFS). Only SQL_REDO columns are filled in SecureFile LOB, SQL_UNDO is not used.

 

 

Larry Catt

OCP

Oracle 12c – Flashback Transaction Query

Flashback Transaction Query is used to retrieve metadata and historical data for single and all transactions in a time interval from a static data dictionary view FLASHBACK_TRANSACTION_QUERY.

The FLASHBACK_TRANSACTION_QUERY has a column UNDO_SQL which is the opposite of DML which caused the change.  You can use the DBMS_FLASHBACK.TRANSACTION_BACKOUT procedure to roll back transaction and dependent transactions.   This procedure does not commit the rollback but temporarily holds the rollback until a manual commit is made.  To perform the flashback transaction query the database must be in archivelog mode and supplemental logging must be enabled with command:  ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

 

For a user to use the flashback query the admin must grant following.

  1. Grant flashback to user.
  2. Grant select privileges on objects.
  3. To allow queries on all tables grant FLASHBACK ANY TABLE privilege.
  4. Grant SELECT ANY TRANSACTION privilege.
  5. Must have SELECT, UPDATE, DELETE, INSERT privilege on that table.
  6. Execute privilege on DBMS_FLASHBACK package.

 

This article details setting up flashback transactions for your database, granting user scott the appropriate privileges, and performing flashback.

 

  1. Logon to your SQLPLUS as sysdba.

 

[oracle@linux2 flash_recovery_area]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Fri Jan 6 08:25:35 2017

 

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

 

SQL>

 

  1. Verify that the database is in archivelog mode, if not switch to archive log mode.

 

SQL> archive log list

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     2708

Next log sequence to archive   2710

Current log sequence           2710

SQL>

 

  1. Issue the command ‘ ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;’

 

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

Database altered.

SQL>

 

  1. To allow queries on all tables grant FLASHBACK ANY TABLE privilege.

 

SQL> grant flashback any table to scott;

Grant succeeded.

SQL>

 

  1. Grant SELECT ANY TRANSACTION privilege.

 

SQL> grant select any transaction to scott;

Grant succeeded.

SQL>

 

  1. Execute privilege on DBMS_FLASHBACK package.

 

SQL> grant execute on dbms_flashback to scott;

Grant succeeded.

SQL>

 

  1. Logon as the user scott.

 

SQL> connect scott/password

Connected.

SQL>

 

  1. Create the test table fb_test.

 

create table fb_test(fname varchar2(30), amt number);

SQL> create table fb_test(fname varchar2(30), amt number);

Table created.

SQL>

 

  1. Insert single record into fb_test.

 

insert into scott.fb_test(fname,amt) values(‘Larry’,111);

commit;

 

 

SQL> insert into scott.fb_test(fname,amt) values(‘Larry’,111);

commit;

1 row created.

SQL>

Commit complete.

SQL>

 

  1. Update single record and commit;

 

update scott.fb_test set amt=222 where fname=’Larry’;

commit;

 

 

SQL> update scott.fb_test set amt=222 where fname=’Larry’;

commit;

1 row updated.

SQL>

Commit complete.

SQL>

 

 

  1. Select value from scott.fb_test.

 

SQL> select * from scott.fb_test;

FNAME                                 AMT

—————————— ———-

Larry                                 222

SQL>

 

  1. Query flashback_transaction_query for transactions against scott.fb_test.

 

SQL> select operation, undo_sql  from flashback_transaction_query

where table_name=’FB_TEST’;  2

OPERATION

——————————–

UNDO_SQL

——————————————————————————–

INSERT

delete from “SCOTT”.”FB_TEST” where ROWID = ‘AAAXaKAAGAAALUdAAA’;

UPDATE

update “SCOTT”.”FB_TEST” set “AMT” = ‘111’ where ROWID = ‘AAAXaKAAGAAALUdAAA’;

SQL>

 

  1. You can now execute the UNDO_SQL column to rewind the update statement.

 

SQL> update “SCOTT”.”FB_TEST” set “AMT” = ‘111’ where ROWID = ‘AAAXaKAAGAAALUdAAA’;

1 row updated.

SQL> commit;

Commit complete.

SQL>

 

  1. For a more complex set of updates impacting muptiple objects, you would use the dbms_flashback.transaction_backout procedure.

 

  1. This completes flashback transaction query.

 

 

Larry Catt

OCP

Oracle tips and tricks.