【Oracle】v$表和v_$同義詞的訪問許可權
買了最新的11gr2tom kyte的書程式設計藝術,參考其中的例子做實驗,發現:
yang@RAC> create or replace view stats
2 as select 'STAT...' || a.name name, b.value
3 from v$statname a, v$mystat b
4 where a.statistic# = b.statistic#
5 union all
6 select 'LATCH.' || name, gets
7 from v$latch
8 union all
9 select 'STAT...Elapsed Time', hsecs from v$timer;
from v$statname a, v$mystat b
*
ERROR at line 3:
ORA-01031: insufficient privileges
單獨查詢則是可以的。
yang@RAC> select 'STAT...' || a.name name, my.value
2 from v$statname a, v$mystat my
3 where a.statistic# = my.statistic# and rownum < 5;
NAME VALUE
----------------------------------------------------------------------- ----------
STAT...OS CPU Qt wait time 0
STAT...logons cumulative 1
STAT...logons current 1
STAT...opened cursors cumulative 101
查詢之後,瞭解到對於v$物件,並不是檢視,而是指向v_$檢視的同義詞,而檢視是基於真正的v$檢視建立的,包括X$,這些物件是Oracle資料庫的執行基礎,在資料庫啟動時由Oracle應用程式動態建立。
這部分表對資料庫來說至關重要,所以Oracle不允許SYSDBA之外的使用者直接訪問,顯示授權不被允許。
sys@RAC> grant select on v_$statname to yang;
Grant succeeded.
sys@RAC>
sys@RAC>
sys@RAC> grant select on v_$latch to yang;
Grant succeeded.
sys@RAC> grant select on v_$timer to yang;
Grant succeeded.
sys@RAC> conn yang/yang
Connected.
yang@RAC>
yang@RAC> drop table run_stats;
Table dropped.
yang@RAC> @runstats_pkg.sql
SP2-0310: unable to open file "runstats_pkg.sql"
yang@RAC> !ls
big_table.sql ch00 ch02 ch04 ch06 ch08 ch10 ch12 ch14 ch16 login.sql mystat.sql show_space.sql
book.zip ch01 ch03 ch05 ch07 ch09 ch11 ch13 ch15 demobld.sql mystat2.sql runstats.sql tk.sql
yang@RAC> @runstats.sql
yang@RAC> set echo on
yang@RAC>
yang@RAC> drop table run_stats;
drop table run_stats
*
ERROR at line 1:
ORA-00942: table or view does not exist
yang@RAC> create global temporary table run_stats
2 ( runid varchar2(15),
3 name varchar2(80),
4 value int )
5 on commit preserve rows;
Table created.
yang@RAC>
yang@RAC> grant select any table to yang;
Grant succeeded.
yang@RAC> create or replace view stats
2 as select 'STAT...' || a.name name, b.value
3 from v$statname a, v$mystat b
4 where a.statistic# = b.statistic#
5 union all
6 select 'LATCH.' || name, gets
7 from v$latch
8 union all
9 select 'STAT...Elapsed Time', hsecs from v$timer;
View created.
yang@RAC>
yang@RAC>
yang@RAC> delete from run_stats;
0 rows deleted.
yang@RAC> commit;
Commit complete.
yang@RAC>
yang@RAC> create or replace package runstats_pkg
2 as
3 procedure rs_start;
4 procedure rs_middle;
5 procedure rs_stop( p_difference_threshold in number default 0 );
6 end;
7 /
Package created.
yang@RAC>
yang@RAC> create or replace package body runstats_pkg
2 as
3
4 g_start number;
5 g_run1 number;
6 g_run2 number;
7
8 procedure rs_start
9 is
10 begin
11 delete from run_stats;
12
13 insert into run_stats
14 select 'before', stats.* from stats;
15
16 g_start := dbms_utility.get_cpu_time;
17 end;
18
19 procedure rs_middle
20 is
21 begin
22 g_run1 := (dbms_utility.get_cpu_time-g_start);
23
24 insert into run_stats
25 select 'after 1', stats.* from stats;
26 g_start := dbms_utility.get_cpu_time;
27
28 end;
29
30 procedure rs_stop(p_difference_threshold in number default 0)
31 is
32 begin
33 g_run2 := (dbms_utility.get_cpu_time-g_start);
34
35 dbms_output.put_line
36 ( 'Run1 ran in ' || g_run1 || ' cpu hsecs' );
37 dbms_output.put_line
38 ( 'Run2 ran in ' || g_run2 || ' cpu hsecs' );
39 if ( g_run2 <> 0 )
40 then
41 dbms_output.put_line
42 ( 'run 1 ran in ' || round(g_run1/g_run2*100,2) ||
43 '% of the time' );
44 end if;
45 dbms_output.put_line( chr(9) );
46
47 insert into run_stats
48 select 'after 2', stats.* from stats;
49
50 dbms_output.put_line
51 ( rpad( 'Name', 30 ) || lpad( 'Run1', 12 ) ||
52 lpad( 'Run2', 12 ) || lpad( 'Diff', 12 ) );
53
54 for x in
55 ( select rpad( a.name, 30 ) ||
56 to_char( b.value-a.value, '999,999,999' ) ||
57 to_char( c.value-b.value, '999,999,999' ) ||
58 to_char( ( (c.value-b.value)-(b.value-a.value)), '999,999,999' ) data
59 from run_stats a, run_stats b, run_stats c
60 where a.name = b.name
61 and b.name = c.name
62 and a.runid = 'before'
63 and b.runid = 'after 1'
64 and c.runid = 'after 2'
65 -- and (c.value-a.value) > 0
66 and abs( (c.value-b.value) - (b.value-a.value) )
67 > p_difference_threshold
68 order by abs( (c.value-b.value)-(b.value-a.value))
69 ) loop
70 dbms_output.put_line( x.data );
71 end loop;
72
73 dbms_output.put_line( chr(9) );
74 dbms_output.put_line
75 ( 'Run1 latches total versus runs -- difference and pct' );
76 dbms_output.put_line
77 ( lpad( 'Run1', 12 ) || lpad( 'Run2', 12 ) ||
78 lpad( 'Diff', 12 ) || lpad( 'Pct', 10 ) );
79
80 for x in
81 ( select to_char( run1, '999,999,999' ) ||
82 to_char( run2, '999,999,999' ) ||
83 to_char( diff, '999,999,999' ) ||
84 to_char( round( run1/decode( run2, 0, to_number(0), run2) *100,2 ), '99,999.99' ) || '%' data
85 from ( select sum(b.value-a.value) run1, sum(c.value-b.value) run2,
86 sum( (c.value-b.value)-(b.value-a.value)) diff
87 from run_stats a, run_stats b, run_stats c
88 where a.name = b.name
89 and b.name = c.name
90 and a.runid = 'before'
91 and b.runid = 'after 1'
92 and c.runid = 'after 2'
93 and a.name like 'LATCH%'
94 )
95 ) loop
96 dbms_output.put_line( x.data );
97 end loop;
98 end;
99
100 end;
101 /
Package body created.
這次可以了。。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-708261/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 授權訪問使用者的所有表.、批量建立和表名一致的同義詞
- android自定義訪問許可權permissionAndroid訪問許可權
- java的訪問許可權Java訪問許可權
- 自定義Android應用的訪問許可權Android訪問許可權
- SQLServer控制使用者訪問許可權表SQLServer訪問許可權
- Oracle中定義者許可權和呼叫者許可權案例分析Oracle
- Java 訪問許可權控制(6)Java訪問許可權
- mongoDB 3.0 安全許可權訪問MongoDB
- Swift4.0 訪問許可權Swift訪問許可權
- AndroidPermission訪問許可權大全Android訪問許可權
- public, private, protected 訪問許可權訪問許可權
- C++中封裝和繼承的訪問許可權C++封裝繼承訪問許可權
- Oracle資料鏈+同義詞+訪問遠端資料庫Oracle資料庫
- 授權與同義詞
- 對定義者許可權和呼叫者許可權的理解
- Oracle的物件許可權、角色許可權、系統許可權Oracle物件
- 【Oracle】-【同義詞】-public與非public同義詞Oracle
- 使用nginx控制ElasticSearch訪問許可權NginxElasticsearch訪問許可權
- Think IN JAVA --------JAVA訪問許可權控制Java訪問許可權
- Oracle建立表空間、建立使用者、授權、授權物件的訪問以及檢視許可權集合Oracle物件
- mysql-v8.x設定許可權可以遠端訪問MySql
- Oracle使用者訪問許可權與PUBLIC角色的關係Oracle訪問許可權
- 儲存過程,角色相關的呼叫者許可權和定義者許可權問題儲存過程
- SQLServer訪問Oracle(通過同義詞-檢視-資料字典)出現的問題SQLServerOracle
- android:各種訪問許可權PermissionAndroid訪問許可權
- Java:談談protected訪問許可權薦Java訪問許可權
- Oracle中的同義詞SYNONYMOracle
- win共享檔案沒有許可權訪問怎麼辦 win10共享檔案許可權訪問的方法Win10
- win10老跳出訪問許可權怎麼辦_win10訪問許可權怎麼關閉Win10訪問許可權
- ORACLE許可權Oracle
- Java中類的成員方法和變數的訪問許可權Java變數訪問許可權
- win7訪問xp您沒有許可權訪問 共享。請與網路管理員聯絡請求訪問許可權Win7訪問許可權
- postgresql關於訪問檢視需要的許可權SQL
- 論Java訪問許可權控制的重要性Java訪問許可權
- Ubuntu共享資料夾訪問許可權問題Ubuntu訪問許可權
- 物件、同義詞和公有同義詞順序選取物件
- ORACLE公有/私有同義詞Oracle
- Swift 中 Selector 方法的訪問許可權控制問題Swift訪問許可權