您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Oracle数据字典详解

2025/10/5 2:38:53发布31次查看
学习笔记:oracle 数据字典详解 --- 本文为ttt 学习笔记,首先介绍数据字典及查看方法,然后分类总结各类数据字典的表和视图。然后列出一些附例。 数据字典系统表,保存在system 表空间中。 由表和视图组成,由服务器在安装数据库时自动创建,用户不可以直接
学习笔记:oracle数据字典详解
---
本文为ttt学习笔记,首先介绍数据字典及查看方法,然后分类总结各类数据字典的表和视图。然后列出一些附例。
数据字典系统表,保存在system表空间中。
由表和视图组成,由服务器在安装数据库时自动创建,用户不可以直接修改数据库字典,在执行ddl语句时,oracle会自动修改。
记录一些表和视图(只读的),新建的表不要和这空间建在一起(9i以前的版本新用户建的表默认表空间为system,注意修改)
--查询数据字典:
select * from dictionary
--数据字典导出方法:
conn / as sysdba
spool on 
spool c:\dic.txt
select * from dictionary
spool off
主要四部分:
1,内部rdbms表:x$……
2,数据字典表:……$
3,动态性能视图:gv$……,v$……
4,数据字典视图:user_……,all_……,dba_……
数据库启动时,动态创建x$,在x$基础上创建gv$,在gv$基础上创建v$x$表-->gv$(视图)--->v$(视图)
+++
一,内部rdbms表 x$……,例如:x$kvit,x$bh,x$ksmsp,x$ksppi和x$ksppcv
核心部分,用于跟踪内部数据库信息,维持db的正常运行。
是加密命名的,不允许sysdba以外的用户直接访问,显示授权不被允许。最好不要修改.
x$kvit=kernel layer performance layer v information tables transitory instance parameter
数据库启动时,动态创建x$……
+++
二,数据字典表 ……$,如tab$,obj$,ts$……
--用来存储表、索引、约束以及其他数据库结构的信息。
--创建数据库时通过脚本sql.bsq来创建,脚本:$oracle_home/rdbms/admin/sql.bsq
+++
三,动态性能视图 gv$……,v$……,如v$parameter
--记录了db运行时信息和统计数据,大部分动态性能视图被实时更新以反映db当前状态。
--数据库创建时建立的。
--只有sysdba可以直接访问。
--查看表v$fixed_view_definition(***),可以查看gv$和v$视图的创建语句。(oracle提供一些特殊视图,用来记录其他视图的创建方式,v$fixed_view_definition就是其中之一)
--select view_definition from v$fixed_view_definition where view_name='v$fixed_table';
--gv$……=global v$,在x$……基础上创建,是为了满足ops环境(多个实例)的需要面产生的,可以返回多个实例的信息。
v$……,在gv$……基础上创建,只返回当前实例的信息。定义语句都带有:where inst_id =userenv('instance')
--gv$和v$之后,oracle建立了gv_$和v_$视图,又为这些视图建立了公用同义词。由脚本catalog.sql实现的,脚本:$oracle_home/rdbms/admin/catalog.sql
create or replace view v_$process as select * from v$process;
create or replace public synonym v$process for v_$process;
create or replace view gv_$process as select * from gv$process;
create or replace public synonym gv$process for gv_$process;
-->可以看出:
v$(视图)-->v_$(视图)-->v$(公用同义词)
gv$(视图)-->gv_$(视图)-->gv$(公用同义词)
这样做的目的:通过v_$和gv_$,oracle把v$视图和gv视图和普通用户隔离开来。(oracle允许v_$视图权限可以授权给其他用户,但不允许任何对于v$视图的直接授权。)
所以,在非sys用户下,我们访问的都是同义词,而不是v$视图或gv视图。
--oracle访问数据顺序:view-->同义词。
+++
四,数据库字典视图
--是在x$表和数据字典表之上建立的视图。
--创建数据库时由脚本catalog.sql创建。脚本 :$oracle_home/rdbms/admin/catalog.sql
--按前缀不同,作用范围的分为三类:
1、以user开头的数据字典: 包含当前用户所拥有的相关对象信息。--能够查到对象的所有者是当前用户的所有对象
select table_name from user_tables;  (scott) 5
2、以all开头的数据字典:  包含当前用户有权限访问的所有对象的信息。--能够查到所有当前用户有权限访问的对象
select table_name from all_tables;  (scott) 96
3、以dba开头的数据字典:  包含数据库所有相关对象的信息。--只能是有dba权限的用户查询,能查到数据库中所有对象
select table_name from dba_tables (sys system)
+++
附:
比较user,all,dba数据字典视图
各数据字典表数量比较
表dictionary与v$fixed_table比较
通过v$parameter视图来追踪一下数据库的架构
oracle如何通过同义词定位对象(10046事件)
+++
比较user,all,dba数据字典视图
---
可以查看脚本catalog.sql中的定义:
+++
--user_tables
create or replace view user_tables
    (table_name, tablespace_name, cluster_name, iot_name, status,
     pct_free, pct_used,
     ini_trans, max_trans,
     initial_extent, next_extent,
     min_extents, max_extents, pct_increase,
     freelists, freelist_groups, logging,
     backed_up, num_rows, blocks, empty_blocks,
     avg_space, chain_cnt, avg_row_len,
     avg_space_freelist_blocks, num_freelist_blocks,
     degree, instances, cache, table_lock,
     sample_size, last_analyzed, partitioned,
     iot_type, temporary, secondary, nested,
     buffer_pool, row_movement,
     global_stats, user_stats, duration, skip_corrupt, monitoring,
     cluster_owner, dependencies, compression, dropped)
