[20130221]视图dict的问题.txt

[20130221]视图dict的问题.txt

1.测试环境

SQL> select * from v$version where rownum
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

2.问题引出:

SQL> column SUBOBJECT_NAME noprint
SQL> column edition_name noprint
SQL> select * from dba_objects where object_name like 'DBA_SCHEDULER_RUNNING_JOBS';
OWNER                OBJECT_NAME          OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE         CREATED             LAST_DDL_TIME       TIMESTAMP           STATUS  T G S  NAMESPACE
-------------------- -------------------- --------- -------------- ------------------- ------------------- ------------------- ------------------- ------- - - - ----------
SYS                  DBA_SCHEDULER_RUNNIN      9188                VIEW                2009-08-15 00:20:20 2009-08-15 00:20:20 2009-08-15:00:20:20 VALID   N N N          1
                     G_JOBS
PUBLIC               DBA_SCHEDULER_RUNNIN      9189                SYNONYM             2009-08-15 00:20:20 2009-08-15 00:20:20 2009-08-15:00:20:20 VALID   N N N          1
                     G_JOBS

但是如果查询字典:

SQL> select * from dict where table_name = 'DBA_SCHEDULER_RUNNING_JOBS';
no rows selected

--可以发现并不在dict视图中.why?看看视图定义:

CREATE OR REPLACE FORCE VIEW SYS.DICTIONARY (table_name, comments)
AS
   SELECT o.NAME, c.comment$
     FROM SYS.obj$ o, SYS.com$ c
    WHERE o.obj# = c.obj#(+)
      AND c.col# IS NULL
      AND o.owner# = 0
      AND o.type# = 4
      AND (   o.NAME LIKE 'USER%'
           OR o.NAME LIKE 'ALL%'
           OR (o.NAME LIKE 'DBA%' AND EXISTS (SELECT NULL
                                                FROM SYS.v$enabledprivs
                                               WHERE priv_number = -47 /* SELECT ANY TABLE */))
          )
   UNION ALL
   SELECT o.NAME, c.comment$
     FROM SYS.obj$ o, SYS.com$ c
    WHERE o.obj# = c.obj#(+)
      AND o.owner# = 0
      AND o.NAME IN
             ('AUDIT_ACTIONS', 'COLUMN_PRIVILEGES', 'DICTIONARY', 'DICT_COLUMNS', 'DUAL', 'GLOBAL_NAME', 'INDEX_HISTOGRAM',
              'INDEX_STATS', 'RESOURCE_COST', 'ROLE_ROLE_PRIVS', 'ROLE_SYS_PRIVS', 'ROLE_TAB_PRIVS', 'SESSION_PRIVS',
              'SESSION_ROLES', 'TABLE_PRIVILEGES', 'NLS_SESSION_PARAMETERS', 'NLS_INSTANCE_PARAMETERS',
              'NLS_DATABASE_PARAMETERS', 'DATABASE_COMPATIBLE_LEVEL', 'DBMS_ALERT_INFO', 'DBMS_LOCK_ALLOCATED')
      AND c.col# IS NULL
   UNION ALL
   SELECT so.NAME, 'Synonym for ' || sy.NAME
     FROM SYS.obj$ ro, SYS.syn$ sy, SYS.obj$ so
    WHERE so.type# = 5
      AND ro.linkname IS NULL
      AND so.owner# = 1
      AND so.obj# = sy.obj#
      AND so.NAME  sy.NAME
      AND sy.owner = 'SYS'
      AND sy.NAME = ro.NAME
      AND ro.owner# = 0
      AND ro.type# = 4
      AND (   ro.owner# = USERENV ('SCHEMAID')
           OR ro.obj# IN (SELECT oa.obj#
                            FROM SYS.objauth$ oa
                           WHERE grantee# IN (SELECT kzsrorol
                                                FROM x$kzsro))
           OR EXISTS (
                 SELECT NULL
                   FROM v$enabledprivs
                  WHERE priv_number IN
                           (-45 /* LOCK ANY TABLE */,
                            -47 /* SELECT ANY TABLE */,
                            -48 /* INSERT ANY TABLE */,
                            -49 /* UPDATE ANY TABLE */,
                            -50 /* DELETE ANY TABLE */
                           ))
          );

--可以发现查询条件存在c.col# IS NULL条件.
--如果删除c.col# IS NULL查询(以sys用户查询).

SQL> column comment$ format a100
SELECT *
  FROM (SELECT o.NAME, c.comment$
          FROM SYS.obj$ o, SYS.com$ c
         WHERE o.obj# = c.obj#(+)
           --AND c.col# IS NULL
           AND o.owner# = 0
           AND o.type# = 4
           AND (   o.NAME LIKE 'USER%'
                OR o.NAME LIKE 'ALL%'
                OR (o.NAME LIKE 'DBA%' AND EXISTS (SELECT NULL
                                                     FROM SYS.v$enabledprivs
                                                    WHERE priv_number = -47 /* SELECT ANY TABLE */))
               ))
 WHERE NAME = 'DBA_SCHEDULER_RUNNING_JOBS';
