A comprehensive collection of 10 hands-on Oracle SQL and PL/SQL lab exercises covering DDL/DML operations, stored procedures, functions, triggers, and exception handling. Each lab includes complete solutions, sample data, and documentation. Perfect for students learning Oracle database programming
A comprehensive collection of 10 hands-on Oracle SQL and PL/SQL lab exercises covering DDL/DML operations, stored procedures, functions, triggers, and exception handling. Each lab includes complete solutions, sample data, and documentation.
Before starting these exercises, ensure you have:
- Oracle Database installed (11g or higher recommended)
- Oracle Express Edition (XE) is sufficient
- SQL Client - any of the following:
- SQL*Plus (included with Oracle)
- Oracle SQL Developer
- DBeaver
- Any Oracle-compatible IDE
- Basic Knowledge of:
- SQL fundamentals (SELECT, INSERT, UPDATE, DELETE)
- Relational database concepts
- Basic programming concepts
git clone https://github.com/CodingwithSanta/SQL-for-beginners.git
cd SQL-for-beginners/oracle-plsql-lab-exercisesUsing SQL*Plus:
sqlplus username/password@localhost:1521/XEUsing SQL Developer:
- Create a new connection with your credentials
- Test the connection before proceeding
Before running PL/SQL blocks, always execute:
SET SERVEROUTPUT ON;This enables output from DBMS_OUTPUT.PUT_LINE() statements.
For each lab, execute the SQL files in this order:
schema.sql- Creates the required tablestest-data.sql- Inserts sample data (if available)solution.sql- Contains the complete solution
Example:
cd labs/lab-01-payroll-management/Then in your SQL client:
@schema.sql
@test-data.sql
@solution.sql- Topics: Basic DML operations, Aggregate functions, Stored Procedures
- Difficulty: ⭐ Beginner
- Learn: INSERT, UPDATE, DELETE, COUNT, MAX, MIN, CREATE PROCEDURE
- Topics: Query filtering, Aggregate functions, Triggers
- Difficulty: ⭐⭐ Intermediate
- Learn: WHERE conditions, AVG, Audit triggers, AFTER INSERT/DELETE
- Topics: DDL/DML operations, Foreign keys, Date handling, Reports
- Difficulty: ⭐⭐ Intermediate
- Learn: Multi-table operations, Date filtering, Relational constraints
- Topics: ALTER operations, Exception handling
- Difficulty: ⭐⭐ Intermediate
- Learn: ALTER TABLE, RENAME COLUMN, ZERO_DIVIDE exception
- Topics: Table modifications, Complex triggers, DML event handling
- Difficulty: ⭐⭐ Intermediate
- Learn: BEFORE triggers, INSERTING/UPDATING/DELETING conditions
- Topics: Date filtering, Exception handling, Report generation
- Difficulty: ⭐⭐ Intermediate
- Learn: BETWEEN operator, Year-based filtering, OTHERS exception
- Topics: Stored procedures, Functions, Return values, Cursors
- Difficulty: ⭐⭐⭐ Advanced
- Learn: IN parameters, RETURN types, Cursor loops, Pass/Fail logic
- Topics: Complete DML suite, Integrity constraints, Data validation
- Difficulty: ⭐ Beginner
- Learn: PRIMARY KEY, NOT NULL, CHECK constraints, TRUNCATE, DROP
- Topics: NULL handling, Type conversion, Built-in exceptions
- Difficulty: ⭐⭐ Intermediate
- Learn: TO_NUMBER, NULL values, VALUE_ERROR, NO_DATA_FOUND exceptions
- Topics: Advanced triggers, Business rules, Data validation
- Difficulty: ⭐⭐⭐ Advanced
- Learn: BEFORE UPDATE triggers, RAISE_APPLICATION_ERROR, Business logic enforcement
oracle-plsql-lab-exercises/
├── README.md
├── labs/
│ ├── lab-01-payroll-management/
│ │ ├── README.md
│ │ ├── schema.sql
│ │ ├── test-data.sql
│ │ └── solution.sql
│ ├── lab-02-student-marks-triggers/
│ ├── lab-03-departments-employees/
│ ├── lab-04-employee-exceptions/
│ ├── lab-05-department-triggers/
│ ├── lab-06-student-report-exceptions/
│ ├── lab-07-procedures-functions/
│ ├── lab-08-dml-operations/
│ ├── lab-09-stock-management/
│ └── lab-10-customer-triggers/
└── docs/
├── setup-guide.md
├── sql-best-practices.md
└── troubleshooting.md
Beginners - Start with these labs:
- Lab 08 (DML Operations & Constraints)
- Lab 01 (Payroll Management System)
Intermediate - Continue with: 3. Lab 03 (Departments & Employees) 4. Lab 02 (Student Marks & Triggers) 5. Lab 04 (Employee Exceptions) 6. Lab 05 (Department Triggers) 7. Lab 06 (Student Report Exceptions) 8. Lab 09 (Stock Management)
Advanced - Complete with: 9. Lab 07 (Procedures & Functions Deep Dive) 10. Lab 10 (Customer Triggers)
Connection Issues:
- Verify Oracle service is running
- Check connection string format
- Ensure firewall allows port 1521
Output Not Displaying:
- Run
SET SERVEROUTPUT ON;before executing PL/SQL blocks
Table Already Exists Error:
- Drop the table first:
DROP TABLE table_name; - Or use
DROP TABLE table_name CASCADE CONSTRAINTS;if foreign keys exist
Data Not Inserted:
- Ensure schema.sql ran successfully before test-data.sql
- Check for constraint violations in error messages
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-lab) - Commit your changes (
git commit -m 'Add new lab exercise') - Push to the branch (
git push origin feature/new-lab) - Open a Pull Request
Santhosh_C
- GitHub: @CodingwithSanta
⭐ If you find this repository helpful, please consider giving it a star!