as
select o.name, decode(bitand(t.property, 2151678048), 0, ts.name, null),
       decode(bitand(t.property, 1024), 0, null, co.name),
       decode((bitand(t.property, 512)+bitand(t.flags, 536870912)),
              0, null, co.name),
       decode(bitand(t.trigflag, 1073741824), 1073741824, 'unusable', 'valid'),
       decode(bitand(t.property, 32+64), 0, mod(t.pctfree$, 100), 64, 0, null),
       decode(bitand(ts.flags, 32), 32, to_number(null),
          decode(bitand(t.property, 32+64), 0, t.pctused$, 64, 0, null)),
       decode(bitand(t.property, 32), 0, t.initrans, null),
       decode(bitand(t.property, 32), 0, t.maxtrans, null),
       s.iniexts * ts.blocksize,
       decode(bitand(ts.flags, 3), 1, to_number(null),
                                      s.extsize * ts.blocksize),
       s.minexts, s.maxexts,
       decode(bitand(ts.flags, 3), 1, to_number(null),
                                      s.extpct),
       decode(bitand(ts.flags, 32), 32, to_number(null),
         decode(bitand(o.flags, 2), 2, 1, decode(s.lists, 0, 1, s.lists))),
       decode(bitand(ts.flags, 32), 32, to_number(null),
         decode(bitand(o.flags, 2), 2, 1, decode(s.groups, 0, 1, s.groups))),
       decode(bitand(t.property, 32+64), 0,
                decode(bitand(t.flags, 32), 0, 'yes', 'no'), null),
       decode(bitand(t.flags,1), 0, 'y', 1, 'n', '?'),
       t.rowcnt,
       decode(bitand(t.property, 64), 0, t.blkcnt, null),
       decode(bitand(t.property, 64), 0, t.empcnt, null),
       decode(bitand(t.property, 64), 0, t.avgspc, null),
       t.chncnt, t.avgrln, t.avgspc_flb,
       decode(bitand(t.property, 64), 0, t.flbcnt, null),
       lpad(decode(t.degree, 32767, 'default', nvl(t.degree,1)),10),
       lpad(decode(t.instances, 32767, 'default', nvl(t.instances,1)),10),
       lpad(decode(bitand(t.flags, 8), 8, 'y', 'n'),5),
       decode(bitand(t.flags, 6), 0, 'enabled', 'disabled'),
       t.samplesize, t.analyzetime,
       decode(bitand(t.property, 32), 32, 'yes', 'no'),
       decode(bitand(t.property, 64), 64, 'iot',
               decode(bitand(t.property, 512), 512, 'iot_overflow',
               decode(bitand(t.flags, 536870912), 536870912, 'iot_mapping', null))),
       decode(bitand(o.flags, 2), 0, 'n', 2, 'y', 'n'),
       decode(bitand(o.flags, 16), 0, 'n', 16, 'y', 'n'),
       decode(bitand(t.property, 8192), 8192, 'yes',
              decode(bitand(t.property, 1), 0, 'no', 'yes')),
       decode(bitand(o.flags, 2), 2, 'default',
             decode(s.cachehint, 0, 'default', 1, 'keep', 2, 'recycle', null)),
       decode(bitand(t.flags, 131072), 131072, 'enabled', 'disabled'),
       decode(bitand(t.flags, 512), 0, 'no', 'yes'),
       decode(bitand(t.flags, 256), 0, 'no', 'yes'),
       decode(bitand(o.flags, 2), 0, null,
           decode(bitand(t.property, 8388608), 8388608,
                  'sys$session', 'sys$transaction')),
       decode(bitand(t.flags, 1024), 1024, 'enabled', 'disabled'),
       decode(bitand(o.flags, 2), 2, 'no',
           decode(bitand(t.property, 2147483648), 2147483648, 'no',
              decode(ksppcv.ksppstvl, 'true', 'yes', 'no'))),
       decode(bitand(t.property, 1024), 0, null, cu.name),
       decode(bitand(t.flags, 8388608), 8388608, 'enabled', 'disabled'),
       decode(bitand(t.property, 32), 32, null,
                decode(bitand(s.spare1, 2048), 2048, 'enabled', 'disabled')),
       decode(bitand(o.flags, 128), 128, 'yes', 'no')
