Bo's Oracle Station

查看: 2446|回复: 0

课程第53/54/55次(2017-09-15星期五和2017-09-17星期天上下午)

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2017-9-17 11:59:46 | 显示全部楼层 |阅读模式
第三阶段New Feature/OCM Exam Preparation31-55
  1. select  * from dba_views v
  2. where v.view_name='DBA_AUDIT_TRAIL';

  3. select  * from dba_tables t
  4.   where t.owner='SYS'  and t.table_name='AUD


  5. ;
  6.   
  7.   create tablespace tbsaudit  datafile    size 50M autoextend on;
  8.   
  9.   alter table aud$ move tablespace tbsaudit;
  10.   
  11. select  bytes/1024/1024  from dba_segments s where s.segment_name='AUD


  12. ;

  13. select  * from dba_obj_audit_opts;

  14. select  * from dba_priv_audit_opts order by privilege;

  15. select  * from dba_stmt_audit_opts
  16. minus
  17.   select  * from dba_priv_audit_opts;
  18.   
  19.   select * from dba_audit_trail t
  20.    where t.username not in ( 'DBSNMP','SYSMAN')
  21.    order by t.timestamp  desc
  22.    ;
  23.    
  24.    noaudit create session ;
  25.    
  26.    
  27.    audit create session by hr whenever  successful  ;
  28.    
  29.   noaudit drop any table;
  30.    
  31.   grant resource to user1;
  32.    ----
  33.    ---
  34.    audit view by hr whenever successful;
  35.    ------
  36.    
  37.    
  38.    
  39.    
  40.    
复制代码
  1. select  * from dba_views v
  2. where v.view_name='DBA_AUDIT_TRAIL';

  3. select  * from dba_tables t
  4.   where t.owner='SYS'  and t.table_name='AUD


  5. ;
  6.   
  7.   create tablespace tbsaudit  datafile    size 50M autoextend on;
  8.   
  9.   alter table aud$ move tablespace tbsaudit;
  10.   
  11. select  bytes/1024/1024  from dba_segments s where s.segment_name='AUD


  12. ;

  13. select  * from dba_obj_audit_opts;

  14. select  * from dba_priv_audit_opts order by privilege;

  15. select  * from dba_stmt_audit_opts
  16. minus
  17.   select  * from dba_priv_audit_opts;
  18.   
  19.   select * from dba_audit_trail t
  20.    where t.username not in ( 'DBSNMP','SYSMAN')
  21.    order by t.timestamp  desc
  22.    ;
  23.    
  24.    noaudit create session ;
  25.    
  26.    
  27.    audit create session by hr whenever  successful  ;
  28.    
  29.   noaudit drop any table;
  30.    
  31.   grant resource to user1;
  32.    ----
  33.    ---
  34.    audit view by hr whenever successful;
  35.    ------
  36.    
  37.    select  * from v$xml_audit_trail  order by extended_timestamp desc;
  38.    
  39.    select  * from dba_common_audit_trail t order by extended_timestamp desc;
  40.    
  41.    ----
  42.    select * from dba_users
  43.      where username='HR';
  44.      
  45.      create tablespace tbs1 datafile size 5M
  46.      encryption  using 'aes256'
  47.      default storage(encrypt);
  48.      
  49.      create table hr.t11( a number )  tablespace tbs1;
  50.      
  51.      insert into hr.t11 values (111);
  52.    commit;
  53.    
  54.    
复制代码
  1. select  * from dba_flashback_archive;

  2. select * from dba_flashback_archive_ts;

  3. select * from dba_flashback_archive_tables;

  4. select  * from dba_tablespaces;

  5. create tablespace tbsfdba1 datafile '/u01/app/oracle/oradata/orcl/tbsfbda1.dbf' size 50M ;

  6. create flashback archive fba1 tablespace tbsfdba1
  7. quota 10M retention 2 year;

  8. create tablespace tbsfdba2 datafile '/u01/app/oracle/oradata/orcl/tbsfbda2.dbf' size 50M ;

  9. alter flashback archive fba1 add tablespace tbsfdba2 quota 10M;
