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

Complete Oracle SQL Concepts InDepth Freshers

This document serves as a comprehensive guide to essential Oracle SQL concepts for Technical Analyst interviews, covering topics such as data types, DDL, DML, TCL commands, and various SQL operations. Each concept is explained with simple examples and interview-ready queries. It also includes performance tips and common interview practice queries.

Uploaded by

Avani G
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)
10 views4 pages

Complete Oracle SQL Concepts InDepth Freshers

This document serves as a comprehensive guide to essential Oracle SQL concepts for Technical Analyst interviews, covering topics such as data types, DDL, DML, TCL commands, and various SQL operations. Each concept is explained with simple examples and interview-ready queries. It also includes performance tips and common interview practice queries.

Uploaded by

Avani G
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

Complete Oracle SQL Concepts – In-Depth Guide for

Freshers

This document covers ALL essential SQL concepts required for Oracle Technical Analyst interviews. Each concept
is explained simply with interview-ready queries.
1. Introduction to SQL
SQL (Structured Query Language) is used to manage and manipulate relational databases.
SELECT * FROM employees;

2. Data Types (Oracle)


Common data types include NUMBER, VARCHAR2, DATE.
CREATE TABLE emp (id NUMBER, name VARCHAR2(50), doj DATE);

3. DDL Commands
DDL commands define database structure.
CREATE TABLE employees (id NUMBER PRIMARY KEY, name VARCHAR2(50));

4. DML Commands
DML commands manipulate data.
INSERT INTO employees VALUES (1, 'Avani');

5. TCL Commands
Transaction Control commands manage transactions.
COMMIT;

6. Constraints
Constraints ensure data integrity.
CREATE TABLE dept (dept_id NUMBER PRIMARY KEY, dept_name VARCHAR2(30) UNIQUE);

7. SELECT Statement
Used to retrieve data.
SELECT name, salary FROM employees;

8. WHERE Clause
Filters rows based on condition.
SELECT * FROM employees WHERE salary > 40000;

9. ORDER BY
Sorts result set.
SELECT * FROM employees ORDER BY salary DESC;

10. DISTINCT
Removes duplicate rows.
SELECT DISTINCT department_id FROM employees;
11. Aggregate Functions
Perform calculation on multiple rows.
SELECT COUNT(*), AVG(salary) FROM employees;

12. GROUP BY
Groups rows.
SELECT department_id, COUNT(*) FROM employees GROUP BY department_id;

13. HAVING
Filters grouped data.
SELECT department_id, COUNT(*) FROM employees GROUP BY department_id HAVING COUNT(*) > 2;

14. JOINS
Combines data from tables.
SELECT [Link], d.dept_name FROM emp e INNER JOIN dept d ON e.dept_id = d.dept_id;

15. Types of Joins


INNER, LEFT, RIGHT, FULL joins.
SELECT * FROM emp LEFT JOIN dept ON emp.dept_id = dept.dept_id;

16. Subqueries
Query inside another query.
SELECT * FROM emp WHERE salary > (SELECT AVG(salary) FROM emp);

17. Correlated Subquery


Subquery depends on outer query.
SELECT name FROM emp e WHERE salary > (SELECT AVG(salary) FROM emp WHERE dept_id = e.dept_id);

18. Views
Virtual table.
CREATE VIEW emp_view AS SELECT id, name FROM emp;

19. Indexes
Improve performance.
CREATE INDEX idx_emp_salary ON emp(salary);

20. Sequences
Generate unique numbers.
CREATE SEQUENCE emp_seq START WITH 1 INCREMENT BY 1;

21. DELETE vs TRUNCATE


DELETE supports rollback; TRUNCATE does not.
TRUNCATE TABLE emp;

22. COMMIT & ROLLBACK


Manage transactions.
ROLLBACK;

23. NULL Handling


Handle missing values.
SELECT NVL(commission, 0) FROM emp;

24. CASE Statement


Conditional logic.
SELECT name, CASE WHEN salary > 50000 THEN 'HIGH' ELSE 'LOW' END FROM emp;

25. Normalization
Organizing data to reduce redundancy.
Split employee and department tables.

26. Performance Tips


Avoid SELECT *, use indexes.
SELECT name FROM emp WHERE emp_id = 1;

27. Interview Practice Queries


Common interview queries.
SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp);