from sys.ts$ ts, sys.seg$ s, sys.obj$ co, sys.tab$ t, sys.obj$ o,
     sys.obj$ cx, sys.user$ cu, x$ksppcv ksppcv, x$ksppi ksppi
where o.owner# = userenv('schemaid')
  and o.obj# = t.obj#
  and bitand(t.property, 1) = 0
  and bitand(o.flags, 128) = 0
  and t.bobj# = co.obj# (+)
  and t.ts# = ts.ts#
  and t.file# = s.file# (+)
  and t.block# = s.block# (+)
  and t.ts# = s.ts# (+)
  and t.dataobj# = cx.obj# (+)
  and cx.owner# = cu.user# (+)
  and ksppi.indx = ksppcv.indx
  and ksppi.ksppinm = '_dml_monitoring_enabled'
--可以看到限制条件:where o.owner# = userenv('schemaid')
+++
--user_all_tables
create or replace view user_all_tables
    (table_name, tablespace_name, cluster_name, iot_name, status,
     pct_free, pct_used,
     ini_trans, max_trans,
     initial_extent, next_extent,
     min_extents, max_extents, pct_increase,
     freelists, freelist_groups, logging,
     backed_up, num_rows, blocks, empty_blocks,
     avg_space, chain_cnt, avg_row_len,
     avg_space_freelist_blocks, num_freelist_blocks,
     degree, instances, cache, table_lock,
     sample_size, last_analyzed, partitioned,
     iot_type, object_id_type,
     table_type_owner, table_type, temporary, secondary, nested,
     buffer_pool, row_movement,
     global_stats, user_stats, duration, skip_corrupt, monitoring,
     cluster_owner, dependencies, compression, dropped)
as
select table_name, tablespace_name, cluster_name, iot_name, status, 
     pct_free, pct_used,
     ini_trans, max_trans,
     initial_extent, next_extent,
     min_extents, max_extents, pct_increase,
     freelists, freelist_groups, logging,
     backed_up, num_rows, blocks, empty_blocks,
     avg_space, chain_cnt, avg_row_len,
     avg_space_freelist_blocks, num_freelist_blocks,
     degree, instances, cache, table_lock,
     sample_size, last_analyzed, partitioned,
     iot_type,
     null, null, null, temporary, secondary, nested,
     buffer_pool, row_movement,
     global_stats, user_stats, duration, skip_corrupt, monitoring,
     cluster_owner, dependencies, compression, dropped
