======= flashback =======
===== 확인 =====
- $ sqlplus / as sysdba
- SQL> select instance_name from v$instance;
- SQL> show user
- export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
==== HR 계정 활성화 ====
- SQL> alter user hr identified by oracle account unlock;
- SQL> grant execute on dbms_flashback to hr;
==== HR 계정으로 접속 ====
- sqlplus hr/oracle
- SQL> select systimestamp from dual;
==== HR 계정으로 AS OF SCN ====
- SQL> create table emp2 as select * from emp;
- SQL> select dbms_flashback.get_system_change_number() from dual;
- SQL> select count(*) from emp2;
- SQL> delete from emp2;
- SQL> select count(*) from emp2;
- SQL> select count(*) from emp2 as of scn ;
- SQL> insert into emp2 select * from emp2 as of scn ;
-
==== HR 계정으로 AS OF TIMESTAMP ====
- SQL> select systimestamp from dual;
- SQL> select count(1) from emp2;
- SQL> delete from emp2 where deptno=30;
- SQL> commit;
- SQL> select systimestamp from dual;
- SQL> select count(*) from emp2;
- SQL> select count(*) from emp2
as of timestamp(to_timestamp('2015-06-20 16:42:00','YYYY-MM-DD HH24:MI:SS'));
- SQL> select count(*) from emp2
as of timestamp(to_timestamp('2015-06-20 16:42:00','YYYY-MM-DD HH24:MI:SS')) where deptno=30;
- SQL> insert into emp2 select * from emp2
as of timestamp(to_timestamp('2015-06-20 16:42:00','YYYY-MM-DD HH24:MI:SS')) where deptno=30;
==== HR 계정 flashback version query ====
-
SQL> create table emp as select * from scott.emp;
SQL> select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from dual;
2015-06-20 16:57:28
SQL> update emp set comm=1234 where empno=7782;
SQL> commit;
SQL> update emp set comm=3456 where empno=7782;
SQL> rollback;
SQL> update emp set comm=5678 where empno=7782;
SQL> commit;
SQL> update emp set comm=7890 where empno=7782;
SQL> commit;
SQL> select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from dual;
2015-06-20 17:01:08
SQL>
set lines 200
column ename format a10
column start_time format a20
column end_time format a20
SELECT empno, ename, sal, comm, deptno,
versions_xid AS XID,
versions_operation as operation,
versions_startscn AS START_SCN,
versions_starttime as start_time,
versions_endscn AS END_SCN,
versions_endtime as end_time
FROM emp VERSIONS BETWEEN TIMESTAMP
TO_TIMESTAMP('2015-06-20 16:57:27','YYYY-MM-DD HH24:MI:SS')
AND TO_TIMESTAMP('2015-06-20 17:01:09','YYYY-MM-DD HH24:MI:SS')
WHERE empno=7782
order by versions_starttime nulls first;