|
第三阶段New Feature/OCM Exam Preparation(31-55)- select * from dba_views v
- where v.view_name='DBA_AUDIT_TRAIL';
-
- select * from dba_tables t
- where t.owner='SYS' and t.table_name='AUD
- ;
-
- create tablespace tbsaudit datafile size 50M autoextend on;
-
- alter table aud$ move tablespace tbsaudit;
-
- select bytes/1024/1024 from dba_segments s where s.segment_name='AUD
- ;
-
- select * from dba_obj_audit_opts;
-
- select * from dba_priv_audit_opts order by privilege;
-
- select * from dba_stmt_audit_opts
- minus
- select * from dba_priv_audit_opts;
-
- select * from dba_audit_trail t
- where t.username not in ( 'DBSNMP','SYSMAN')
- order by t.timestamp desc
- ;
-
- noaudit create session ;
-
-
- audit create session by hr whenever successful ;
-
- noaudit drop any table;
-
- grant resource to user1;
- ----
- ---
- audit view by hr whenever successful;
- ------
-
-
-
-
-
复制代码- select * from dba_views v
- where v.view_name='DBA_AUDIT_TRAIL';
-
- select * from dba_tables t
- where t.owner='SYS' and t.table_name='AUD
- ;
-
- create tablespace tbsaudit datafile size 50M autoextend on;
-
- alter table aud$ move tablespace tbsaudit;
-
- select bytes/1024/1024 from dba_segments s where s.segment_name='AUD
- ;
-
- select * from dba_obj_audit_opts;
-
- select * from dba_priv_audit_opts order by privilege;
-
- select * from dba_stmt_audit_opts
- minus
- select * from dba_priv_audit_opts;
-
- select * from dba_audit_trail t
- where t.username not in ( 'DBSNMP','SYSMAN')
- order by t.timestamp desc
- ;
-
- noaudit create session ;
-
-
- audit create session by hr whenever successful ;
-
- noaudit drop any table;
-
- grant resource to user1;
- ----
- ---
- audit view by hr whenever successful;
- ------
-
- select * from v$xml_audit_trail order by extended_timestamp desc;
-
- select * from dba_common_audit_trail t order by extended_timestamp desc;
-
- ----
- select * from dba_users
- where username='HR';
-
- create tablespace tbs1 datafile size 5M
- encryption using 'aes256'
- default storage(encrypt);
-
- create table hr.t11( a number ) tablespace tbs1;
-
- insert into hr.t11 values (111);
- commit;
-
-
复制代码- select * from dba_flashback_archive;
- select * from dba_flashback_archive_ts;
- select * from dba_flashback_archive_tables;
- select * from dba_tablespaces;
- create tablespace tbsfdba1 datafile '/u01/app/oracle/oradata/orcl/tbsfbda1.dbf' size 50M ;
- create flashback archive fba1 tablespace tbsfdba1
- quota 10M retention 2 year;
- create tablespace tbsfdba2 datafile '/u01/app/oracle/oradata/orcl/tbsfbda2.dbf' size 50M ;
- alter flashback archive fba1 add tablespace tbsfdba2 quota 10M;
复制代码- [oracle@station17 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Thu Sep 21 00:25:14 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/hr
- Connected.
- SQL> alter table employees flashback archive fba1 ;
- Table altered.
- SQL> select object_id from user_objects where object_name='EMPLOYEES';
- OBJECT_ID
- ----------
- 73933
- SQL> select salary from employees where employee_id=100;
- SALARY
- ----------
- 24000
- SQL> update employees set salary=25000 where employee_id=100;
- 1 row updated.
- SQL> commit;
- Commit complete.
- SQL> select * from hr.sys_fba_hist_73933;
- select * from hr.sys_fba_hist_73933
- *
- ERROR at line 1:
- ORA-00942: table or view does not exist
- SQL> select * from hr.sys_fba_hist_73933;
- select * from hr.sys_fba_hist_73933
- *
- ERROR at line 1:
- ORA-00942: table or view does not exist
- SQL> select * from hr.sys_fba_hist_73933;
- RID STARTSCN ENDSCN XID O EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- ---------- ---------------- - ----------- -------------------- ------------------------- ------------------------- -------------------- ------------------ ---------- ---------- -------------- ---------- -------------
- AAAR5VAAFAAAADPAAA 2572167 100 Steven King SKING 515.123.4567 17-JUN-03 AD_PRES 24000 90
- SQL> update hr.sys_fba_hist_73933 set salary=40000 where rid='AAAR5VAAFAAAADPAAA';
- update hr.sys_fba_hist_73933 set salary=40000 where rid='AAAR5VAAFAAAADPAAA'
- *
- ERROR at line 1:
- ORA-55622: DML, ALTER and CREATE UNIQUE INDEX operations are not allowed on table "HR"."SYS_FBA_HIST_73933"
- SQL> select * frm departments;
- select * frm departments
- *
- ERROR at line 1:
- ORA-00923: FROM keyword not found where expected
- SQL> select * from departments;
- DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID
- ------------- ------------------------------ ---------- -----------
- 10 Administration 200 1700
- 20 Marketing 201 1800
- 30 Purchasing 114 1700
- 40 Human Resources 203 2400
- 50 Shipping 121 1500
- 60 IT 103 1400
- 70 Public Relations 204 2700
- 80 Sales 145 2500
- 90 Executive 100 1700
- 100 Finance 108 1700
- 110 Accounting 205 1700
- 120 Treasury 1700
- 130 Corporate Tax 1700
- 140 Control And Credit 1700
- 150 Shareholder Services 1700
- 160 Benefits 1700
- 170 Manufacturing 1700
- 180 Construction 1700
- 190 Contracting 1700
- 200 Operations 1700
- 210 IT Support 1700
- 220 NOC 1700
- 230 IT Helpdesk 1700
- 240 Government Sales 1700
- 250 Retail Sales 1700
- 260 Recruiting 1700
- 270 Payroll 1700
- 27 rows selected.
- SQL> update departments set DEPARTMENT_NAME='XXX' where department_id=270;
- 1 row updated.
- SQL> commit;
- Commit complete.
- SQL> select sysdate from dual;
- SYSDATE
- ------------------
- 21-SEP-17
- SQL> select to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YY
- -------------------
- 2017-09-21:00:35:10
- SQL> select * from departments as of timestamp
- 2 to_timestamp('2017-09-21:00:34:10','YYYY-MM-DD:HH24:MI:SS') where department_id=270;
- DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID
- ------------- ------------------------------ ---------- -----------
- 270 Payroll 1700
- SQL> select * from employees as of scn
- 2 2572167 where employee_id=100;
- EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
- ----------- -------------------- ------------------------- ------------------------- -------------------- ------------------ ---------- ---------- -------------- ---------- -------------
- 100 Steven King SKING 515.123.4567 17-JUN-03 AD_PRES 25000 90
- SQL> select * from employees as of scn
- 2 2572166 where employee_id=100;
- EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
- ----------- -------------------- ------------------------- ------------------------- -------------------- ------------------ ---------- ---------- -------------- ---------- -------------
- 100 Steven King SKING 515.123.4567 17-JUN-03 AD_PRES 24000 90
- SQL> /
- EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
- ----------- -------------------- ------------------------- ------------------------- -------------------- ------------------ ---------- ---------- -------------- ---------- -------------
- 100 Steven King SKING 515.123.4567 17-JUN-03 AD_PRES 24000 90
- SQL> select * from departments as of timestamp
- 2 to_timestamp('2017-09-21:00:34:10','YYYY-MM-DD:HH24:MI:SS') where department_id=270;
- select * from departments as of timestamp
- *
- ERROR at line 1:
- ORA-01555: snapshot too old: rollback segment number with name "" too small
- SQL> select versions_xid, versions_startscn , versions_operation , salary
- 2 from employees
- 3 versions between scn minvalue and maxvalue
- 4 where employee_id=100;
- VERSIONS_XID VERSIONS_STARTSCN V SALARY
- ---------------- ----------------- - ----------
- 24000
- 05001E00AB040000 2572167 U 25000
- SQL> select versions_xid, versions_startscn , versions_operation , department_name
- 2 from departments
- 3 versions between scn minvalue and maxvalue
- 4 where department_id=270;
- from departments
- *
- ERROR at line 2:
- ORA-01555: snapshot too old: rollback segment number with name "" too small
- SQL> alter table employees enable row movement;
- Table altered.
- SQL> flashback table employees to scn 2572166;
- flashback table employees to scn 2572166
- *
- ERROR at line 1:
- ORA-00604: error occurred at recursive SQL level 1
- ORA-01555: snapshot too old: rollback segment number with name "" too small
- SQL>
复制代码- SQL> show user
- USER is "HR"
- SQL> create table new19_a( a number , b varchar2(20)) ;
- Table created.
- SQL> create table new19_b( a number , b varchar2(20)) ;
- Table created.
- SQL> insert into new19_a values ( 1 ,'A') ;
- 1 row created.
- SQL> insert into new19_b values ( 1 ,'A') ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> select to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YY
- -------------------
- 2017-09-21:00:48:53
- SQL> alter table new19_a flashback archive fba1 ;
- Table altered.
- SQL> update new19_a set a=2 where a=1;
- 1 row updated.
- SQL> update new19_b set a=2 where a=1;
- 1 row updated.
- SQL> commit;
- Commit complete.
- SQL> select * from new19_a as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS') ;
- A B
- ---------- --------------------
- 1 A
- SQL> select * from new19_b as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS') ;
- A B
- ---------- --------------------
- 1 A
- SQL> alter table new19_a drop ( b ) ;
- Table altered.
- SQL> alter table new19_b drop ( b ) ;
- Table altered.
- SQL> select * from new19_b as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS') ;
- select * from new19_b as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS')
- *
- ERROR at line 1:
- ORA-01466: unable to read data - table definition has changed
- SQL> select * from new19_a as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS') ;
- A B
- ---------- --------------------
- 1 A
- SQL>
复制代码- select * from dba_flashback_archive;
-
- alter flashback archive fba1 set default;
- select * from dba_flashback_archive_ts;
- alter flashback archive fba1 modify tablespace tbsfdba2 quota 0;
- alter flashback archive fba1 remove tablespace tbsfdba2;
- select * from dba_flashback_archive_tables;
- select * from hr.sys_fba_hist_73933;
- select * from hr.sys_fba_hist_76373;
- select * from hr.sys_fba_hist_76374;
- alter flashback archive fba1 modify retention 5 day;
- alter flashback archive fba1 purge before timestamp ( sysdate - numtodsinterval('1','second')) ;
复制代码
|
|