from user_tables
union all
select table_name, tablespace_name, cluster_name, iot_name, status,
     pct_free, pct_used,
     ini_trans, max_trans,
     initial_extent, next_extent,
     min_extents, max_extents, pct_increase,
     freelists, freelist_groups, logging,
     backed_up, num_rows, blocks, empty_blocks,
     avg_space, chain_cnt, avg_row_len,
     avg_space_freelist_blocks, num_freelist_blocks,
     degree, instances, cache, table_lock,
     sample_size, last_analyzed, partitioned,
     iot_type, object_id_type,
     table_type_owner, table_type, temporary, secondary, nested,
     buffer_pool, row_movement,
     global_stats, user_stats, duration, skip_corrupt, monitoring,
     cluster_owner, dependencies, compression, dropped
from user_object_tables
--扩展了关于用户有权限访问的对象信息,所以user_tables是all_tables的子集。
+++
--dba_tables
create or replace view dba_tables
    (owner, table_name, tablespace_name, cluster_name, iot_name, status,
     pct_free, pct_used,
     ini_trans, max_trans,
     initial_extent, next_extent,
     min_extents, max_extents, pct_increase,
     freelists, freelist_groups, logging,
     backed_up, num_rows, blocks, empty_blocks,
     avg_space, chain_cnt, avg_row_len,
     avg_space_freelist_blocks, num_freelist_blocks,
     degree, instances, cache, table_lock,
     sample_size, last_analyzed, partitioned,
     iot_type, temporary, secondary, nested,
     buffer_pool, row_movement,
     global_stats, user_stats, duration, skip_corrupt, monitoring,
     cluster_owner, dependencies, compression, dropped)
as
select u.name, o.name, decode(bitand(t.property,2151678048), 0, ts.name, null),
       decode(bitand(t.property, 1024), 0, null, co.name),
       decode((bitand(t.property, 512)+bitand(t.flags, 536870912)),
              0, null, co.name),
       decode(bitand(t.trigflag, 1073741824), 1073741824, 'unusable', 'valid'),
       decode(bitand(t.property, 32+64), 0, mod(t.pctfree$, 100), 64, 0, null),
       decode(bitand(ts.flags, 32), 32, to_number(null),
          decode(bitand(t.property, 32+64), 0, t.pctused$, 64, 0, null)),
       decode(bitand(t.property, 32), 0, t.initrans, null),
       decode(bitand(t.property, 32), 0, t.maxtrans, null),
       s.iniexts * ts.blocksize,
       decode(bitand(ts.flags, 3), 1, to_number(null),
                                      s.extsize * ts.blocksize),
       s.minexts, s.maxexts,
       decode(bitand(ts.flags, 3), 1, to_number(null),
                                      s.extpct),
       decode(bitand(ts.flags, 32), 32, to_number(null),
         decode(bitand(o.flags, 2), 2, 1, decode(s.lists, 0, 1, s.lists))),
       decode(bitand(ts.flags, 32), 32, to_number(null),
         decode(bitand(o.flags, 2), 2, 1, decode(s.groups, 0, 1, s.groups))),
       decode(bitand(t.property, 32+64), 0,
                decode(bitand(t.flags, 32), 0, 'yes', 'no'), null),
       decode(bitand(t.flags,1), 0, 'y', 1, 'n', '?'),
       t.rowcnt,
       decode(bitand(t.property, 64), 0, t.blkcnt, null),
       decode(bitand(t.property, 64), 0, t.empcnt, null),
       t.avgspc, t.chncnt, t.avgrln, t.avgspc_flb,
       decode(bitand(t.property, 64), 0, t.flbcnt, null),
       lpad(decode(t.degree, 32767, 'default', nvl(t.degree,1)),10),
       lpad(decode(t.instances, 32767, 'default', nvl(t.instances,1)),10),
       lpad(decode(bitand(t.flags, 8), 8, 'y', 'n'),5),
       decode(bitand(t.flags, 6), 0, 'enabled', 'disabled'),
       t.samplesize, t.analyzetime,
       decode(bitand(t.property, 32), 32, 'yes', 'no'),
       decode(bitand(t.property, 64), 64, 'iot',
               decode(bitand(t.property, 512), 512, 'iot_overflow',
               decode(bitand(t.flags, 536870912), 536870912, 'iot_mapping', null))),
       decode(bitand(o.flags, 2), 0, 'n', 2, 'y', 'n'),
       decode(bitand(o.flags, 16), 0, 'n', 16, 'y', 'n'),
       decode(bitand(t.property, 8192), 8192, 'yes',
              decode(bitand(t.property, 1), 0, 'no', 'yes')),
       decode(bitand(o.flags, 2), 2, 'default',
             decode(s.cachehint, 0, 'default', 1, 'keep', 2, 'recycle', null)),
       decode(bitand(t.flags, 131072), 131072, 'enabled', 'disabled'),
       decode(bitand(t.flags, 512), 0, 'no', 'yes'),
       decode(bitand(t.flags, 256), 0, 'no', 'yes'),
       decode(bitand(o.flags, 2), 0, null,
          decode(bitand(t.property, 8388608), 8388608,
                 'sys$session', 'sys$transaction')),
       decode(bitand(t.flags, 1024), 1024, 'enabled', 'disabled'),
       decode(bitand(o.flags, 2), 2, 'no',
           decode(bitand(t.property, 2147483648), 2147483648, 'no',
              decode(ksppcv.ksppstvl, 'true', 'yes', 'no'))),
       decode(bitand(t.property, 1024), 0, null, cu.name),
       decode(bitand(t.flags, 8388608), 8388608, 'enabled', 'disabled'),
       decode(bitand(t.property, 32), 32, null,
                decode(bitand(s.spare1, 2048), 2048, 'enabled', 'disabled')),
       decode(bitand(o.flags, 128), 128, 'yes', 'no')