Common questions

Powered by AI

The DISTINCT keyword in SQL queries eliminates duplicate rows from the result set, ensuring that each row is unique. While this can be useful for obtaining cleaner data, it might impact query performance since the database needs to sort and possibly hash the results to determine duplicates . Its use should be evaluated carefully, especially on large datasets, as it can lead to increased processing time and resource usage.

Joins in SQL are used to combine rows from two or more tables based on a related column between them, allowing the modeling of complex data relationships and retrieving related data in a single query. The document mentions four types of joins: INNER JOIN, which returns rows that have matching values in both tables; LEFT JOIN (or LEFT OUTER JOIN), which returns all rows from the left table and matched rows from the right table; RIGHT JOIN (or RIGHT OUTER JOIN), which returns all rows from the right table and matched rows from the left table; and FULL JOIN (or FULL OUTER JOIN), which returns all rows when there is a match in either table .

The DELETE command in SQL is used to remove specific rows from a table and supports transaction control, allowing for rollbacks. This makes DELETE suitable for situations where selective row removal is necessary or where operations might need to be undone. TRUNCATE, on the other hand, removes all rows from a table without logging individual row deletions and does not support rollbacks, usually performing faster because it deallocates entire data pages . TRUNCATE is preferable when complete data removal is needed, and transaction support is not required.

Some SQL performance tips include the use of indexes to speed up queries, limiting the result set with WHERE clauses where possible, and particularly avoiding 'SELECT *'. Avoiding 'SELECT *' is important because querying all columns (many of which may be unnecessary) can lead to increased memory usage and slower network transmission, unnecessarily burdening the database and degrading performance. Instead, specifying only the needed columns can lead to more efficient data retrieval and better use of resources .

Normalization is a database design technique used to minimize redundancy and dependency by organizing fields and tables of a database. Its primary goal is to divide large tables into smaller ones and establish relationships between them using foreign keys, thus ensuring that data modifications are performed in one place only. This reduces duplicate data storage, thereby improving data integrity and consistency . It aims to achieve various forms (normal forms) that define levels of redundancy removal and dependency.

Views in SQL serve as virtual tables that provide a selection of data, offering simplified and secure data access by abstracting the complexity of queries from the underlying tables. They help encapsulate and limit user access to specific data, enhancing security by exposing only needed data and concealing implementation details. Furthermore, they can simplify complex queries by saving reusable query logic. However, views may impact performance if not indexed adequately or if they represent overly complex queries, as their execution can still involve full table scans underlying the view . Their use should be balanced with careful performance consideration.

Dependent (or correlated) subqueries differ from regular subqueries in that they rely on values from the outer query to evaluate each row. This creates a dependency where the subquery must be executed multiple times, once for each row processed by the outer query. This can lead to challenges in execution performance, as the repeated computation can result in slower query processing compared to independent subqueries, which run only once and provide results for use across the entire outer query .

The GROUP BY clause in SQL is used to arrange identical data into groups, often employed in combination with aggregate functions to perform calculations on each group independently. This clause is crucial for generating summary statistics, such as totals or averages, for each group. For instance, to find the number of employees per department, one could use `SELECT department_id, COUNT(*) FROM employees GROUP BY department_id;` . This calculates and returns the employee count for each department separately, illustrating how GROUP BY helps in grouping rows that share a value and applying aggregate operations to these groups.

Aggregate functions in SQL perform calculations on a set of values and return a single value, which are crucial for data analysis as they allow summarizing large volumes of data. Common aggregate functions include COUNT(), SUM(), AVG(), MIN(), and MAX(). For example, using the SQL query `SELECT COUNT(*), AVG(salary) FROM employees;` one can count the total employees and calculate their average salary, providing a summary insight into workforce size and compensation . These functions enable succinct reports and stakeholder insights through aggregated data metrics.

Transaction control commands COMMIT and ROLLBACK are integral to managing transactions in SQL database operations. COMMIT applies all modifications made during the current transaction, ensuring changes are permanent and visible to others. ROLLBACK undoes all changes made in the current transaction, reverting the database to its previous state if an error occurs, thus preserving data integrity. These capabilities are crucial for ensuring that a series of operations either fully completes or has no effect, maintaining consistent database state and preventing partial updates . They help in error recovery and ensuring the atomicity of transactions.

You might also like