Skip to content

Commit 7cce940

Browse files
Merge pull request #280 from oracle-devrel/ulrike23c-basic
Ulrike 23c basic sql scripts
2 parents a2a7ac2 + eb818f1 commit 7cce940

File tree

9 files changed

+213
-0
lines changed

9 files changed

+213
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# 23c-basic-examples
2+
3+
Examples to illustrate some SQL features in 23c using the 23c Developer FREE release.
4+
5+
6+
## Useful Links
7+
8+
### Documentation
9+
10+
- [Oracle Database 23c Free – Developer Release documentation](https://docs.oracle.com/en/database/oracle/oracle-database/23/index.html)
11+
- [Oracle Database New Features](https://docs.oracle.com/en/database/oracle/oracle-database/23/nfcoa/introduction.html)
12+
- [Installation Guide for Linux x86-64](https://docs.oracle.com/en/database/oracle/oracle-database/23/xeinl/index.html#Oracle%C2%AE-Database-Free)
13+
14+
### Team Publications
15+
16+
- [Oracle Database 23c Free Developer Release - 10 features you should know](https://blogs.oracle.com/coretec/post/oracle-database-23c-free-developer-sql)
17+
- [New value constructor in 23c](https://blogs.oracle.com/coretec/post/new-value-constructor-in-23c)
18+
19+
### Blogs
20+
21+
- [Introducing Oracle Database 23c Free – Developer Release](https://blogs.oracle.com/database/post/oracle-database-23c-free)
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.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
REM Script in 23c: alias-in-group.sql
2+
3+
-- GROUP BY with alias
4+
5+
SELECT to_char(hiredate,'YYYY') "Year", count(*)
6+
FROM emp
7+
GROUP BY "Year";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
REM Script in 23c: annotations.sql
2+
3+
drop table emp_annotated;
4+
5+
create table emp_annotated
6+
( empno number annotations(identity, display 'person_identity', details 'person_info'),
7+
ename varchar2(50),
8+
salary number annotations (display 'person_salary', col_hidden))
9+
annotations (display 'employee_table')
10+
/
11+
12+
-- monitor annotations
13+
col object_name format a20
14+
col object_type format a15
15+
col column_name format a15
16+
col annotation_value format a25
17+
col annotation_name format a20
18+
col domain_owner format a10
19+
col domain_name format a15
20+
21+
select object_name, object_type, column_name, annotation_name, annotation_value
22+
from user_annotations_usage;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
REM Script in 23c: boolean.sql
2+
3+
drop table test_boolean;
4+
5+
create table TEST_BOOLEAN
6+
( name VARCHAR2(100),
7+
IS_SLEEPING BOOLEAN);
8+
9+
alter table TEST_BOOLEAN modify (IS_SLEEPING boolean NOT NULL);
10+
11+
alter table TEST_BOOLEAN modify (IS_SLEEPING default FALSE);
12+
13+
insert into TEST_BOOLEAN (name) values ('Mick');
14+
insert into TEST_BOOLEAN (name, is_sleeping) values ('Keith','NO');
15+
insert into TEST_BOOLEAN (name, is_sleeping) values ('Ron',1);
16+
17+
18+
select name from test_boolean where not is_sleeping;
19+
20+
col name format a25
21+
select * from test_boolean;
22+
23+
select dump(is_sleeping) from test_boolean where name = 'Ron';​
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
REM Script in 23c: domain.sql
2+
3+
drop domain yearbirth;
4+
5+
create domain yearbirth as number(4)
6+
constraint check ((trunc(yearbirth) = yearbirth) and (yearbirth >= 1900))
7+
display (case when yearbirth < 2000 then '19-' ELSE '20-' end)||mod(yearbirth, 100)
8+
order (yearbirth -1900)
9+
annotations (title 'yearformat');
10+
11+
drop table person;
12+
create table person
13+
( id number(5),
14+
name varchar2(50),
15+
salary number,
16+
person_birth number(4) DOMAIN yearbirth
17+
)
18+
annotations (display 'person_table');
19+
20+
desc person
21+
22+
insert into person values (1,'MARTIN',3000, 1988);
23+
24+
select DOMAIN_DISPLAY(person_birth) from person;
25+
26+
-- monitor domains
27+
set linesize window
28+
col object_name format a20
29+
col object_type format a15
30+
col column_name format a15
31+
col annotation_value format a25
32+
col annotation_name format a20
33+
col domain_owner format a10
34+
col domain_name format a15
35+
36+
select * from user_annotations_usage;
37+
38+
col owner format a10
39+
col name format a15
40+
41+
select * from user_domains;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
REM Script in 23c: if-not-exists.sql
2+
3+
-- suppose table DEPT exists
4+
desc dept
5+
6+
-- try several times, no error occurs
7+
create table if not exists scott.dept (deptno number, dname varchar2(10), loc varchar2(15));
8+
9+
-- create a helper table
10+
create table dept1 as select * from dept;
11+
12+
-- drop several times, no error occurs
13+
drop table if exists dept1;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
REM Script in 23c: update-joins.sql
2+
3+
-- query column sal
4+
select e.ename, e.sal from dept d, emp e where e.deptno=d.deptno
5+
and d.dname='RESEARCH';
6+
7+
-- update with join
8+
update emp e set e.sal=e.sal*2
9+
from dept d
10+
where e.deptno=d.deptno
11+
and d.dname='RESEARCH';
12+
13+
-- query column sal
14+
select e.ename, e.sal from dept d, emp e where e.deptno=d.deptno
15+
and d.dname='RESEARCH';
16+
17+
rollback;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
REM Script in 23c: update-returning.sql
2+
3+
SELECT ename, sal FROM emp
4+
WHERE ename = 'KING';
5+
6+
-- create variables in SQL*Plus and Update with returning
7+
VARIABLE old_salary NUMBER
8+
VARIABLE new_salary NUMBER
9+
10+
UPDATE emp
11+
SET sal=sal+1000
12+
WHERE ename = 'KING'
13+
RETURNING OLD sal, NEW sal into :old_salary, :new_salary;
14+
15+
-- check the result
16+
PRINT old_salary
17+
PRINT new_salary
18+
19+
rollback;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
REM Script in 23c: value-constructor.sql
2+
3+
-- use it in the FROM clause to generate rows
4+
SELECT *
5+
FROM (VALUES (1,'SCOTT'),
6+
(2,'SMITH'),
7+
(3,'JOHN')
8+
) t1 (employee_id, first_name);
9+
10+
-- with clause
11+
with CCCP (c1,c2) as (
12+
values (1, 'SCOTT'), (2, 'SMITH'), (3, 'JOHN'))
13+
select * from cccp;
14+
15+
16+
-- create a table and cast it to get the correct length of the column
17+
drop table if exists cccp;
18+
19+
create table cccp
20+
as
21+
SELECT *
22+
FROM (VALUES (1,'SCOTT'),
23+
(2,cast('SMITH' as VARCHAR2(30))),
24+
(3,'JOHN')
25+
) t1 (employeed_id,first_name)
26+
where 1=2;
27+
28+
desc cccp
29+
30+
- use it to add 3 rows
31+
insert into cccp (EMPLOYEED_ID, FIRST_NAME)
32+
values (1,'SCOTT'),
33+
(2,'SMITH'),
34+
(3,'JOHN');
35+
commit;
36+
37+
select * from cccp;

0 commit comments

Comments
 (0)