Skip to content

Commit 676c32c

Browse files
authored
Table Value Constructor (#12)
* Update Boolean page Signed-off-by: Gerald Venzl <gerald.venzl@oracle.com> * Update IF NOT EXISTS page Signed-off-by: Gerald Venzl <gerald.venzl@oracle.com> * Add Table Value Constructor Signed-off-by: Gerald Venzl <gerald.venzl@oracle.com> --------- Signed-off-by: Gerald Venzl <gerald.venzl@oracle.com>
1 parent 3a3005f commit 676c32c

File tree

3 files changed

+110
-6
lines changed

3 files changed

+110
-6
lines changed

features/boolean.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ The `BOOLEAN` data type enables the storage and processing of `TRUE` and `FALSE`
66

77
Boolean values can be used as table column values or inside SQL query expressions.
88

9-
To declare a table column of type `BOOLEAN`, either use the `BOOLEAN` or `BOOL` keyword:
9+
To declare a table column of type `BOOLEAN`, either use the `BOOLEAN` or `BOOL` keyword.
10+
11+
*This feature is part of the ISO SQL:1999 standard.*
1012

1113
[source,sql]
1214
[subs="verbatim"]

features/if-not-exists.adoc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,15 @@ Error starting at line : 1 in command -
6565
DROP TABLE my_test
6666
Error report -
6767
ORA-00942: table or view does not exist
68-
00942. 00000 - "table or view does not exist"
69-
*Cause:
70-
*Action:
68+
7169
SQL>
7270
SQL> -- Recreate the table in a clean state
7371
SQL> CREATE TABLE my_test
7472
2 (
7573
3 id NUMBER NOT NULL PRIMARY KEY,
7674
4 name VARCHAR2(255),
7775
5 created_tms DATE DEFAULT SYSDATE NOT NULL
78-
6* );
76+
6 );
7977
8078
Table MY_TEST created.
8179
@@ -110,7 +108,7 @@ SQL> CREATE TABLE my_test
110108
3 id NUMBER NOT NULL PRIMARY KEY,
111109
4 name VARCHAR2(255),
112110
5 created_tms DATE DEFAULT SYSDATE NOT NULL
113-
6* );
111+
6 );
114112
115113
Table MY_TEST created.
116114
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
= Table Value Constructor
2+
:database-version: 23.2.0
3+
:database-category: sql
4+
5+
The Table Value Constructor can be used to generate multiple
6+
table values (e.g. rows) in a single invocation.
7+
8+
*This feature is part of the ISO SQL:1992 standard.*
9+
10+
11+
[source,sql]
12+
[subs="verbatim"]
13+
----
14+
-- Table to demonstrate the table value constructor
15+
CREATE TABLE bookings
16+
(
17+
id NUMBER,
18+
location VARCHAR2(25),
19+
type VARCHAR2(25)
20+
);
21+
22+
-- Insert multiple rows with a single insert statement
23+
INSERT INTO bookings
24+
VALUES (12113, 'Vienna', 'Family'),
25+
(62361, 'San Francisco', 'Business'),
26+
(38172, 'Berlin', 'Leisure');
27+
28+
-- Retrieve newly inserted rows
29+
SELECT * FROM bookings;
30+
31+
-- Generate multiple rows using the table value constructor
32+
SELECT employee_id, first_name
33+
FROM (
34+
VALUES (1,'Scott'),
35+
(2,'James'),
36+
(3,'John')
37+
) employees (employee_id, first_name);
38+
----
39+
40+
.Result
41+
[source,sql]
42+
[subs="verbatim"]
43+
----
44+
SQL> -- Table to demonstrate the table value constructor
45+
SQL> CREATE TABLE bookings
46+
2 (
47+
3 id NUMBER,
48+
4 location VARCHAR2(25),
49+
5 type VARCHAR2(25)
50+
6 );
51+
52+
Table BOOKINGS created.
53+
54+
SQL> -- Insert multiple rows with a single insert statement
55+
SQL> INSERT INTO bookings
56+
2 VALUES (12113, 'Vienna', 'Family'),
57+
3 (62361, 'San Francisco', 'Business'),
58+
4 (38172, 'Berlin', 'Leisure');
59+
60+
3 rows inserted.
61+
62+
SQL> -- Retrieve newly inserted rows
63+
SQL> SELECT * FROM bookings;
64+
65+
ID LOCATION TYPE
66+
-------- ---------------- --------
67+
12113 Vienna Family
68+
62361 San Francisco Business
69+
38172 Berlin Leisure
70+
71+
SQL> -- Generate multiple rows using the table value constructor
72+
SQL> SELECT employee_id, first_name
73+
2 FROM (
74+
3 VALUES (1,'Scott'),
75+
4 (2,'James'),
76+
5 (3,'John')
77+
6 ) employees (employee_id, first_name);
78+
79+
EMPLOYEE_ID FIRST_NAME
80+
-------------- ----------
81+
1 Scott
82+
2 James
83+
3 John
84+
----
85+
86+
== Benefits
87+
88+
The table value constructor enables users to insert multiple rows within a
89+
single `INSERT` operation. This avoids unnecessary additional `INSERT`
90+
executions and roundtrips from and to the client for inserting multiple rows.
91+
92+
Using this feature can make SQL scripts more concise and readable.
93+
94+
Using this feature can save time when writing `INSERT` statements manually.
95+
96+
The table value constructor provides a convenient and concise way to
97+
generate multiple rows with values.
98+
99+
== Further information
100+
101+
* Introduced: xref:versions:{database-version}/index.adoc[]
102+
* Availability: All Offerings
103+
* link:https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6[Multi-row `INSERT`] and link:https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6[`VALUES` row generation] documentation
104+
* link:https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6[Multi-row `INSERT`] and link:https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6[`VALUES` row generation] example

0 commit comments

Comments
 (0)