Skip to content

Commit

Permalink
Merge branch 'oracle-livelabs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dohdatabase authored Dec 10, 2024
2 parents a853044 + 0556350 commit d8228cc
Show file tree
Hide file tree
Showing 21 changed files with 726 additions and 111 deletions.
4 changes: 2 additions & 2 deletions db-23ai-fundamentals/database-setup/database-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The objective of this workshop is to set up the 23ai always free ADB. The follow

![locate adb](images/im2.png " ")

3. Keep the default compartment and give the datable a display name and database name. Let's name it db23ai. Next **click** transaction Processing and keep the serverless option for the database.
3. Keep the default compartment and give the database a display name and database name. Let's name it db23ai. Next **click** transaction Processing and keep the serverless option for the database.

![locate adb](images/im3.png " ")

Expand All @@ -33,7 +33,7 @@ The objective of this workshop is to set up the 23ai always free ADB. The follow

![locate adb](images/im5.png " ")

6. The databse in now being created for us. It should take around 5 min or less. Once its available it will show green and say Available.
6. The database in now being created for us. It should take around 5 min or less. Once its available it will show green and say Available.

![locate adb](images/im6.png " ")

Expand Down
20 changes: 20 additions & 0 deletions db-23ai-fundamentals/db-tools/db-tools-intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Introduction

Welcome to the "Database Tools" section of this workshop. In the following two labs, you will learn about two different tools that you can use to access the Oracle Database. We will cover both Database Actions (AKA SQL Developer Web) and the new SQL Developer VS Code Extension. These two labs will focus on what they are and how to set them up.

### **SQL Developer Web**
SQL Developer Web provides a browser-based interface to manage your Oracle Database without requiring additional installations. It supports running queries, managing database objects, and visualizing data models directly through Oracle Database Actions. It’s a straightforward tool designed for quick access and efficient database management.

### **SQL Developer on VS Code
For those who live in VS Code, the SQL Developer extension integrates Oracle Database management directly into your favorite editor. It combines the elegance of Oracle’s SQL tools with the flexibility of a lightweight coding environment. Writing and running queries, exploring database objects, or debugging PL/SQL—all without leaving the editor—makes this extension a dream for developers who want everything in one place. Plus, with almost 200k installs (since I last checked) it’s as simple to set up as it is to use.

## Learn More

