你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle Namespace 说明

[日期:2011-07-28] 来源:Linux社区  作者:tianlesoftware [字体:大 中 小]

一. 初识Namespace

Oracle通过namespace来管理schema object的名字,关于Namespace 的定义,在官网文档上没有找到一个详细的定义,在网上搜到一些相关信息:

SchemaObject Namespaces

            A namespace defines a group of object types, within whichall names must be uniquely identified—by schema and name. Objects in differentnamespaces can share the same name.
            The Oracle database usesnamespaces to resolve schema object references. When you refer to an object ina SQL statement, Oracle considers the context of the SQL statement and locatesthe object in the appropriate namespace. After locating the object, Oracleperforms the operation specified by the statement on the object. If the named object cannot be found in the appropriate namespace,then Oracle returns an error.
            Because tables and views are in the same namespace, a table and a view inthe same schema cannot have the same name. However, tables and indexesare in different namespaces. Therefore, a table and an index in the same schemacan have the same name.
            Eachschema in the database has its own namespaces for the objects it contains. Thismeans, for example, that two tables in different schemas are in differentnamespaces and can have the same name.

--以上解释提到了几点:

            1.每个用户都有自己对应的namespace来保存自己的对象

            2.表和视图存放在同一个namespace,所以对于同一个用户的表和视图不能重名,但是表和索引是存放在不同的namespace,所以可以重名。

            开始时,我们提到Oracle 通过schema 和 name 来保证namespace中对象的唯一性。 在obj$ 字典里owner# 对应用户的ID。 通过如下SQL,我们可以查看他们之间的对应关系:

           

/* Formatted on 2011/7/21 15:41:26(QP5 v5.163.1008.3004) */

SELECT username,user_id

  FROM dba_users

WHERE user_id IN (SELECT DISTINCTowner# FROM obj$);

USERNAME                     USER_ID

------------------------- ----------

SYS                                0

SYSTEM                             5

DBSNMP                            24

SYSMAN                            58

DAVE                              61

OUTLN                             11

MDSYS                             46

ORDSYS                            43

CTXSYS                            36

EXFSYS                            34

DMSYS                             35

WMSYS                             25

XDB                               38

ORDPLUGINS                        44

SI_INFORMTN_SCHEMA                45

OLAPSYS                           47

SCOTT                             54

ORACLE_OCM                        55

TSMSYS                            21

19 rows selected.

 

一个小示例验证以上结论:

SYS@anqing2(rac2)> createtable anqing(id number);

Table created.

SYS@anqing2(rac2)>create index anqing on anqing(id);

Index created.

SYS@anqing2(rac2)>create view anqing as select * from anqing;

create view anqing asselect * from anqing

            *

ERROR at line 1:

ORA-00955: name isalready used by an existing object

 

以下类型的对象使用同一个namespace:

? Tables
? Views
? Sequences
? Private synonyms
? Stand-alone procedures
? Stand-alone stored functions
? Packages
? Materialized views
? User-defined types

 

如下类型的对象使用自己的namespace:

? Indexes
? Constraints
? Clusters
? Database triggers
? Private database links
? Dimensions

 

以下Non schema objects 使用自己的namespace:

? User roles
? Public synonyms
? Public database links
? Tablespaces
? Profiles
? Parameter files (PFILEs) and server parameter files (SPFILEs)

以上信息随Oracle 版本不同,可能有出入。

linux
相关资讯       Oracle教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款