暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 23c 中使用注解

99

点击蓝字关注我吧


本文介绍了如何使用注解(Annotations)来记录 Oracle 数据库 23c 中的数据库对象。

重点是什么?

我们可以将注解视为数据库注释(comments的扩展。通过注解,我们能够向表和列等对象添加自由文本,从而使我们能够描述它们的目的和用法。注解更进一步,允许我们将名称-值对与大多数数据库对象相关联,这可以用来描述或分类它们。名称和值是自由文本,因此我们可以选择任何对我们有意义的内容。

您可能会看到被描述为“应用程序使用注解”的注解。这只是强调注解是为了帮助您的应用程序的文档。

使用注解

如果对象支持注解,则注解子句通常遵循此格式。

    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:此注解允许我们对存在的信息类型进行分类。在本例中,我们将其分类为“Fruit Info”。

      请记住,所有这些注解都只是我们编写的自由文本。除了我们与它们相关的含义之外,它们对数据库或任何工具都没有任何意义。如果我们在键名中需要空格,我们必须用双引号将它们引起来。保留字也是如此。

      我们可以通过添加或删除注解来修改注解。在这些示例中,我们在不使用可选 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 视图。

            set linesize 150
            column object_name format a12
            column object_type format a12
            column column_name format a12
            column domain_name format a12
            column domain_owner format a12
            column annotation_name format a14
            column annotation_value format a20


            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;


            OBJECT_NAME OBJECT_TYPE COLUMN_NAME DOMAIN_NAME DOMAIN_OWNER ANNOTATION_NAM ANNOTATION_VALUE
            ------------ ------------ ------------ ------------ ------------ -------------- --------------------
            FRUIT TABLE ID CLASSIFICATION Fruit Info
            FRUIT TABLE DESCRIPTION CLASSIFICATION Fruit Info
            FRUIT TABLE NAME CLASSIFICATION Fruit Info
            FRUIT TABLE CLASSIFICATION Fruit Info
            FRUIT TABLE ID SURROGATEKEY
            FRUIT TABLE DESCRIPTION UI_DISPLAY Description
            FRUIT TABLE ID UI_DISPLAY Fruit ID
            FRUIT TABLE NAME UI_DISPLAY Fruit Name
            FRUIT TABLE UI_DISPLAY Fruit Table
            FRUIT TABLE VISIBILITY Everyone
            FRUIT TABLE ID VISIBILITY Hidden


            11 rows selected.


            SQL>

            近期文章:

            喜欢就点"在看"哦~


            文章转载自山东Oracle用户组,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

            评论