
Top 100 PL SQL Interview Questions for Freshers
​PL/SQL (Procedural Language for SQL) is an essential extension of SQL in Oracle databases, enabling developers to write powerful, reusable, and efficient database programs. Mastering PL/SQL allows professionals to handle complex business logic, automate tasks, and ensure data integrity through stored procedures, functions, triggers, and packages.
Candidates should be well-prepared to tackle both the PL/SQL Online Assessment and the Technical Interview Round at IDM TechPark. To help you succeed, we have compiled a comprehensive list of the Top 100 PL/SQL Interview Questions along with their answers. Mastering these concepts will give you a strong edge in securing a PL/SQL Developer role and excelling in the field of database development and administration.
1. What is PL/SQL?
PL/SQL (Procedural Language/Structured Query Language) is Oracle’s procedural extension of SQL. It allows procedural programming features like loops, conditions, and exception handling.
2. What are the key features of PL/SQL?
-
Block-structured language
-
Supports procedural constructs (loops, conditions)
-
Exception handling
-
Supports SQL operations
-
Improves performance through batch processing
3. What are the components of a PL/SQL block?
A PL/SQL block consists of:
-
DECLARE – Used for declaring variables and constants
-
BEGIN – Contains executable statements
-
EXCEPTION – Handles errors
-
END – Marks the end of the block
4. How do you declare a variable in PL/SQL?
plsql
CopyEdit
DECLARE v_name VARCHAR2(50); BEGIN v_name := 'John Doe'; END;
5. What is the difference between SQL and PL/SQL?
FeatureSQLPL/SQL
TypeDeclarativeProcedural
ExecutionExecutes one statement at a timeExecutes a block of statements
Error HandlingLimitedSupports exception handling
Use CaseQueries & transactionsBusiness logic & procedural programming
6. What is %TYPE in PL/SQL?
-
%TYPE is used to declare a variable with the same data type as an existing table column.
-
Example:
plsql
CopyEdit
DECLARE v_salary employees.salary%TYPE; BEGIN v_salary := 5000; END;
7. What is %ROWTYPE in PL/SQL?
-
%ROWTYPE is used to declare a variable with the same structure as a table row.
-
Example:
plsql
CopyEdit
DECLARE emp_record employees%ROWTYPE; BEGIN emp_record.salary := 6000; END;
8. How do you display output in PL/SQL?
-
Using DBMS_OUTPUT.PUT_LINE:
plsql
CopyEdit
BEGIN DBMS_OUTPUT.PUT_LINE('Hello, PL/SQL!'); END;
9. What are the different types of PL/SQL control structures?
-
Conditional Statements (IF-ELSE, CASE)
-
Loops (FOR, WHILE, LOOP)
10. How do you use an IF statement in PL/SQL?
plsql
CopyEdit
DECLARE v_salary NUMBER := 5000; BEGIN IF v_salary > 4000 THEN DBMS_OUTPUT.PUT_LINE('High Salary'); ELSE DBMS_OUTPUT.PUT_LINE('Low Salary'); END IF; END;
11. What are the types of loops in PL/SQL?
-
BASIC LOOP
-
WHILE LOOP
-
FOR LOOP
12. How do you use a FOR LOOP in PL/SQL?
plsql
CopyEdit
BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE('Iteration: ' || i); END LOOP; END;
13. What is an EXCEPTION in PL/SQL?
-
An EXCEPTION is used to handle errors in PL/SQL programs.
-
Example:
plsql
CopyEdit
BEGIN -- Some code EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('No data found!'); END;
14. What are the types of exceptions in PL/SQL?
-
Predefined Exceptions (e.g., NO_DATA_FOUND, TOO_MANY_ROWS)
-
User-defined Exceptions
15. What is a cursor in PL/SQL?
A cursor is used to fetch multiple rows from a SQL query.
16. What are the types of cursors in PL/SQL?
-
Implicit Cursor: Automatically created for SQL queries
-
Explicit Cursor: Defined by the user for handling multiple rows
17. How do you declare an explicit cursor?
plsql
CopyEdit
DECLARE CURSOR emp_cursor IS SELECT emp_name FROM employees; BEGIN FOR rec IN emp_cursor LOOP DBMS_OUTPUT.PUT_LINE(rec.emp_name); END LOOP; END;
18. What is the difference between COMMIT and ROLLBACK?
-
COMMIT: Saves changes permanently
-
ROLLBACK: Undoes uncommitted changes
19. What is a trigger in PL/SQL?
A trigger is an automatic event-driven procedure that executes before or after database modifications.
20. How do you create a simple trigger?
plsql
CopyEdit
CREATE OR REPLACE TRIGGER before_insert_trigger BEFORE INSERT ON employees FOR EACH ROW BEGIN :NEW.hire_date := SYSDATE; END;
21. What is the DUAL table in PL/SQL?
-
DUAL is a dummy table used for executing functions like:
pl
CopyEdit
SELECT SYSDATE FROM DUAL;
22. What is the difference between CHAR and VARCHAR2?
FeatureCHARVARCHAR2
StorageFixed-lengthVariable-length
PerformanceFaster for fixed-size valuesMore efficient for dynamic data
23. How do you define a stored procedure in PL/SQL?
plsql
CopyEdit
CREATE OR REPLACE PROCEDURE show_message IS BEGIN DBMS_OUTPUT.PUT_LINE('Hello, World!'); END;
24. How do you call a stored procedure in PL/SQL?
plsql
CopyEdit
BEGIN show_message; END;
25. What is the difference between FUNCTION and PROCEDURE?
FeatureFUNCTIONPROCEDURE
Returns a Value?YesNo
Used in SQL Queries?YesNo
Call MethodSELECT function_name FROM DUAL;BEGIN procedure_name; END;