from sys.user$ u, sys.ts$ ts, sys.seg$ s, sys.obj$ co, sys.tab$ t, sys.obj$ o,
     sys.obj$ cx, sys.user$ cu, x$ksppcv ksppcv, x$ksppi ksppi
where o.owner# = u.user#
  and o.obj# = t.obj#
  and bitand(t.property, 1) = 0
  and bitand(o.flags, 128) = 0
  and t.bobj# = co.obj# (+)
  and t.ts# = ts.ts#
  and t.file# = s.file# (+)
  and t.block# = s.block# (+)
  and t.ts# = s.ts# (+)
  and t.dataobj# = cx.obj# (+)
  and cx.owner# = cu.user# (+)
  and ksppi.indx = ksppcv.indx
  and ksppi.ksppinm = '_dml_monitoring_enabled'
  --返回数据库中所有表的信息
+++
各数据字典表数量比较:可以从v$fixed_table中查询。
(以下为oracle10g单机数据库,定制db)
sql> select * from v$version;
banner
----------------------------------------------------------------
oracle database 10g enterprise edition release 10.2.0.1.0 - prod
pl/sql release 10.2.0.1.0 - production
core    10.2.0.1.0      production
tns for 32-bit windows: version 10.2.0.1.0 - production
nlsrtl version 10.2.0.1.0 - production
sql> select count(*) from v$fixed_table where name like 'x$%';
count(*)
----------
       613
sql> select count(*) from v$fixed_table where name like 'gv$%';
count(*)
----------
       372
sql> select count(*) from v$fixed_table where name like 'v$%';
count(*)
----------
       396
--这里:x%+gv$+v$=613+372+396=1381
sql> select count(*) from v$fixed_table;
count(*)
----------
      1383
--一般情况下,这里会=x%+gv$+v$,但现在不等,我们看一下有什么其他的表:
sql> select substr(name,1,2) from v$fixed_table group by substr(name,1,2);
subs
----
x$
v$
o$
go
gv
--可以看出,多出两个前缀分别是o$,go的两类表,应该每种只有一个:
sql> select name from v$fixed_table where name like 'o$%';
name
------------------------------
o$sql_bind_capture
sql> select name from v$fixed_table where name like 'go%';
name
------------------------------
go$sql_bind_capture
sql>
--此外,一般情况下gv$=v$,但现在gv$=396,v$=372个,我们看一下gv$都多出什么表了:
sql> select max(a.name_max) from (select length(name) as name_max from v$fixed_t
able where name like 'gv$%' or name like 'v$%') a;
max(a.name_max)
---------------
             30
select a.gv_name,b.v_name from
(select substr(name,4,30) gv_name from v$fixed_table where substr(name,1,3)='gv$') a,
(select substr(name,3,30) v_name from v$fixed_table where substr(name,1,2)='v$') b
where a.gv_name=b.v_name(+)
  and b.v_name is null
