Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 44 additions & 24 deletions features/boolean.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,83 @@ To declare a table column of type `BOOLEAN`, either use the `BOOLEAN` or `BOOL`
[source,sql]
[subs="verbatim"]
----
-- Create a new table containing two boolean columns
CREATE TABLE email_addresses
(
user_id NUMBER NOT NULL,
email VARCHAR2(255) NOT NULL,
active BOOLEAN NOT NULL,
primary BOOL NOT NULL
);

-- Insert values into the table
INSERT INTO email_addresses
(user_id, active, primary, email)
VALUES ( 1, true, true, 'jon.doe@example.com'),
( 2, true, true, 'jane.smith@gmail.com'),
( 2, false, false, 'jsmith@gmail.com'),
( 3, true, true, 'max.well@example.com'),
( 3, true, false, 'mwell@gmail.com');

COMMIT;

-- Select all email addresses that are active
SELECT email FROM email_addresses
WHERE active;

-- Select all email addresses that are active but not primary
SELECT email FROM email_addresses
WHERE active AND NOT primary;
----

.Example
.Result
[source,sql]
[subs="verbatim"]
----
SQL> -- Create a new table containing two boolean columns
SQL> CREATE TABLE email_addresses
2 (
3 user_id NUMBER NOT NULL,
4 email VARCHAR2(255) NOT NULL,
5 active BOOLEAN NOT NULL,
6 primary BOOL NOT NULL
7 );
(
user_id NUMBER NOT NULL,
email VARCHAR2(255) NOT NULL,
active BOOLEAN NOT NULL,
primary BOOL NOT NULL
);

Table EMAIL_ADDRESSES created.
Table created.

SQL> -- Insert values into the table
SQL> INSERT INTO email_addresses
2 (user_id, active, primary, email)
3 VALUES ( 1, true, true, 'jon.doe@example.com'),
4 ( 2, true, true, 'jane.smith@gmail.com'),
5 ( 2, false, false, 'jsmith@gmail.com'),
6 ( 3, true, true, 'max.well@example.com'),
7 ( 3, true, false, 'mwell@gmail.com');
(user_id, active, primary, email)
VALUES ( 1, true, true, 'jon.doe@example.com'),
( 2, true, true, 'jane.smith@gmail.com'),
( 2, false, false, 'jsmith@gmail.com'),
( 3, true, true, 'max.well@example.com'),
( 3, true, false, 'mwell@gmail.com');

5 rows inserted.
5 rows created.

SQL> COMMIT;

Commit complete.

SQL> -- Select all email addresses that are active
SQL> SELECT email FROM email_addresses
2 WHERE active;
WHERE active;

EMAIL
--------------------
--------------------------------------------------------------------------------
jon.doe@example.com
jane.smith@gmail.com
max.well@example.com
mwell@gmail.com

SQL> -- Select all email addresses that are active and primary
SQL> -- Select all email addresses that are active but not primary
SQL> SELECT email FROM email_addresses
2 WHERE active AND primary;
WHERE active AND NOT primary;

EMAIL
--------------------
jon.doe@example.com
jane.smith@gmail.com
max.well@example.com
--------------------------------------------------------------------------------
mwell@gmail.com
----

== Benefits
Expand All @@ -77,6 +97,6 @@ The `BOOLEAN` data type standardizes the storage of "Yes" and "No" values.
== Further information

* Introduced: xref:versions:{database-version}/index.adoc[]
* Availability: all editions
* Availability: All Offerings
* link:https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/Data-Types.html[Documentation]
* link:https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/Data-Types.html[Example]
2 changes: 1 addition & 1 deletion features/feature.adoctemplate
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Replace this text with the benefits the feature provides
== Further information

* Introduced: xref:versions:{database-version}/index.adoc[]
* Availability: ###Oracle Database feature edition availability, use "all editions" if it is not factored###
* Availability: ###Oracle Database feature edition availability, use "All Offerings" if it is not factored###
* link:###URL Link to the Doc###[Documentation]
* link:###URL Link to an example###[Example]
30 changes: 26 additions & 4 deletions features/identity-columns.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,30 @@ To declare a column as an identity in a table, use the `GENERATED AS IDENTITY` c
[source,sql]
[subs="verbatim"]
----
-- Create a table with the column "ID" generated as Identity column
CREATE TABLE employees
(
id NUMBER GENERATED AS IDENTITY NOT NULL PRIMARY KEY,
first_name VARCHAR2(10),
last_name VARCHAR2(10) NOT NULL,
job_title VARCHAR2(20) NOT NULL
);

-- Note the absence of the "ID" column in the INSERT statement.
-- Although it is a primary key and NOT NULL, the inserts succeed.
INSERT INTO employees (first_name, last_name, job_title)
VALUES ('Gerald', 'Venzl', 'Developer');

INSERT INTO employees (first_name, last_name, job_title)
VALUES ('Andres', 'Almiray', 'Developer');

INSERT INTO employees (first_name, last_name, job_title)
VALUES ('Chris', 'Saxon', 'Developer Evangelist');

COMMIT;

-- The SELECT statement will show the "ID" column with values filled by the generated identity values.
SELECT * FROM employees;
----

The identity column provides additional syntax modifiers to:
Expand All @@ -33,6 +50,7 @@ The identity column provides additional syntax modifiers to:
[source,sql]
[subs="verbatim"]
----
SQL> -- Create a table with the column "ID" generated as Identity column
SQL> CREATE TABLE employees
2 (
3 id NUMBER GENERATED AS IDENTITY NOT NULL PRIMARY KEY,
Expand All @@ -43,25 +61,29 @@ SQL> CREATE TABLE employees

Table EMPLOYEES created.

SQL> -- Note the absence of the "ID" column in the INSERT statement.
SQL> -- Although it is a primary key and NOT NULL, the inserts succeed.

SQL> INSERT INTO employees (first_name, last_name, job_title)
2 VALUES ('Gerald', 'Venzl', 'Developer');
VALUES ('Gerald', 'Venzl', 'Developer');

1 row inserted.

SQL> INSERT INTO employees (first_name, last_name, job_title)
2 VALUES ('Andres', 'Almiray', 'Developer');
VALUES ('Andres', 'Almiray', 'Developer');

1 row inserted.

SQL> INSERT INTO employees (first_name, last_name, job_title)
2 VALUES ('Chris', 'Saxon', 'Developer Evangelist');
VALUES ('Chris', 'Saxon', 'Developer Evangelist');

1 row inserted.

SQL> COMMIT;

Commit complete.

SQL> -- The SELECT statement will show the "ID" column with values filled by the generated identity values.
SQL> SELECT * FROM employees;

ID FIRST_NAME LAST_NAME JOB_TITLE
Expand All @@ -82,6 +104,6 @@ Identity columns ensure that the value for a new row will always be unique by us
== Further information

* Introduced: xref:versions:{database-version}/index.adoc[]
* Availability: all editions
* Availability: All Offerings
* link:https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-TABLE.html#GUID-F9CE0CC3-13AE-4744-A43C-EAC7A71AAAB6__CJAECCFH[Documentation - CREATE TABLE identity_clause]
* link:https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-TABLE.html#GUID-F9CE0CC3-13AE-4744-A43C-EAC7A71AAAB6__CJAHCAFF[Example]
2 changes: 1 addition & 1 deletion features/plsql-function-in-sql.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ but the user does either not have the necessary privileges to create a named fun
== Further information

* Introduced: xref:versions:{database-version}/index.adoc[]
* Availability: all editions
* Availability: All Offerings
* link:https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6__BABFAFID[Documentation]
* link:https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6__BABJFIDC[Example]