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

Oracle SQL L3 Interview Full Queries

The document contains a comprehensive set of Oracle SQL interview queries covering various topics such as filtering data with WHERE and HAVING, using ROWNUM and ROW_NUMBER, handling duplicates, creating synonyms, and utilizing analytical functions. It also includes examples of creating tables, views, indexes, sequences, and constraints, as well as techniques for deadlock investigation and execution planning. Each query is designed to test knowledge and skills relevant to Oracle SQL at a Level 3 proficiency.

Uploaded by

ajim sayyad
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)
28 views4 pages

Oracle SQL L3 Interview Full Queries

The document contains a comprehensive set of Oracle SQL interview queries covering various topics such as filtering data with WHERE and HAVING, using ROWNUM and ROW_NUMBER, handling duplicates, creating synonyms, and utilizing analytical functions. It also includes examples of creating tables, views, indexes, sequences, and constraints, as well as techniques for deadlock investigation and execution planning. Each query is designed to test knowledge and skills relevant to Oracle SQL at a Level 3 proficiency.

Uploaded by

ajim sayyad
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 L3 Interview Queries - Full Set

1. WHERE vs HAVING
SELECT department, COUNT(*)
FROM employees
WHERE status = 'ACTIVE'
GROUP BY department
HAVING COUNT(*) > 10;

2. ROWNUM vs ROW_NUMBER
SELECT employee_id, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rank
FROM employees;

3. Second highest salary


SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

4. Duplicate records
SELECT name, COUNT(*)
FROM employees
GROUP BY name
HAVING COUNT(*) > 1;

5. Delete duplicate rows


DELETE FROM employees e
WHERE ROWID > (
SELECT MIN(ROWID)
FROM employees e2
WHERE e.name = e2.name);

6. First record by hire date


SELECT * FROM (
SELECT * FROM employees ORDER BY hire_date ASC
) WHERE ROWNUM = 1;

7. Last record by hire date


SELECT * FROM (
SELECT * FROM employees ORDER BY hire_date DESC
) WHERE ROWNUM = 1;

8. Correlated subquery
Oracle SQL L3 Interview Queries - Full Set

SELECT e1.name
FROM employees e1
WHERE salary > (
SELECT AVG(salary)
FROM employees e2
WHERE e1.department = e2.department);

9. Create synonym
CREATE SYNONYM emp FOR HR.EMPLOYEES;

10. PRAGMA AUTONOMOUS_TRANSACTION


DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
INSERT INTO log_table VALUES (...);
COMMIT;
END;

11. Analytical Functions


SELECT employee_id, department_id,
RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rank
FROM employees;

12. Partitioned table creation


CREATE TABLE sales_partitioned (
sale_id NUMBER,
sale_date DATE
)
PARTITION BY RANGE (sale_date) (
PARTITION p1 VALUES LESS THAN (TO_DATE('2024-01-01','YYYY-MM-DD')),
PARTITION p2 VALUES LESS THAN (TO_DATE('2025-01-01','YYYY-MM-DD'))
);

13. Materialized View Example


CREATE MATERIALIZED VIEW emp_mv
REFRESH FAST ON COMMIT
AS
SELECT * FROM employees;

14. View Example


Oracle SQL L3 Interview Queries - Full Set

CREATE VIEW active_employees AS


SELECT * FROM employees WHERE status = 'ACTIVE';

15. Index Example


CREATE INDEX idx_emp_name ON employees(name);

16. Use of Sequence


CREATE SEQUENCE emp_seq
START WITH 1
INCREMENT BY 1;

INSERT INTO employees(employee_id, name) VALUES(emp_seq.NEXTVAL, 'Ajim');

17. Function-based Index


CREATE INDEX idx_upper_name
ON employees(UPPER(name));

18. Foreign Key Example


ALTER TABLE orders
ADD CONSTRAINT fk_customer
FOREIGN KEY (customer_id) REFERENCES customers(customer_id);

19. Unique Constraint


ALTER TABLE employees
ADD CONSTRAINT uc_email UNIQUE(email);

20. Deadlock Investigation


SELECT blocking_session, sid, serial#
FROM v$session
WHERE blocking_session IS NOT NULL;

21. Escaping Locks


SELECT * FROM v$locked_object;

22. Explain Plan


EXPLAIN PLAN FOR
SELECT * FROM employees WHERE department_id = 10;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);


Oracle SQL L3 Interview Queries - Full Set

23. DELETE vs TRUNCATE


-- DELETE Example
DELETE FROM employees WHERE status = 'INACTIVE';

-- TRUNCATE Example
TRUNCATE TABLE temp_data;

24. Use of CHECK Constraint


ALTER TABLE employees
ADD CONSTRAINT chk_salary CHECK (salary > 0);

25. Check Execution Plan Hint


SELECT /*+ INDEX(employees emp_name_idx) */ name
FROM employees
WHERE name = 'Ajim';

You might also like