NAME                         COMMENT$
---------------------------- ----------------------------------------------------------------------------------------------------
DBA_SCHEDULER_RUNNING_JOBS   Owner of the running scheduler job
DBA_SCHEDULER_RUNNING_JOBS   Name of the running scheduler job
DBA_SCHEDULER_RUNNING_JOBS   Subname of the running scheduler job (for a job running a chain step)
DBA_SCHEDULER_RUNNING_JOBS   Job style. - regular, lightweight or volatile
DBA_SCHEDULER_RUNNING_JOBS   Process number of the slave process running the scheduler job
DBA_SCHEDULER_RUNNING_JOBS   Operating system process number of the slave process running the scheduler job
DBA_SCHEDULER_RUNNING_JOBS   Database instance number of the slave process running the scheduler job
DBA_SCHEDULER_RUNNING_JOBS   Resource consumer group of the session in which the scheduler job is running
DBA_SCHEDULER_RUNNING_JOBS   Time elapsed since the scheduler job started
DBA_SCHEDULER_RUNNING_JOBS   CPU time used by the running scheduler job, if available
DBA_SCHEDULER_RUNNING_JOBS   Owner of destination object (if used) else NULL
DBA_SCHEDULER_RUNNING_JOBS   Destination that this job is running on
DBA_SCHEDULER_RUNNING_JOBS   Owner of login credential used for this running job, if any
DBA_SCHEDULER_RUNNING_JOBS   Name of login credential used for this running job, if any
14 rows selected.

--很奇怪sys.com$中不存在该对象col#为空的的记录:

SQL> SELECT * FROM SYS.com$ WHERE obj# IN (SELECT obj# FROM SYS.obj$ WHERE NAME = 'DBA_SCHEDULER_RUNNING_JOBS');
      OBJ#       COL# COMMENT$
---------- ---------- ----------------------------------------------------------------------------------------------------
      9188          1 Owner of the running scheduler job
      9188          2 Name of the running scheduler job
      9188          3 Subname of the running scheduler job (for a job running a chain step)
      9188          4 Job style. - regular, lightweight or volatile
      9188          7 Process number of the slave process running the scheduler job
      9188          8 Operating system process number of the slave process running the scheduler job
      9188          9 Database instance number of the slave process running the scheduler job
      9188         10 Resource consumer group of the session in which the scheduler job is running
      9188         11 Time elapsed since the scheduler job started
      9188         12 CPU time used by the running scheduler job, if available
      9188         13 Owner of destination object (if used) else NULL
      9188         14 Destination that this job is running on
      9188         15 Owner of login credential used for this running job, if any
      9188         16 Name of login credential used for this running job, if any
14 rows selected.

3.自己建立一个视图看看.

SQL> create view v_dept as select * from dept ;
View created.
SQL> SELECT * FROM SYS.com$ WHERE obj# IN (SELECT obj# FROM SYS.obj$ WHERE NAME = 'V_DEPT');
no rows selected
SQL> COMMENT ON TABLE SCOTT.V_DEPT IS 'this is a test!';
Comment created.
SQL> SELECT * FROM SYS.com$ WHERE obj# IN (SELECT obj# FROM SYS.obj$ WHERE NAME = 'V_DEPT');
      OBJ#       COL# COMMENT$
---------- ---------- --------------------
    269361            this is a test!
--可以发现表或者视图的注解对应的col#为NULL.
SQL> COMMENT ON TABLE SCOTT.V_DEPT IS '';
Comment created.
SQL> SELECT * FROM SYS.com$ WHERE obj# IN (SELECT obj# FROM SYS.obj$ WHERE NAME = 'V_DEPT');
      OBJ#       COL# COMMENT$
---------- ---------- ----------------------
    269361
SQL> COMMENT ON TABLE SCOTT.V_DEPT IS null;
COMMENT ON TABLE SCOTT.V_DEPT IS null
                                 *
ERROR at line 1:
ORA-01780: string literal required
--另外可以发现一旦建立注解,无法删除,仅仅为空.而且即使是视图,注解的对象是view,命令也是COMMENT ON TABLE,有点奇怪!
--给SYS.DBA_SCHEDULER_RUNNING_JOBS
SQL> COMMENT ON TABLE SYS.DBA_SCHEDULER_RUNNING_JOBS IS 'SCHEDULER RUNNING JOBS';
Comment created.
SQL> select * from dict where TABLE_NAME='DBA_SCHEDULER_RUNNING_JOBS';
TABLE_NAME                     COMMENTS
------------------------------ ------------------------
DBA_SCHEDULER_RUNNING_JOBS     SCHEDULER RUNNING JOBS

