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 版本不同,可能有出入。