0% found this document useful (0 votes)
2 views4 pages

Oracle SQL Queries Guide

This document serves as a quick reference guide for Oracle SQL queries, covering database object operations, CRUD operations, data filtering, sorting, and limiting. It also includes aggregate functions, joins, grouping data, views, indexes, sequences, synonyms, and PL/SQL basics. The guide provides essential SQL commands and examples for each topic.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Oracle SQL Queries Guide

This document serves as a quick reference guide for Oracle SQL queries, covering database object operations, CRUD operations, data filtering, sorting, and limiting. It also includes aggregate functions, joins, grouping data, views, indexes, sequences, synonyms, and PL/SQL basics. The guide provides essential SQL commands and examples for each topic.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Oracle SQL Queries - Quick Reference Guide

1. Database Object Operations

• Create Table:

CREATE TABLE employees (


emp_id NUMBER PRIMARY KEY,
name VARCHAR2(100),
salary NUMBER,
department_id NUMBER
);

• Drop Table:

DROP TABLE employees;

• Alter Table:

ALTER TABLE employees ADD hire_date DATE;


ALTER TABLE employees MODIFY name VARCHAR2(200);

2. CRUD Operations

• Insert Data:

INSERT INTO employees (emp_id, name, salary, department_id)


VALUES (1, 'John Doe', 50000, 10);

• Select Data:

SELECT * FROM employees;

• Update Data:

1
UPDATE employees SET salary = 55000 WHERE emp_id = 1;

• Delete Data:

DELETE FROM employees WHERE emp_id = 1;

3. Filtering Data

• Basic WHERE Clause:

SELECT * FROM employees WHERE salary > 40000;

• Using IN, BETWEEN, LIKE:

SELECT * FROM employees WHERE department_id IN (10, 20);


SELECT * FROM employees WHERE salary BETWEEN 30000 AND 60000;
SELECT * FROM employees WHERE name LIKE 'J%';

4. Sorting & Limiting

• Order By:

SELECT * FROM employees ORDER BY salary DESC;

• Top N Rows (Oracle 12c+):

SELECT * FROM employees FETCH FIRST 5 ROWS ONLY;

5. Aggregate Functions

• Count, Sum, Avg, Min, Max:

SELECT COUNT(*), AVG(salary), MIN(salary), MAX(salary) FROM employees;

2
6. Joins

• Inner Join:

SELECT e.name, d.department_name


FROM employees e
JOIN departments d ON e.department_id = d.department_id;

• Left Outer Join:

SELECT e.name, d.department_name


FROM employees e
LEFT JOIN departments d ON e.department_id = d.department_id;

7. Grouping Data

• Group By:

SELECT department_id, COUNT(*) FROM employees GROUP BY department_id;

• Having Clause:

SELECT department_id, COUNT(*) AS total


FROM employees
GROUP BY department_id
HAVING COUNT(*) > 2;

8. Views & Indexes

• Create View:

CREATE VIEW emp_view AS SELECT name, salary FROM employees;

• Create Index:

3
CREATE INDEX idx_emp_name ON employees(name);

9. Sequences & Synonyms

• Create Sequence:

CREATE SEQUENCE emp_seq START WITH 1 INCREMENT BY 1;

• Create Synonym:

CREATE SYNONYM emp FOR employees;

10. PL/SQL Basics

• Anonymous Block:

BEGIN
DBMS_OUTPUT.PUT_LINE('Hello, Oracle!');
END;

• Stored Procedure:

CREATE OR REPLACE PROCEDURE raise_salary (emp_id IN NUMBER) AS


BEGIN
UPDATE employees SET salary = salary + 1000 WHERE emp_id = emp_id;
END;

Let me know if you want this converted to PDF or expanded with advanced Oracle concepts like triggers,
packages, or performance tuning.

You might also like