[20171115]关于namespace.txt

简介: [20171115]关于namespace.txt --//第一次听到这个概念,好像是那篇blog提到,表与索引在不同的namespace里面.也就是在相同schema下建立的表可以与索引同名.

[20171115]关于namespace.txt

--//第一次听到这个概念,好像是那篇blog提到,表与索引在不同的namespace里面.也就是在相同schema下建立的表可以与索引同名.
--//而在同一schema下的namespace的建立的对象名字是不能重名的.

--//前几天在测试dbms_shared_pool.pin时,发现SEQUENCE的namespace竟然是TABLE/PROCEDURE,感觉有必要做一些学习,了解这方面
--//的知识.

--//摘要: http://blog.csdn.net/tianlesoftware/article/details/6624122

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

Schema Object Namespaces

A namespace defines a group of object types, within which all names must be uniquely identified—by schema and name.
Objects in different namespaces can share the same name.

The Oracle database uses namespaces to resolve schema object references. When you refer to an object in a SQL statement,
Oracle considers the context of the SQL statement and locates the object in the appropriate namespace. After locating
the object, Oracle performs 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 in the 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. This means, for example, that two tables
in different schemas are in different namespaces and can have the same name.

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

1.每个用户都有自己对应的namespace来保存自己的对象
2.表和视图存放在同一个namespace,所以对于同一个用户的表和视图不能重名,但是表和索引是存放在不同的namespace,所以可以重名。

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.测试:
SYS@book> select distinct kglhdnsp,kglhdnsd,kglobtyd from x$kglob order by 1;
KGLHDNSP KGLHDNSD                        KGLOBTYD
-------- ------------------------------- ---------------------------------
       0 SQL AREA                        CURSOR
       1 TABLE/PROCEDURE                 CURSOR
       1 TABLE/PROCEDURE                 FUNCTION
       1 TABLE/PROCEDURE                 LIBRARY
       1 TABLE/PROCEDURE                 OPERATOR
       1 TABLE/PROCEDURE                 PACKAGE
       1 TABLE/PROCEDURE                 PROCEDURE
       1 TABLE/PROCEDURE                 SEQUENCE
       1 TABLE/PROCEDURE                 SYNONYM
       1 TABLE/PROCEDURE                 TABLE
       1 TABLE/PROCEDURE                 TYPE
       1 TABLE/PROCEDURE                 VIEW
       2 BODY                            CURSOR
       2 BODY                            PACKAGE BODY
       2 BODY                            TYPE BODY
       4 INDEX                           INDEX
       5 CLUSTER                         CLUSTER
      10 QUEUE                           QUEUE
      18 PUB SUB INTERNAL INFORMATION    PUB SUB INTERNAL INFORMATION
      23 RULESET                         RULESET
      24 RESOURCE MANAGER                RESOURCE MANAGER CONSUMER GROUP
      45 MULTI-VERSION OBJECT FOR TABLE  MULTI-VERSIONED OBJECT
      48 MULTI-VERSION OBJECT FOR INDEX  MULTI-VERSIONED OBJECT
      51 SCHEDULER GLOBAL ATTRIBUTE      CURSOR
      51 SCHEDULER GLOBAL ATTRIBUTE      SCHEDULER GLOBAL ATTRIBUTE
      52 SCHEDULER EARLIEST START TIME   SCHEDULER EARLIEST START TIME
      64 EDITION                         EDITION
      69 DBLINK                          CURSOR
      73 SCHEMA                          CURSOR
      73 SCHEMA                          NONE
      74 DBINSTANCE                      CURSOR
      75 SQL AREA STATS                  CURSOR STATS
      79 ACCOUNT_STATUS                  NONE
      82 SQL AREA BUILD                  CURSOR
34 rows selected.

--//个人感觉查询比较全,至少我机器正在运行的namespace.

https://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements008.htm#SQLRF51109

Within a namespace, no two objects can have the same name.

The following schema objects share one namespace:
    Tables
    Views
    Sequences
    Private synonyms
    Stand-alone procedures
    Stand-alone stored functions
    Packages
    Materialized views
    User-defined types

Each of the following schema objects has its own namespace:
    Indexes
    Constraints
    Clusters
    Database triggers
    Private database links
    Dimensions

Because tables and views are in the same namespace, a table and a view in the same schema cannot have the same name.
However, tables and indexes are in different namespaces. Therefore, a table and an index in the same schema can have the
same name.

Each schema in the database has its own namespaces for the objects it contains. This means, for example, that two tables
in different schemas are in different namespaces and can have the same name.

Each of the following nonschema objects also has its own namespace:

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

Because the objects in these namespaces are not contained in schemas, these namespaces span the entire database.

--//注意看同义词,Private synonyms与table在一个名字空间里面,而 Public synonyms是分开单独的名字空间.
--//这些概念不小心还是乱...

--//继续做一些测试:

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.测试:

SCOTT@book> CREATE SYNONYM DEPT FOR SCOTT.DEPT;
CREATE SYNONYM DEPT FOR SCOTT.DEPT
*
ERROR at line 1:
ORA-01471: cannot create a synonym with same name as object

--//而建立PUBLIC SYNONYM 就没有问题.

SCOTT@book> CREATE PUBLIC SYNONYM DEPT FOR SCOTT.DEPT;
Synonym created.

SCOTT@book> drop PUBLIC SYNONYM DEPT ;
Synonym dropped.

--//因为这两者属于不同的名字空间,这就很好理解.

目录
相关文章
|
5月前
|
C++
c++中的using namespace std;
c++中的using namespace std;
151 1
|
安全 程序员 C语言
命名空间和using namespace std的详解【C++】
命名空间和using namespace std的详解【C++】
|
11月前
|
安全 C++
【C++】从认识using namespace std开始进入C++的学习
【C++】从认识using namespace std开始进入C++的学习
64 0
|
11月前
|
算法 编译器 C语言
C++ | 你真的了解namespace吗?
C++ | 你真的了解namespace吗?
51 0
|
11月前
|
存储 Kubernetes Docker
volume 、namespace
volume 、namespace
|
前端开发 容器
什么是space-around
什么是space-around
227 0
|
Kubernetes 容器
k8s的Namespace详解
k8s的Namespace详解
169 0
|
Kubernetes 调度 数据中心
K8S 集群 NameSpace(命名空间)_NameSpace 介绍及查看 | 学习笔记
快速学习 K8S 集群 NameSpace(命名空间)_NameSpace 介绍及查看
1095 0
K8S 集群 NameSpace(命名空间)_NameSpace 介绍及查看 | 学习笔记
|
图形学
Unity 报错之 The type or namespace name 'UI' does not exist in the namespace 'UnityEngine'
关于Unity2017 升级到 Unity2019 两个问题。 The type or namespace name 'UI' does not exist in the namespace 'UnityEngine'
3143 0
Unity 报错之 The type or namespace name 'UI' does not exist in the namespace 'UnityEngine'