Oracle SQL Practical File
Oracle SQL Practical File
This practical file contains important SQL concepts and queries required for database management
using Oracle. It includes Views, Sequences, Indexes, DDL & DML commands, Operators, Clauses,
Functions, and essential SQL programs.
1. Views
A view is a virtual table based on the result of a SQL query. It does not store data physically but
provides a way to represent data from one or more tables.
Syntax:
CREATE VIEW view_name AS
SELECT column1, column2 FROM table_name WHERE condition;
Example:
CREATE VIEW EmployeeView AS
SELECT name, salary FROM Employees WHERE salary > 50000;
2. Sequences
A sequence is a database object used to generate unique numerical values, commonly used for
primary keys.
Syntax:
CREATE SEQUENCE sequence_name
START WITH start_value
INCREMENT BY increment_value;
Example:
CREATE SEQUENCE Emp_Seq START WITH 1 INCREMENT BY 1;
3. Indexes
A trigger is a stored procedure that executes automatically when a specified event occurs.
Syntax:
CREATE TRIGGER trigger_name
BEFORE|AFTER INSERT|UPDATE|DELETE ON table_name FOR EACH ROW BEGIN
-- SQL statements
END;
Example:
CREATE TRIGGER BeforeInsertEmployee
BEFORE INSERT ON Employees
FOR EACH ROW BEGIN
INSERT INTO Logs (action, timestamp) VALUES ('Insert', SYSDATE);
END;
5. Cursors