A collection of database labs (TPs) covering advanced SQL/PL-SQL (Oracle) — DDL & constraints, triggers, stored procedures, views, object-relational modeling (REF/DEREF, type inheritance) — plus a NoSQL/MongoDB series (CRUD, embedded documents, aggregation pipelines) for comparison.
The focus of this repo is advanced SQL / data-analysis-oriented database work: enforcing business rules in the database layer (triggers), encapsulating logic (stored procedures/functions), analytical queries (JOINs, GROUP BY, aggregation pipelines), and modeling complex/nested data both relationally (object-relational) and in a document store (MongoDB).
.
├── plsql-oracle/
│ ├── 01-ddl-constraints/
│ │ ├── ex1_ddl_constraints.sql # PK/FK/CHECK, ALTER TABLE, DROP CASCADE
│ │ └── ex2_cinema_schema.sql # multi-table schema, ON DELETE CASCADE
│ ├── 02-triggers-procedures/
│ │ ├── ex1_trigger_salary_log.sql # BEFORE UPDATE trigger, audit log
│ │ ├── ex2_trigger_capacity_check.sql # BEFORE INSERT + business rule validation
│ │ ├── ex3_disjoint_subtype_procedures_views.sql # disjoint-subtype triggers, procedures, views
│ │ └── ex4_drone_missions_view_function_trigger.sql # view + function + range-check trigger
│ └── 03-object-relational/
│ ├── ex1_type_hierarchy_treat.sql # type inheritance (UNDER), TREAT, VALUE()
│ ├── ex2_client_commande_refs.sql # REF/DEREF object-relational model
│ └── ex2b_client_commande_refs_extended.sql # + CARDINALITY, TABLE() unnesting, ALTER TYPE
├── mongodb-nosql/
│ ├── ex1_crud_etudiant.js # basic CRUD, regex queries, sort
│ ├── ex2_nested_documents_personne.js # embedded documents/arrays vs. joined tables
│ └── ex3_aggregation_student_scores.js # $group/$match/$project/$avg pipelines
├── basic-sql/
│ └── users_orders_join.sql # simple schema + JOIN
└── LICENSE
Each script is self-contained: it creates a fresh Oracle user (CREATE USER c##...), grants privileges, connects as that user, then builds and exercises the schema. Run with SQL*Plus or SQL Developer as a DBA-privileged account.
sqlplus sys/your_password@XEPDB1 as sysdba @plsql-oracle/01-ddl-constraints/ex1_ddl_constraints.sqlHighlights:
- Triggers —
BEFORE UPDATE/BEFORE INSERTrow-level triggers,:OLD/:NEWpseudo-records,RAISE_APPLICATION_ERRORfor enforcing business rules directly in the database (capacity limits, disjoint subtypes, valid altitude ranges, uniqueness across a nested table). - Stored procedures & functions — encapsulating multi-table inserts and reusable calculations, with exception handling (
NO_DATA_FOUND). - Views — including views built on top of other views for layered aggregation.
- Object-relational features —
OBJECTtypes, type hierarchies (UNDER,NOT FINAL,TREAT),REF/DEREFpointers between object tables, nested tables ofREF,CARDINALITY(),TABLE()collection unnesting, andALTER TYPE ... ADD ATTRIBUTE ... CASCADEfor schema evolution.
Note:
02-triggers-procedures/ex3_disjoint_subtype_procedures_views.sqlhad a stray leftover token before theCREATE OR REPLACE VIEWstatement in the original script (would have caused an ORA error) — it's been cleaned up here so the script runs top to bottom.
Run with mongosh. Exercise 3 requires importing an external dataset first (see the header comment in that file for the mongoimport command).
Highlights:
- CRUD basics, regex pattern matching, sorting,
updateOnewith$set. - Modeling a relationship (person → follows → writes → tags) as embedded documents/arrays instead of separate joined tables — the NoSQL counterpart to the relational
REF/nested-table modeling done in the object-relational PL/SQL exercises. - Aggregation framework:
$group,$match,$project,$avgacross multiple fields,$addFields, multi-key (gender+career) grouping — the MongoDB equivalent ofGROUP BY+ aggregate functions.
A minimal two-table schema with a JOIN, kept as a quick reference example.
Oracle PL/SQL (SQL*Plus / SQL Developer) · MongoDB (mongosh, mongoimport)
MIT — see LICENSE.