Skip to content

Commit 458603a

Browse files
Merge pull request #260 from oracle-devrel/Ulrike-23c-annotation
Ulrike 23c annotation
2 parents 26dd774 + ab8f58b commit 458603a

7 files changed

+106
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
REM Script for 23c: 1-create-table-with-annotations.sql
2+
3+
-- optional drop table emp_annotated
4+
drop table if exists emp_annotated; -- with new 23c "if exists" syntax
5+
6+
-- create a table with two column annotations for ename and salary and a table annotation
7+
create table emp_annotated
8+
( empno number,
9+
ename varchar2(50) annotations (display 'lastname'),
10+
salary number annotations (person_salary, column_hidden)
11+
)
12+
annotations (display 'employees');
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REM Script for 23c: 2-drop-column-annotation.sql
2+
3+
--- drop a column annotation with ALTER TABLE MODIFY
4+
alter table emp_annotated modify ename annotations (drop display);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
REM Script for 23c: 3-create-view-with-annotations.sql
2+
3+
-- create a view with column annotations for emp_id, emp_name, and emp_dname and an annotation for the view itself
4+
5+
create or replace view empdept_ann
6+
(emp_id annotations (identity, display 'employee Id', category 'emp info'),
7+
emp_name annotations (display 'employee name', category 'emp info'),
8+
emp_dname annotations (category 'emp info')
9+
)
10+
annotations (title 'employee view')
11+
as select e.empno, e.ename, d.dname
12+
from emp e, dept d
13+
where e.deptno=d.deptno and sal>1000;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
REM Script for 23c: 4-create-index-with-annotation.sql
2+
3+
-- create index on column loc with annotation
4+
5+
create index i_loc_dept on dept (loc) annotations (display 'Deptno Location Index');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
REM Script for 23c: 5-monitor-with-user-annotations-usage.sql
2+
REM Use USER_ANNOTATIONS_USAGE to track the list of annotations and their usage across your schema objects
3+
4+
-- If the annotation is specified for a table column, view column, or domain column, the name of the column, filter on the column name otherwise on NULL
5+
-- in our case to obtain object-level annotations for table, index, domain and view, we filter on NULL
6+
7+
set lines 200
8+
set pages 200
9+
col object_name format a25
10+
col object_type format a15
11+
col annotation_name format a15
12+
col annotation_value format a25
13+
col column_name format a20
14+
15+
select object_name, object_type, annotation_name, annotation_value
16+
from user_annotations_usage
17+
where column_name is null order by 2,1;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
REM Script for 23c: 6-monitor-with-user-annotations-usage.sql
2+
REM Use USER_ANNOTATIONS_USAGE to track the list of annotations and their usage across your schema objects
3+
4+
-- Obtain column-level annotations
5+
6+
set lines 200
7+
set pages 200
8+
col object_name format a25
9+
col object_type format a15
10+
col annotation_name format a15
11+
col annotation_value format a25
12+
col column_name format a20
13+
14+
select object_name, object_type, column_name, annotation_name, annotation_value
15+
from user_annotations_usage
16+
where column_name is not null order by 2,1;
17+
18+
-- Display annotations as a single JSON collection per column
19+
select object_type, object_name, column_Name, JSON_ARRAYAGG(JSON_OBJECT(Annotation_Name, Annotation_Value)) in_jsonformat
20+
from user_annotations_usage
21+
where column_name is not null group by object_type, object_name, column_name;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# annotations
2+
3+
Annotations (also called application usage annotations) are optional property metadata for database objects. They are centrally stored in the database, so that you can share metadata information across applications, modules, and microservices. You can use them to customize business logic, user interfaces or provide information about your database objects to your metadata repositories.
4+
Annotations are supported for the database objectts such as tables and table columns, views and view columns, materialized views and materialized view columns, indexes, and also for domains and multi-column domain columns.
5+
An annotation is either a name-value pair or name by itself. The name is mandatory, the value optional and both can be provided as freeform text fields. Annotations can be generated with CREATE or ALTER statements.
6+
7+
## Useful Links
8+
9+
### Documentation
10+
11+
- [SQL Language Reference 23c](https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/CREATE-TABLE.html#GUID-F9CE0CC3-13AE-4744-A43C-EAC7A71AAAB6)
12+
- [Database Reference](https://docs.oracle.com/en/database/oracle/oracle-database/23/refrn/ALL_ANNOTATIONS_USAGE.html#GUID-BD09C121-62C2-4881-83AE-99B168095711)
13+
- [Database Reference](https://docs.oracle.com/en/database/oracle///////oracle-database/23/refrn/USER_ANNOTATIONS.html#GUID-9B38677B-BCC6-45A4-983A-68ABE9661962)
14+
- [Database Development Guide](https://docs.oracle.com/en/database/oracle/oracle-database/23/adfns/registering-application-data-usage-database.html#GUID-2DAF069E-0938-40AF-B05B-75AFE71D666C)
15+
16+
17+
### Team Publications
18+
19+
- [Annotations - The new metadata in 23c](https://blogs.oracle.com/coretec/post/annotations-the-new-metadata-in-23c)
20+
- [Oracle Database 23c Free Developer Release - 10 features you should know](https://blogs.oracle.com/coretec/post/oracle-database-23c-free-developer-sql)
21+
22+
23+
### LiveLabs Workshops
24+
25+
- coming soon
26+
27+
28+
# License
29+
30+
Copyright (c) 2023 Oracle and/or its affiliates.
31+
32+
Licensed under the Universal Permissive License (UPL), Version 1.0.
33+
34+
See LICENSE for more details.

0 commit comments

Comments
 (0)