复制代码
  1. [oracle@station17 ~]$ sqlplus /nolog

  2. SQL*Plus: Release 11.2.0.1.0 Production on Thu Sep 21 00:25:14 2017

  3. Copyright (c) 1982, 2009, Oracle.  All rights reserved.

  4. SQL> conn hr/hr     
  5. Connected.
  6. SQL> alter table employees flashback archive fba1  ;

  7. Table altered.

  8. SQL> select object_id from user_objects  where object_name='EMPLOYEES';

  9. OBJECT_ID
  10. ----------
  11.      73933

  12. SQL> select  salary from employees where employee_id=100;

  13.     SALARY
  14. ----------
  15.      24000

  16. SQL> update employees  set salary=25000 where employee_id=100;

  17. 1 row updated.

  18. SQL> commit;

  19. Commit complete.

  20. SQL> select  * from hr.sys_fba_hist_73933;
  21. select        * from hr.sys_fba_hist_73933
  22.                   *
  23. ERROR at line 1:
  24. ORA-00942: table or view does not exist


  25. SQL> select  * from hr.sys_fba_hist_73933;
  26. select        * from hr.sys_fba_hist_73933
  27.                   *
  28. ERROR at line 1:
  29. ORA-00942: table or view does not exist


  30. SQL> select  * from hr.sys_fba_hist_73933;

  31. 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
  32. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- ---------- ---------------- - ----------- -------------------- ------------------------- ------------------------- -------------------- ------------------ ---------- ---------- -------------- ---------- -------------
  33. AAAR5VAAFAAAADPAAA                                                                                                                               2572167                                  100 Steven                   King                      SKING                       515.123.4567            17-JUN-03               AD_PRES               24000                                          90

  34. SQL> update hr.sys_fba_hist_73933 set salary=40000 where rid='AAAR5VAAFAAAADPAAA';
  35. update hr.sys_fba_hist_73933 set salary=40000 where rid='AAAR5VAAFAAAADPAAA'
  36.           *
  37. ERROR at line 1:
  38. ORA-55622: DML, ALTER and CREATE UNIQUE INDEX operations are not allowed on table "HR"."SYS_FBA_HIST_73933"


  39. SQL> select  * frm departments;
  40. select        * frm departments
  41.           *
  42. ERROR at line 1:
  43. ORA-00923: FROM keyword not found where expected


  44. SQL> select  * from departments;

  45. DEPARTMENT_ID DEPARTMENT_NAME                     MANAGER_ID LOCATION_ID
  46. ------------- ------------------------------ ---------- -----------
  47.            10 Administration                            200        1700
  48.            20 Marketing                             201        1800
  49.            30 Purchasing                            114        1700
  50.            40 Human Resources                            203        2400
  51.            50 Shipping                                    121        1500
  52.            60 IT                                    103        1400
  53.            70 Public Relations                            204        2700
  54.            80 Sales                                    145        2500
  55.            90 Executive                             100        1700
  56.           100 Finance                                    108        1700
  57.           110 Accounting                            205        1700
  58.           120 Treasury                                               1700
  59.           130 Corporate Tax                                       1700
  60.           140 Control And Credit                               1700
  61.           150 Shareholder Services                               1700
  62.           160 Benefits                                               1700
  63.           170 Manufacturing                                       1700
  64.           180 Construction                                       1700
  65.           190 Contracting                                       1700
  66.           200 Operations                                       1700
  67.           210 IT Support                                       1700
  68.           220 NOC                                               1700
  69.           230 IT Helpdesk                                       1700
  70.           240 Government Sales                                       1700
  71.           250 Retail Sales                                       1700
  72.           260 Recruiting                                       1700
  73.           270 Payroll                                               1700

  74. 27 rows selected.

  75. SQL> update departments  set DEPARTMENT_NAME='XXX' where department_id=270;

  76. 1 row updated.

  77. SQL> commit;

  78. Commit complete.

  79. SQL> select  sysdate from dual;

  80. SYSDATE
  81. ------------------
  82. 21-SEP-17

  83. SQL> select  to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS')  from dual;

  84. TO_CHAR(SYSDATE,'YY
  85. -------------------
  86. 2017-09-21:00:35:10

  87. SQL> select  * from departments as of timestamp
  88.   2   to_timestamp('2017-09-21:00:34:10','YYYY-MM-DD:HH24:MI:SS')  where department_id=270;

  89. DEPARTMENT_ID DEPARTMENT_NAME                     MANAGER_ID LOCATION_ID
  90. ------------- ------------------------------ ---------- -----------
  91.           270 Payroll                                               1700

  92. SQL> select  * from employees as of scn      
  93.   2  2572167 where employee_id=100;

  94. EMPLOYEE_ID FIRST_NAME                 LAST_NAME                   EMAIL                     PHONE_NUMBER          HIRE_DATE             JOB_ID            SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
  95. ----------- -------------------- ------------------------- ------------------------- -------------------- ------------------ ---------- ---------- -------------- ---------- -------------
  96.         100 Steven                 King                           SKING                     515.123.4567          17-JUN-03             AD_PRES             25000                                        90

  97. SQL> select  * from employees as of scn
  98.   2  2572166 where employee_id=100;

  99. EMPLOYEE_ID FIRST_NAME                 LAST_NAME                   EMAIL                     PHONE_NUMBER          HIRE_DATE             JOB_ID            SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
  100. ----------- -------------------- ------------------------- ------------------------- -------------------- ------------------ ---------- ---------- -------------- ---------- -------------
  101.         100 Steven                 King                           SKING                     515.123.4567          17-JUN-03             AD_PRES             24000                                        90

  102. SQL> /

  103. EMPLOYEE_ID FIRST_NAME                 LAST_NAME                   EMAIL                     PHONE_NUMBER          HIRE_DATE             JOB_ID            SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
  104. ----------- -------------------- ------------------------- ------------------------- -------------------- ------------------ ---------- ---------- -------------- ---------- -------------
  105.         100 Steven                 King                           SKING                     515.123.4567          17-JUN-03             AD_PRES             24000                                        90

  106. SQL> select  * from departments as of timestamp
  107.   2   to_timestamp('2017-09-21:00:34:10','YYYY-MM-DD:HH24:MI:SS')  where department_id=270;
  108. select        * from departments as of timestamp
  109.                *
  110. ERROR at line 1:
  111. ORA-01555: snapshot too old: rollback segment number  with name "" too small


  112. SQL> select versions_xid, versions_startscn , versions_operation , salary  
  113.   2  from employees
  114.   3  versions between scn minvalue and maxvalue
  115.   4  where employee_id=100;

  116. VERSIONS_XID         VERSIONS_STARTSCN V         SALARY
  117. ---------------- ----------------- - ----------
  118.                                           24000
  119. 05001E00AB040000           2572167 U          25000

  120. SQL> select versions_xid, versions_startscn , versions_operation , department_name
  121.   2  from departments
  122.   3  versions between scn minvalue and maxvalue
  123.   4  where department_id=270;
  124. from departments
  125.      *
  126. ERROR at line 2:
  127. ORA-01555: snapshot too old: rollback segment number  with name "" too small


  128. SQL> alter table employees enable row movement;

  129. Table altered.

  130. SQL> flashback table employees to scn 2572166;
  131. flashback table employees to scn 2572166
  132.                 *
  133. ERROR at line 1:
  134. ORA-00604: error occurred at recursive SQL level 1
  135. ORA-01555: snapshot too old: rollback segment number  with name "" too small


  136. SQL>
复制代码
  1. SQL> show user
  2. USER is "HR"
  3. SQL> create table new19_a( a number , b varchar2(20))  ;

  4. Table created.

  5. SQL> create table new19_b( a number , b varchar2(20))  ;

  6. Table created.

  7. SQL> insert into new19_a values ( 1 ,'A') ;

  8. 1 row created.

  9. SQL> insert into new19_b values ( 1 ,'A') ;

  10. 1 row created.

  11. SQL> commit;

  12. Commit complete.

  13. SQL> select  to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS')  from dual;

  14. TO_CHAR(SYSDATE,'YY
  15. -------------------
  16. 2017-09-21:00:48:53

  17. SQL> alter table new19_a  flashback archive fba1  ;  

  18. Table altered.

  19. SQL> update new19_a set a=2 where a=1;

  20. 1 row updated.

  21. SQL> update new19_b set a=2 where a=1;

  22. 1 row updated.

  23. SQL> commit;

  24. Commit complete.

  25. SQL> select   * from new19_a  as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS')  ;

  26.          A B
  27. ---------- --------------------
  28.          1 A

  29. SQL> select   * from new19_b  as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS')  ;

  30.          A B
  31. ---------- --------------------
  32.          1 A

  33. SQL> alter table new19_a drop ( b ) ;

  34. Table altered.

  35. SQL> alter table new19_b drop ( b ) ;

  36. Table altered.

  37. SQL> select   * from new19_b  as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS')  ;
  38. select         * from new19_b  as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS')
  39.                 *
  40. ERROR at line 1:
  41. ORA-01466: unable to read data - table definition has changed


  42. SQL>  select   * from new19_a  as of timestamp to_timestamp('2017-09-21:00:48:53','YYYY-MM-DD:HH24:MI:SS')  ;

  43.          A B
  44. ---------- --------------------
  45.          1 A

  46. SQL>

复制代码
  1. select  * from dba_flashback_archive;

  2. alter flashback archive fba1 set default;

  3. select  * from dba_flashback_archive_ts;

  4. alter flashback archive fba1 modify tablespace tbsfdba2 quota 0;

  5. alter flashback archive fba1  remove  tablespace tbsfdba2;

  6. select  * from dba_flashback_archive_tables;

  7. select  * from hr.sys_fba_hist_73933;

  8. select  * from hr.sys_fba_hist_76373;

  9. select  * from hr.sys_fba_hist_76374;

  10. alter flashback archive fba1 modify retention 5 day;

  11. alter flashback archive fba1 purge before  timestamp  ( sysdate - numtodsinterval('1','second')) ;
复制代码




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-19 13:59 , Processed in 0.114655 second(s), 24 queries .

快速回复 返回顶部 返回列表