Oracle SQL — Basics
Database & schema fundamentals
A database contains schemas, which organise database objects like tables and views. Schema creation requires user setup with appropriate privileges.
SQL command categories
DDL — Data Definition Language. Commands for structural changes: CREATE, ALTER, DROP, RENAME, TRUNCATE. The CREATE TABLE statement defines table structure, ALTER modifies existing tables, and DROP removes them permanently.
DML — Data Manipulation Language. Commands for data modification: INSERT adds rows, UPDATE modifies existing data, and DELETE removes rows. "You must give Commit after you executes any DML command."
TCL — Transaction Control Language. COMMIT saves transactions permanently, while ROLLBACK undoes unsaved changes.
DQL — Data Query Language. SELECT retrieves data with optional WHERE conditions. DESC displays table structure.
DCL — Data Control Language. GRANT and REVOKE manage permissions.
Practical patterns
The content includes SQL syntax patterns and examples for operations like:
- Creating student records with
INSERT - Updating specific rows with conditional
WHEREclauses - Removing data via
DELETE - Querying with various operators (
>,<,=,!=,<>)
Indexes and Views in Oracle
Indexes — overview
Indexes accelerate data retrieval by storing row information and corresponding ROWID data, similar to a book's table of contents. Without indexes, Oracle performs a FULL TABLE SCAN, reading all records sequentially. B-tree is Oracle's default index type.
Index types
B-Tree Index — the standard index type, suitable for key columns.
Bitmap Index — used when values repeat frequently.
Function-Based Index — required when functions appear in WHERE clauses.
Unique Index — enforces uniqueness on indexed columns.
Reverse Key Index — reverses index key values (e.g. 123 becomes 321).
Compressed Index — reduces space for multi-column indexes with data repetition.
Managing indexes
View indexes:
Drop index:
Views — definition
A virtual table created from query results without physically storing data. Views simplify complexity and enhance security by restricting column access.
CREATE VIEW syntax:
Simple view:
View with concatenation:
View with column aliases:
Multi-table view:
Drop view:
Advantages
- Restricts access to selected columns and data
- Simplifies complex queries through joins
- Enhances security
- Improves performance for complex queries
- Consumes no memory space
Disadvantages
- DML operations unsupported
- Becomes inactive if underlying table is dropped
Inline view
An inline view is a subquery in the FROM clause, also called a derived table or sub-select.
Example 1 — Top 10 products:
Example 2 — Category analysis:
Distinct, Like, Operators, Where, Null & Order by
SELECT DISTINCT
The DISTINCT statement returns only unique values from a column. When a table contains duplicate values, this clause filters for different entries.
Examples:
WHERE clause
Used to filter records based on specified conditions. Works in SELECT, UPDATE and DELETE statements.
Examples:
AND, OR, NOT operators
- AND — all conditions must be
TRUE - OR — at least one condition must be
TRUE - NOT — condition must
NOTbeTRUE
LIKE operator
Searches for patterns in columns using wildcards:
%— zero, one or multiple characters_— exactly one character
ORDER BY clause
Sorts results in ascending (default) or descending order.
Examples:
IS NULL and IS NOT NULL
NULL represents missing or inapplicable information and cannot be compared with standard operators.