* [About SQL Developer Web](https://docs.oracle.com/en/database/oracle/sql-developer-web/20.3/sdweb/about-sdw.html)
* [SQL Developer for VS Code](https://www.oracle.com/database/sqldeveloper/vscode/)

## Acknowledgements
* **Author** - Killian Lynch, Database Product Management
* **Contributors**:
* **Last Updated By/Date** - Killian Lynch, December 2024

Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ In this lab, you will explore the new vector data type and SQL Functions introdu
```
![insert into the table](images/vec6.png =50%x*)
By defining the number of dimensions, we are effetely creating a check constraint.
By defining the number of dimensions, we are effectively creating a check constraint.
5. We could also create multiple vectors in one table and define them with different formats and dimensions.
Expand Down
36 changes: 31 additions & 5 deletions db-23ai-fundamentals/new-duality-views/new-duality-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ This lab assumes you have:
Let's see an example.
First, we can insert some orders into our Jim Brown customer. Here, we can use `mergepath`.
First, we can insert some orders into our Jim Brown customer. Here, we can use `json_mergepatch`.
```
Expand Down Expand Up @@ -322,7 +322,7 @@ This lab assumes you have:
For a small example, I will show this using a macOS native terminal and execute a basic GET request.
2. Click on SQL under the Development section. The first thing we want to do is enable REST on our Duality Views. Use the Oracle Database Actions Navigator on the left side of the screen, click the drop-down arrow for the box showing the Table objects, and select Views. Refer to the picture below.
2. In the Navigator menu on the left hand side of the screen, click the drop-down arrow for the box showing the Table objects, and select Views. Refer to the picture below if needed.
![load rest](images/rest1.png " ")
Expand Down Expand Up @@ -350,7 +350,7 @@ This lab assumes you have:
ADB_LL_URL=https://ajs6esm7pafcr84-atp97134.adb.us-ashburn-1.oraclecloudapps.com
```
6. Now, create a variable in your terminal (It shouldn't have / at the end.)
6. Now, if you're on macOS or Linux create a variable in your terminal (It shouldn't have / at the end.). If you're on windows, see step 9 below.
```
<copy>
Expand All @@ -367,7 +367,7 @@ This lab assumes you have:
```
> NOTE: This base url will be unique for each user, verify that you are using the correct URL.
8. Make a GET request from your laptop terminal command line.
8. Make a GET request from your laptop terminal command line. I've done this on a macOS - if you're running on Windows, see step 9 below instead.
```
<copy>
Expand All @@ -377,13 +377,39 @@ This lab assumes you have:
```
![pull one doc](images/r1.png " ")
9. If you're using a Windows 10 and up machine, run the following
9. This lab is only intended to give you a small taste of what Duality Views have to offer. For full, in-depth free workshops, follow the link below:
```
<copy>
set ADB_LL_URL=https://ajs6esm7pafcr84-atp97134.adb.us-ashburn-1.oraclecloudapps.com
</copy>
```
10. Check it was set.
```
<copy>
echo %ADB_LL_URL%
</copy>
```
> NOTE: This base url will be unique for each user, verify that you are using the correct URL.
11. Make a GET request from your laptop terminal command line.
```
<copy>
curl -X GET %ADB_LL_URL%/ords/admin/customers_dv/
</copy>
```
![pull one doc](images/r1.png " ")
12. This lab is only intended to give you a small taste of what Duality Views have to offer. For full, in-depth free workshops, follow the link below:
[23ai JSON Duality View Workshops](https://livelabs.oracle.com/pls/apex/f?p=133:100:110578183178299::::SEARCH:duality%20views)
In summary, this lab checks out the power of JSON Relational Duality Views, allowing you to work with data in either JSON Document format or SQL Relational format. Changes made through views are reflected in the corresponding documents and tables. This flexibility enables convenient create, read, update, or delete operations across multiple documents and tables with ease.
10. We can clean up from the lab by dropping our tables. Navigate back to the SQL editor or go back to task one - step one if you need a reminder where it is.
```
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified db-23ai-fundamentals/new-property-graph/images/im2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified db-23ai-fundamentals/new-property-graph/images/im3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
204 changes: 103 additions & 101 deletions db-23ai-fundamentals/new-property-graph/new-property-graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,63 @@ This lab is just a short overview of the functionality introduced with Property
```
<copy>
drop table if exists people cascade CONSTRAINTS;
drop table if exists relationship cascade CONSTRAINTS;
CREATE TABLE people (
p_id NUMBER PRIMARY KEY,
name VARCHAR2(50)
);
INSERT INTO people (p_id, name) VALUES
(1, 'Alice'),
(2, 'Bob'),
(3, 'Carol'),
(4, 'Dave'),
(5, 'Eve');
CREATE TABLE relationship (
r_id NUMBER PRIMARY KEY,
DROP TABLE if exists customer_relationships CASCADE CONSTRAINTS;
DROP TABLE if exists customers CASCADE CONSTRAINTS;
CREATE TABLE CUSTOMERS
(
CUSTOMER_ID NUMBER ,
FIRST_NAME VARCHAR2 (100) ,
LAST_NAME VARCHAR2 (100) ,
EMAIL VARCHAR2 (255) NOT NULL ,
SIGNUP_DATE DATE DEFAULT SYSDATE ,
HAS_SUB BOOLEAN ,
DOB DATE ,
ADDRESS VARCHAR2 (200) ,
ZIP VARCHAR2 (10) ,
PHONE_NUMBER VARCHAR2 (20) ,
CREDIT_CARD VARCHAR2 (20)
) ;
INSERT INTO customers (customer_id, first_name, last_name, email, signup_date, has_sub, dob, address, zip, phone_number, credit_card)
VALUES
(1, 'John', 'Doe', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL),
(2, 'Jane', 'Smith', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL),
(3, 'Alice', 'Johnson', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL),
(4, 'Bob', 'Brown', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL),
(5, 'Charlie', 'Davis', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL),
(6, 'David', 'Wilson', '[email protected]', SYSDATE, TRUE, TO_DATE('1985-08-15', 'YYYY-MM-DD'), '123 Elm Street', '90210', '555-1234', '4111111111111111'),
(7, 'Jim', 'Brown', '[email protected]', SYSDATE, TRUE, TO_DATE('1988-01-01', 'YYYY-MM-DD'), '456 Maple Street', '12345', NULL, NULL),
(8, 'Suzy', 'Brown', '[email protected]', SYSDATE, TRUE, TO_DATE('1990-01-01', 'YYYY-MM-DD'), '123 Maple Street', '12345', '555-1234', '4111111111111111');
CREATE TABLE if not exists customer_relationships(
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) not null constraint rel_pk primary key,
source_id NUMBER,
target_id NUMBER,
relationship VARCHAR2(50),
CONSTRAINT connections_people_1_fk FOREIGN KEY (source_id) REFERENCES people (p_id),
CONSTRAINT connections_people_2_fk FOREIGN KEY (target_id) REFERENCES people (p_id)
);
INSERT INTO relationship (r_id, source_id, target_id, relationship)
VALUES
(1, 1, 2, 'friend'),
(2, 2, 3, 'colleague'),
(3, 3, 4, 'neighbor'),
(4, 4, 1, 'sibling'),
(5, 1, 3, 'mentor');
relationship VARCHAR2(100));
INSERT INTO customer_relationships (SOURCE_ID, TARGET_ID, RELATIONSHIP)
VALUES
(8, 7, 'Married'),
(7, 8, 'Married'),
(7, 4, 'Brother'),
(4, 7, 'Brother'),
(1, 2, 'Friend'),
(3, 5, 'Colleague'),
(6, 4, 'Neighbor'),
(7, 6, 'Friend'),
(6, 7, 'Friend'),
(7, 3, 'Friend'),
(3, 7, 'Friend'),
(7, 1, 'Friend'),
(1, 7, 'Friend');
</copy>
```
Expand All @@ -136,38 +162,36 @@ This lab is just a short overview of the functionality introduced with Property
The property graphs are stored as metadata inside the database meaning they don't store the actual data. Rather, the data is still stored in the underlying objects and we use the SQL/PQG syntax to interact with the property graphs.
"Why not do this in SQL?" Short answer is, you can. However, it may not be simple. Modeling graphs inside the database using SQL can be difficult and cumbersome and could require complex SQL code to accurately represent and query all aspects of a graph.
"Why not do this in SQL?" The short answer is, you can. However, it may not be simple. Modeling graphs inside the database using SQL can be difficult and cumbersome and could require complex SQL code to accurately represent and query all aspects of a graph.
This is where property graphs come in. Property graphs make the process of working with interconnected data, like identifying influencers in a social network, predicting trends and customer behavior, discovering relationships based on pattern matching and more by providing a more natural and efficient way to model and query them. Let's take a look at how to create property graphs and query them using the SQL/PGQ extension.
2. We'll first create a property graph that models the relationship between people (our tables created earlier).
2. We'll first create a property graph that models the relationship between customers.
```
<copy>
drop property graph if exists relationships_pg;
CREATE PROPERTY GRAPH relationships_pg
VERTEX TABLES (
people
KEY (p_id)
LABEL person
PROPERTIES ALL COLUMNS
)
EDGE TABLES (
relationship
KEY (r_id)
SOURCE KEY (source_id) REFERENCES people (p_id)
DESTINATION KEY (target_id) REFERENCES people (p_id)
LABEL relationship
PROPERTIES ALL COLUMNS
);
DROP PROPERTY GRAPH IF EXISTS moviestreams_pg;
create property graph moviestreams_pg
vertex tables (
customers
key(customer_id)
label customer
properties (customer_id, first_name, last_name)
)
edge tables (
customer_relationships as related
key (id)
source key(source_id) references customers(customer_id)
destination key(target_id) references customers(customer_id)
properties (id, relationship)
)
</copy>
```
A couple things to point out here:
* Vertex represent our people table
* Vertex represent our customers table
* Edges represent how they are connected (relationship table)
* Our edges table has a source key and destination key, representing the connection between the two people
Expand Down Expand Up @@ -285,78 +309,56 @@ This lab is just a short overview of the functionality introduced with Property
12. In this short lab we've looked at SQL property graphs and SQL/PGQ in Oracle Database 23ai. We've learned how to create property graphs from existing tables, query these graphs to discover relationships, and prepare data for visualization.
## Task 3: Querying Property Graphs with SQL/PGQ
1. Now we can use SQL/PQG to query and work with our property graphs. We'll use the GRAPH_TABLE operator here to display people who are connected to each other.
13. We can clean our environment.
```
<copy>
SELECT person_1, relationship, person_2
FROM graph_table (relationships_pg
MATCH
(p1 IS person) -[r IS relationship]-> (p2 IS person)
COLUMNS (p1.name AS person_1, r.relationship, p2.name AS person_2)
);
drop table if exists customer_relationships CASCADE CONSTRAINTS;
drop table if exists customers CASCADE CONSTRAINTS;
drop property graph moviestreams_pg;
</copy>
```
![use sql/pgq to query the graph](images/im4.png =50%x*)
## Task 4: Clean up
2. We can filter our results like we can in SQL.
1. Sign back in with the **admin** user.
```
<copy>
SELECT person_1, relationship, person_2
FROM graph_table (relationships_pg
MATCH
(p1 IS person WHERE p1.name = 'Alice') -[r IS relationship]-> (p2 IS person)
COLUMNS (p1.name AS person_1, r.relationship, p2.name AS person_2)
);
If you've forgotten your password, it can be found by clicking the **View login info** button in the top left of these instruction. Alternatively, you can watch the gif below to find the password.
</copy>
```
![reset the password](images/pswrd1.gif " ")
2. Now using the password we found above, sign in as the admin user.
![sign into the admin user](images/im25.png " ")
![use sql/pgq to select a person from the graph](images/im5.png " ")
3. Using the hamburger menu in the upper left hand corner of the screen, find and open the SQL Editor
![sign into the admin user](images/im22.png " ")
4. Terminate any active sessions created by the DB23AI user and drop the user.
3. We can also check the metadata about our graph
```
<copy>
SELECT person_1, relationship, person_2, id_person_1, id_relationship, id_person_2
FROM graph_table (relationships_pg
MATCH
(p1 IS person) -[r IS relationship]-> (p2 IS person)
COLUMNS (p1.name AS person_1,
p2.name AS person_2,
r.relationship AS relationship,
vertex_id(p1) AS id_person_1,
edge_id(r) AS id_relationship,
vertex_id(p2) AS id_person_2)
);
BEGIN
FOR session IN (SELECT SID, SERIAL# FROM V$SESSION WHERE USERNAME = 'DB23AI') LOOP
EXECUTE IMMEDIATE 'ALTER SYSTEM KILL SESSION ''' || session.SID || ',' || session.SERIAL# || ''' IMMEDIATE';
END LOOP;
END;
</copy>
```
![check graph metadata using sql/pgq](images/im6.png " ")
![terminate sessions](images/im21.png " ")
4. In this short lab we've looked at SQL property graphs and SQL/PGQ in Oracle Database 23ai. We've learned how to create property graphs from existing tables, query these graphs to discover relationships, and prepare data for visualization.
5. Now drop the user
This is just a small sample of what you can do with Property Graphs and SQL/PQG in Oracle Database 23ai. For more in depth labs and other graph functionality, brows through the following link
* [Graphs in 23ai](https://livelabs.oracle.com/pls/apex/f?p=133:100:105582422382278::::SEARCH:graph)
5. We can clean our environment.
```
<copy>
drop table people cascade CONSTRAINTS;
drop table relationship cascade CONSTRAINTS;
drop property graph relationships_pg;
DROP USER DB23AI CASCADE;
</copy>
```
You may now **proceed to the next lab**
## Learn More
Expand All @@ -367,4 +369,4 @@ You may now **proceed to the next lab**
## Acknowledgements
* **Author** - Killian Lynch, Database Product Management
* **Contributors** - Dom Giles, Distinguished Database Product Manager
* **Last Updated By/Date** - Killian Lynch, April 2024
* **Last Updated By/Date** - Killian Lynch, December 2024
Loading

0 comments on commit d8228cc

Please sign in to comment.