模式对象的命名规则和命名空间

一、 命名规则
参考ORACLE 11g Document Library 的官方文档:
Basic names
Basic names identify columns, tables, views and indexes. Basic names must follow these rules:
1、The maximum length of a basic name is 30 characters.
2、A name can consist of any combination of letters (A to Z a to z), decimal digits (0 to 9), $, #, @, or underscore (_). For identifiers, the first character must be a letter (A-Z a-z) and not a digit or special character. However, for parameter names, the first character can be a letter (A-Z a-z), a decimal digit (0 to 9), or special characters $, #, @, or underscore (_). Neither a cache group name nor a cache group table name can contain #.
4、TimesTen changes lowercase letters (a to z) to the corresponding uppercase letters (A to Z). Thus names are not case-sensitive.
5、If you enclose a name in quotation marks, you can use any combination of characters even if they are not in the set of legal characters. When the name is enclosed in quotes, the first character in the name can be any character, including one or more spaces.
If a column, table, or index is initially defined with a name enclosed in quotation marks and the name does not conform to the rule noted in the second bullet, then that name must always be enclosed in quotation marks whenever it is subsequently referenced.
6、Unicode characters are not allowed in names.
我们可以知道,一般模式对象的命名规则为:
●长度限制。名称的长度必须在1到30个字符之间(除了数据库链接名之外,它可能达到128个字符长)。
●保留字限制。保留字(如SELECT)不能用作名称。
●字符限制。名称只能是字母开头,后面字符可以是字母、数字、下划线(_)、美元符号($)、哈希符(#)、@。
●大小写说明。所有名称不管是大写还是小写,最后都会转换为大写。
      违反以上命名规则,都会导致报错。
      不过,如果名称中的字符是由双引号括住字符串的(如“abc”),则除了要求其满足长度限制的要求外,其他的限制都不用遵循。但是,使用这个名称的时候,必须同时带上双引号。
      在给模式对象命名是,一般会根据用途来给对象命名,比如说跟人力资源有关的表对象,会以HR_开头,这样比较便于管理和使用。在数据字典中,也有类似的命名情况。比如说,USER_字符开头的表示当前用户可以拥有的对象,ALL_表示数据库中任何一个用户拥有的对象,并且当前用户拥有访问这些对象的权限,DBA_表示所有的对象,V_$和GV_$分别表示动态性能视图和全局动态性能视图等等。


二、 命名空间
       如果一个表和一个视图拥有相同的名称,这样是否允许呢?通过下面的实例,可以看出其实会报错,因为表和视图拥有一个共同的命名空间。

 

Create table AB (A INTEGER);
create view AB 
as
select A from AB;
------------错误报告:
SQL 错误: ORA-00955: 名称已由现有对象使用
00955. 00000 -  "name is already used by an existing object"
*Cause:    
*Action:


 


       每一个模式对象都会被分配在一个命名空间里面。每一个命名空间会有一种或多种模式对象,在同一个命名空间内的对象名称必须唯一,不同命名空间之间的对象名称可以相同。数据库在查找对象名称的时候,会有一个优先级别,先是在用户模式下进行查找,如果没找到匹配的对象名,则会在公用命名空间中查找匹配的对象名称。这就是,如果私有同义词和公有同义词的名称相同的话,只会识别私有同义词的原因。


以下类型的对象使用同一个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
● role
● Public synonyms
●Public database links
● Tablespaces
● Profiles
● Parameter files (PFILEs) and server parameter files (SPFILEs)

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值