Oracle Interview Questions and Answers for 10 years experience
-
What are the different types of joins in Oracle SQL? Explain with examples.
- Answer: Oracle supports various JOIN types: INNER JOIN (returns rows only when there is a match in both tables), LEFT (OUTER) JOIN (returns all rows from the left table and matching rows from the right table; NULLs for non-matching rows), RIGHT (OUTER) JOIN (returns all rows from the right table and matching rows from the left table; NULLs for non-matching rows), FULL (OUTER) JOIN (returns all rows from both tables; NULLs for non-matching rows in either table), and SELF JOIN (joins a table to itself). Example:
SELECT * FROM employees e INNER JOIN departments d ON e.department_id = d.department_id;
(INNER JOIN)
- Answer: Oracle supports various JOIN types: INNER JOIN (returns rows only when there is a match in both tables), LEFT (OUTER) JOIN (returns all rows from the left table and matching rows from the right table; NULLs for non-matching rows), RIGHT (OUTER) JOIN (returns all rows from the right table and matching rows from the left table; NULLs for non-matching rows), FULL (OUTER) JOIN (returns all rows from both tables; NULLs for non-matching rows in either table), and SELF JOIN (joins a table to itself). Example:
-
Explain the concept of indexes in Oracle. What are the different types of indexes?
- Answer: Indexes are data structures that improve the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data. Types include B-tree (most common, for equality and range searches), bitmap (efficient for columns with low cardinality), function-based (on expressions or functions), unique (ensures uniqueness of indexed columns), and composite (on multiple columns).
-
Describe different ways to optimize SQL queries in Oracle.
- Answer: Optimization techniques include using appropriate indexes, avoiding functions in WHERE clauses, optimizing joins (using hints judiciously), using bind variables, rewriting queries (e.g., replacing subqueries with joins), analyzing execution plans (using EXPLAIN PLAN), and using partitioning to improve query performance on large tables.
-
What are stored procedures and how are they beneficial?
- Answer: Stored procedures are pre-compiled SQL code stored in the database. Benefits include improved performance (due to pre-compilation), enhanced security (centralized access control), modularity (reusability of code), and reduced network traffic (since only the procedure call needs to be sent).
-
Explain the concept of transactions in Oracle. What are ACID properties?
- Answer: Transactions are sequences of database operations treated as a single logical unit of work. ACID properties are Atomicity (all operations succeed or none do), Consistency (transactions maintain database integrity), Isolation (concurrent transactions appear to execute serially), and Durability (committed transactions survive system failures).
-
How do you handle deadlocks in Oracle?
- Answer: Deadlocks occur when two or more transactions are blocked indefinitely, waiting for each other to release resources. Strategies include proper schema design, minimizing lock duration, using shorter transactions, and setting appropriate timeout values. Oracle's deadlock detection mechanism automatically detects and resolves deadlocks, usually by rolling back one of the involved transactions.
-
What is PL/SQL? Give an example of a simple PL/SQL block.
- Answer: PL/SQL (Procedural Language/SQL) is Oracle's procedural extension to SQL. It allows for procedural programming constructs like loops, conditional statements, and exception handling within SQL. Example:
DECLARE v_name VARCHAR2(50) := 'John Doe'; BEGIN DBMS_OUTPUT.PUT_LINE('Hello, ' || v_name); END; /
- Answer: PL/SQL (Procedural Language/SQL) is Oracle's procedural extension to SQL. It allows for procedural programming constructs like loops, conditional statements, and exception handling within SQL. Example:
-
Explain different ways to manage data integrity in Oracle.
- Answer: Data integrity is managed through constraints (NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK), triggers (to enforce business rules), and stored procedures (to encapsulate data modification logic).
-
What are triggers in Oracle? Explain different types of triggers.
- Answer: Triggers are stored programs automatically executed in response to certain events on a particular table or view. Types include BEFORE/AFTER row/statement triggers, INSTEAD OF triggers (for views), and compound triggers (combining row and statement level actions).
Thank you for reading our blog post on 'Oracle Interview Questions and Answers for 10 years experience'.We hope you found it informative and useful.Stay tuned for more insightful content!