?
+++
表dictionary与v$fixed_table比较(没有什么用处~~)
---
sql> select count(*) from dictionary;
count(*)
----------
      1870
sql> select count(*) from v$fixed_table;
count(*)
----------
      1383
--两表综合比较:
dic有,fixed无--1112
dic无,fixed有--625
dictionary中gv$-368 v$-398
v$fixed_table中gv$-372 v$-396
--两表中gv$比较:
dic有,fixed无
gv$sql_bind_capture
gv$aq
gv$tempseg_usage
dic无,fixed有
gv$_lock1
gv$_resumable2
gv$rman_status_current
gv$_sequences
gv$db_transportable_platform
gv$rman_encryption_algorithms
gv$transportable_platform
--两表中v$表比较
dic有,fixed无
v$aq
v$tempseg_usage
v$sql_bind_capture
v$backup_files
v$rollname
dic无,fixed有
v$_lock1
v$rman_encryption_algorithms
v$_sequences
+++
通过v$parameter视图来追踪一下数据库的架构
1,v$parameter的结构:
sql> select view_definition from v$fixed_view_definition where view_name='v$para
meter';
view_definition
--------------------------------------------------------------------------------
select  num , name , type , value , display_value, isdefault , isses_modifiable
, issys_modifiable , isinstance_modifiable, ismodified , isadjusted , isdeprecat
ed, description, update_comment, hash  from gv$parameter where inst_id = userenv
('instance')
--可以看出v$parameter是由gv$parameter创建的
sql> select view_definition from v$fixed_view_definition where view_name='gv$par
ameter';
view_definition
--------------------------------------------------------------------------------
select x.inst_id,x.indx+1,ksppinm,ksppity,ksppstvl, ksppstdvl, ksppstdf,  decode
(bitand(ksppiflg/256,1),1,'true','false'),  decode(bitand(ksppiflg/65536,3),1,'i
mmediate',2,'deferred',                                  3,'immediate','false'),
decode(bitand(ksppiflg,4),4,'false',                                     decod
e(bitand(ksppiflg/65536,3), 0, 'false', 'true')),     decode(bitand(ksppstvf,7),
1,'modified',4,'system_mod','false'),  decode(bitand(ksppstvf,2),2,'true','false
'),  decode(bitand(ksppilrmflg/64, 1), 1, 'true', 'false'),  ksppdesc, ksppstcmn
t, ksppihash  from x$ksppi x, x$ksppcv y where (x.indx = y.indx) and  ((translat
e(ksppinm,'_','#') not like '##%') and    ((translate(ksppinm,'_','#') not like
'#%')      or (ksppstdf = 'false') or      (bitand(ksppstvf,5) > 0)))
--可以看出gv$parameter是由x$ksppi和x$ksppcv两个x$创建的
--x$ksppi和x$ksppcv基本上包含所有数据库参数,gv$parameter展现的是不包含“_”开头的参数
--“_”开头的参数为隐含参数,不建议修改,也少有人知,但很多隐含参数因为功能强大而经常使用,并不段的被探索和研究。
+++
oracle如何通过同义词定位对象(10046事件)
如果愿意的话,我们可以进一步来进行追溯,使用 10046事件,我们可以看到更多的东西。
通过 10046事件跟踪查询: 
[oracle@jumper udump]$ sqlplus eygle/eygle
sql*plus: release 9.2.0.4.0 - production on mon jun 13 18:29:22 2005
copyright (c) 1982, 2002, oracle corporation.    all rights reserved.
connected to: 
oracle9i enterprise edition release 9.2.0.4.0 - production 
with the partitioning option 
jserver release 9.2.0.4.0 - production
sql> alter session set events '10046 trace name context forever,level 12';
session altered.
sql> select count(*) from v$parameter;
count(*) 
---------- 
       262
sql> exit 
disconnected from oracle9i enterprise edition release 9.2.0.4.0 - production 
with the partitioning option 
jserver release 9.2.0.4.0 - production
--查看生成的跟踪文件
10046 事件的使用请参考: 
http://www.eygle.com/case/use.sql_trace.to.diagnose.database.htm
ok,在这里我们不要使用 tkprof格式化,因为 tkprof可能会隐去重要信息(本文仅摘取几段重要跟踪信息,你完全可以通过实验获得相同的输出):
第一段重要代码是: 
parsing in cursor #2 len=198 dep=1 uid=0 oct=3 lid=0 tim=1092440257023120 hv=2703824309 ad='567681f0' 
select obj#,type#,ctime,mtime,stime,status,dataobj#,flags,oid$, spare1, spare2 from obj$ where owner#=:1 and name=:2 and 
namespace=:3 and remoteowner is null and linkname is null and subname is null 
end of stmt 
parse #2:c=0,e=1601,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=1092440257023088 
binds #2: 
  bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0 
   bfp=b701cf24 bln=22 avl=02 flg=05 
   value=25 
  bind 1: dty=1 mxl=32(11) mal=00 scl=00 pre=00 oacflg=18 oacfl2=1 size=32 offset=0 
   bfp=b701c7b4 bln=32 avl=11 flg=05 
   value=v$parameter 
  bind 2: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0 
   bfp=b701c790 bln=24 avl=02 flg=05 
   value=1
oracle 根据三个传入参数 owner#=25,name=v$parameter,namespace=1,来判断对象类型,按照表、视图优
先规则来定位判断,对于本例这个查询是不会有结果的。
接下来 oracle 继续判断,那么此时需要验证同一词了:
parsing in cursor #4 len=46 dep=1 uid=0 oct=3 lid=0 tim=1092440257028409 hv=3378994511 ad='576eb040' 
select node,owner,name from syn$ where obj#=:1 
end of stmt 
parse #4:c=0,e=1278,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=1092440257028379                                                           
binds #4: 
  bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0 
   bfp=b701b3cc bln=22 avl=03 flg=05 
   value=841
传入绑定变量值是 841,我们看看 841 是什么: 
sql> select object_name,object_id,object_type from dba_objects where object_id=841;
object_name                     object_id object_type 
------------------------------                 ----------   ------------------ 
v$parameter                           841 synonym
841 正是这个同义词,我们再继续看这个递归 sql的作用:
sql> select node,owner,name from syn$ where obj#=841;
node     owner                          name 
-------- ------------------------------ ------------------------------ 
         sys                            v_$parameter
原来这个 sql 获得的是同义词的底层对象,这里得到了 v_$parameter。
我们继续向下看: 
parsing in cursor #8 len=37 dep=1 uid=0 oct=3 lid=0 tim=1092440257074273 hv=3468666020 ad='576db210' 
select text from view$ where rowid=:1 
end of stmt 
parse #8:c=0,e=1214,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=1092440257074242 
binds #8: 
  bind 0: dty=11 mxl=16(16) mal=00 scl=00 pre=00 oacflg=18 oacfl2=1 size=16 offset=0 
   bfp=b7018770 bln=16 avl=16 flg=05 
   value=000001cd.0013.0001 
exec #8:c=0,e=972,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=1092440257075602
注意这里,oracle 执行查询访问 view$视图,获得视图定义文本,我们看一下这里访问的是什么对象,绑定变
量传入的 rowid 值为000001cd.0013.0001,注意这是个受限 rowid,查询时需要转换一下处理:
sql> select obj# from view$ where dbms_rowid.rowid_to_restricted(rowid,0) = '000001cd.0013.0001';
obj# 
----------
       840
sql> select object_name,object_type from dba_objects where object_id=840;
object_name                    object_type 
------------------------------ ------------------ 
v_$parameter                   view
这里 oracle访问的正是 v_$parameter 视图的定义方式。执行查询可以得到:
select text from view$ where obj#=840;
text 
-------------------------------------------------------------------------------- 
select 
num,name,type,value,isdefault,isses_modifiable,issys_modifiable,ismodified,isadjuste
d,description,update_comment from v$parameter
至此就完成了查询中的回溯及定位,当然,实际过程中 oracle后台的递归操作比这还要复杂的多,感兴趣的
朋友可以按照文中的方法测试研究一下,文中不再赘述。
--sql语句中oracle对于对象名的解析顺序:
--用户表/视图-->私有同义词-->公共同义词-->返回错误ora-00942
参考一:盖国强深入oracle--dba入门、进阶与诊断案例>之
参考二:张云河老师课堂笔记。
转帖请注明:
本文源自ttt blog
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product