-- 这样查询就存在了.

4.这样就有许多视图不存在dict中.

SELECT *
  FROM dba_objects
 WHERE object_id IN (
 SELECT DISTINCT obj# FROM SYS.com$ WHERE col# IS NOT NULL
 MINUS
 SELECT obj# FROM SYS.com$ WHERE col# IS NULL);

--这样这些对象在dict中都应该无法查询.

时间: 2024-10-31 15:19:08

[20130221]视图dict的问题.txt的相关文章

[20131001]ctas与视图user_tables,user_objects.txt

[20131001]ctas与视图user_tables,user_objects.txt 链接:http://www.itpub.net/thread-1819520-1-1.htmlSQL> show user ;USER is "SCOTT"SQL> purge recyclebin; Recyclebin purged. SQL> select table_name from user_tables where table_name = 'NO_EXISTS'

[20131210]11G的内部视图X$DBGALERTEXT补充.txt

[20131210]11G的内部视图X$DBGALERTEXT补充.txt http://blog.itpub.net/267265/viewspace-775126/ 曾经写过一篇blog,以前我们看alert*.log文件,一般直接进入目录,直接查看.当然也可以通过外部表来访问alert*.log. 而11G开始引入了新的ADR自动诊断仓库特性,默认的Alert.log转换为LOG.XML的形式,默认存放在$ADR_HOME/alert&trace目录下,并且 为日志条目增加了如Level之

[20120507]视图all_tab_columns的定义问题.txt

[20120507]视图all_tab_columns的定义问题.txt 生产系统我发现一个问题,开发人员在使用pb9.0维护时要调用如下类似的语句: SELECT synonym_name  FROM SYS.all_synonyms s, SYS.all_tab_columns t WHERE s.owner IN ('SCOTT', 'PUBLIC')   AND s.synonym_name = 'DEPT'   AND s.table_owner = t.owner   AND s.t

[20130125]利用v$active_session_history视图解决数据库问题.txt

[20130125]利用v$active_session_history视图解决数据库问题.txt 在数据库出现性能问题的时候使用awr,ash,addm都是不错的选择,实际上直接查询v$active_session_history也能很快定位解决问题.实际上如果查看v$active_session_history视图,结合一些视图可以获取许多信息.举几个例子来说明: 1.确定那个对象有高的等待:SELECT   a.current_obj#, o.object_name, o.object_t

[20131211]mysql pager定义=vim.txt

[20131211]mysql pager定义=vim.txt 今天看厂家调试安全设备,发现后台数据库使用mysql.我发现他select * from 自己一点也不熟悉mysql,不过我在公司使用cacti监控各种设备以及服务器,自己也测试看看. # mysql -u rootWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 14542484 to server versio

ios从服务器拿到历史记录导入demo的数据库显示问题

问题描述 读取数据库历史记录时:如何让我发的消息显示在右边 解决方案 给message.from   和message.to  赋值解决方案二:你拉取的你们自己的服务器上的消息,那么你接收和发送是怎么写的啊解决方案三:拉取的你们自己的服务器上的消息,插到数据库,插入是用这样的方法,然后就用你们demo的方法读取数据库 //判断消息的类型    if([dict[@"msg_type"]isEqualToString:@"txt"])    {        //插入

vim下快速输入sql语句

vim下快速输入sql语句 最近没事干,看了<Hacking Vim>,自己总觉一下,写了一个快速输入sql的脚本abbr,通过别名以及字典建立快速输入sql:(注意斜线被替换为全角的/). abbreviate sqls select * from where = : ;abbreviate sqlu update set = : where = : ;abbreviate sqld delete from where = : ; nnoremap /c/+>/einoremap /c

Apache Open Office Database数据源操作入门

办公室中很多日常业务需要使用办公套件,Open Office 是开源免费的办公套件,且被广泛使用.Open Office Database 类似于 http://www.aliyun.com/zixun/aggregation/11208.html">Microsoft Access,负责对基本的数据源进行数据存储和数据管理,并与 Open Office 的应用组件 Text Document, Spreadsheet 集成.Database 能够管理的数据源除了常用的数据库外,还包括能够

asp.net实现从Txt文件读取数据到数据视图的方法_实用技巧

本文实例讲述了asp.net实现从Txt文件读取数据到数据视图的方法.分享给大家供大家参考,具体如下: #region 从Txt文件读取数据到数据视图 /// 从Txt文件读取数据到数据视图 /// </summary> /// <param name="strExcelPath">文件路径</param> /// <returns>返回一个数据视图</returns> public static DataView GetDa