首页 > 数据库 > Oracle > 分类分级在oracle 23c中应用
Oracle 23c 引入了一个新特性 ,那就是 “ 注释 ”
我们可以将注释视为数据库注释的扩展。通过评论,我们能够向表格和列等对象添加自由文本,使我们能够描述它们的目的和用法。注释更进一步,允许我们将名称 - 值对与大多数数据库对象相关联,这些对象可用于描述或分类它们。名称和值是自由文本的,所以我们可以选择任何对我们有意义的东西。
更方便我们识别字段含义,以及字段之间的关联关系,方便程序开发人员辨认信息。
如果对象支持注释,则注释子句通常遵循这种格式。
ANNOTATIONS ( {ADD|DROP} annotation_name {'annotation_value'} {,} )
以下是表添加注释的简单示例。请注意,在添加这些注释时,我们不使用可选的 ADD 关键字。
create table fruit ( id number annotations (SurrogateKey, UI_Display 'Fruit ID', Classification 'Fruit Info'), name varchar2(50) annotations (UI_Display 'Fruit Name', Classification 'Fruit Info'), description varchar2(50) annotations (UI_Display 'Description', Classification 'Fruit Info') ) annotations (UI_Display 'Fruit Table', Classification 'Fruit Info');
SurrogateKey :此注释告诉我们该列是代理键。请注意,此注释没有任何价值,因为名称足以提供含义。
UI_Display :此注释给出了任何 UI 中的显示名称。
Classificaton :此注释允许我们对存在的信息类型进行 分类 。在本例中,我们将其分类为“水果信息”。
需要注意的是所有这些注释都只是我们编写的自由文本。除了让我们知道它们相关的含义之外,它们对数据库或任何工具都没有任何意义。如果我们在键名中需要空格,我们必须用双引号将它们引起来。
我们可以通过添加或删除注释来修改注释。在这些示例中,我们在不使用可选 ADD 关键字的情况下向表中添加新注释,使用 DROP 关键字删除该注释,然后再次添加它,这次使用可选 ADD 关键字。
alter table fruit annotations (Visibility 'Everyone'); alter table fruit annotations (drop Visibility); alter table fruit annotations (add Visibility 'Everyone');
我们可以对列级注释执行类似的操作。
alter table fruit modify (id annotations (Visibility 'Hidden')); alter table fruit modify (id annotations (drop Visibility)); alter table fruit modify (id annotations (add Visibility 'Hidden'));
有两个与注释相关的主要视图。它们是 USER_ANNOTATIONS 和 USER_ANNOTATIONS_USAGE 视图,但您可能只会使用 USER_ANNOTATIONS_USAGE 视图。USER_ANNOTATIONS没啥意义
select object_name, object_type, column_name, domain_name, domain_owner, annotation_name, annotation_value from user_annotations_usage order by annotation_name, annotation_value;
实验 :
再建立一张动物表
create table animal ( id number annotations (SurrogateKey, UI_Display 'animal ID', Classification 'animal Info'), name varchar2(50) annotations (UI_Display 'animal Name', Classification 'animal Info'), description varchar2(50) annotations (UI_Display 'Description', Classification 'Fruit Info') ) annotations (UI_Display 'animal Table', Classification 'animal Info');
SELECT * FROM user_annotations_usage ;

我想要水果分类的信息,那么用以下语句查询:
SELECT * FROM user_annotations_usage WHERE ANNOTATION_NAME='CLASSIFICATION' AND ANNOTATION_VALUE='Fruit Info'
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23825935/viewspace-3006793/ ,如需转载,请注明出处,否则将追究法律责任。