
If you’re preparing for a role in database development or Oracle systems, PL/SQL is a skill you’ll need to know well. PL/SQL combines SQL’s data-handling power with the features of a procedural programming language. It lets you build secure, efficient, and reusable code for tasks like data validation, batch processing, and business logic implementation.
In technical interviews, candidates are often asked about PL/SQL blocks, loops, functions, triggers, and performance tuning. To help you succeed, we’ve created a list of the most common PL/SQL interview questions and answers. These are questions that hiring managers use to test both knowledge and problem-solving skills.
Going through these questions can help you structure better answers and explain your thinking during the interview. Whether you’re applying for a junior or senior role, this guide is a great way to review key concepts and sharpen your PL/SQL skills before the big day.
- We can perform row-by-row processing with a cursor. It helps to validate the operations of each row.
- A cursor can provide the first few rows before the assembling of the entire result set. It helps to achieve better response time.
- A single connection can have multiple cursors open simultaneously. All the cursor result sets are available at the same time to an application, which can fetch data rows from them at will.
- Cursors can be faster in contrast to a while loop but at the cost of more overhead.
- A cursor in SQL is a temporary work area created in system memory. It occupies memory from a system that may be accessible for other processes. Thus, the cursor occupies more temporary storage & resources.
- Each time when the row is fetched from a cursor, it results in the network round trip. It uses more network bandwidth than a SQL statement execution such as DELETE or SELECT that only makes one round trip.
- Repeated network round trips can degrade operations speed.
- You can see the changes made during a transaction by querying the modified tables, but other users cannot see those changes. Once you commit a transaction, the changes are visible to other users’ statements that execute after the commit.
- You can undo or roll back any changes made during a transaction with a ROLLBACK statement.
- Predefined Oracle server
- Non-predefined Oracle server
- User defined
- Better Performance: The procedure calls are efficient & quick as stored procedures are compiled once & stored in the executable form. Thus, the response is quick. The executable code is cached automatically; hence it lowers the memory requirements.
- Higher Productivity: As the same piece of code is used repeatedly, it results in higher productivity.
- Ease of Use: To create a stored procedure, one can utilize any IDE or Integrated Development Environment. Thereby, it can be deployed on any tier of the network architecture.
- Scalability: Stored procedures increase the scalability by isolating app processing on a server.
- Maintainability: It is much easier to maintain a procedure on a server than maintaining copies on several client machines, it is because scripts are in one location.
- Security: Access to Oracle data can be restricted by enabling users to manipulate data only through a stored procedure that executes with their definer’s privileges.
- Aggregate SQL Functions- In SQL, the aggregate functions perform the calculation on a group of values and return a single value. Below are some commonly used Aggregate Functions: [fusion_table fusion_table_type=”1″ fusion_table_rows=”” fusion_table_columns=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=””] [/fusion_table]
Function Description SUM() It is used to return the sum of a group of values. COUNT() It returns the number of rows based on a condition or without the condition. AVG() It is used to calculate the average value of the numeric column. MIN() It returns a minimum value of the column. MAX() It returns a maximum value of the column. FIRST() It is used to return the first value of a column. LAST() It returns the last value of a column. - Scalar SQL Functions- In SQL, Scalar Function is used to return a single value from a given input value. Here is a list of some most commonly used Aggregate Functions:[fusion_table fusion_table_type=”1″ fusion_table_rows=”” fusion_table_columns=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=””] [/fusion_table]
Function Description LCASE() It is used to convert the string column values to a lowercase. UCASE() It is used to convert the string column values to uppercase. LEN() It returns the length of text values in a column. MID() It extracts the substrings in SQL from the column values with the string data type. ROUND() It rounds off the numeric value to the nearest integer. NOW() It is used to return the current system time & date. FORMAT() It is used to format how a field should be displayed.
- Character Functions: The character function accepts the character input and/or returns both number & character values as output. SQL provides various character data types, including VARCHAR, LONG RAW, CHAR, LONG, RAW, & VARCHAR2.
- Number Functions: The number function accepts the numeric input & returns numeric values. It includes MOD, TRUNC, & ROUND.
- Date Functions: The data function operates on values of the Date data type. It returns a value of DATE data type except for the MONTHS_BETWEEN Function, which returns a number. Date Functions are ADD_MONTHS, MONTHS_BETWEEN, LAST_DAY, NEXT_DAY, ROUND, & TRUNC.
- NUMBER to VARCHAR2
- CHAR or VARCHAR2 to NUMBER, DATE
- DATE to VARCHAR2
- TO_NUMBER
- TO_CHAR
- TO_DATE
- TO_NUMBER: It is used to convert a character string to the number or numeric format. TO_NUMBER function uses fx modifier. Format: TO_NUMBER ( char[, ‘ format_model’] ). The fx modifier denotes the exact matching for a character argument & the number format model.
- TO_CHAR: This function converts a number or the date data type to a character format. TO_CHAR Function uses the fm element to suppress leading zeros & remove the padded blanks. Format: TO_CHAR (date, ‘format_model’).The format model must be enclosed in the single quotation mark & is case sensitive.
- TO_DATE: It converts a character string to the date format. TO_DATE uses an fx modifier that specifies the exact matching for a character argument & date format model. Format: TO_DATE ( char[, ‘ format_model’] ).
- Enclose subqueries within the parenthesis
- Set subqueries on the right side of the comparison condition.
- Use a single-row operator with the single-row subqueries & multiple-row operators with the multiple-row subqueries.
- Single-Row Subquery: These queries only return a row from the inner select statement. Its operators are: =, >, >=, <, <=, <>
- Multiple-Row Subquery: These queries return multiple rows from the inner Select statement. The Multi-Row Subquery is also multiple-column subqueries that return multiple columns from the inner select statement. Operators include: IN, ANY, ALL.
- The ALL operator is used to select all tuples of a SELECT STATEMENT. It helps to compare a value to every value in another value set or the result from a subquery.
- The ALL operators return TRUE if all subqueries values meet the specified condition. ALL must be preceded by the comparison operators.
- ALL operator is used with SELECT, HAVING, WHERE statement.
- ANY compares the value to each value in the list or results from a subquery. It evaluates to true if the result of the inner query contains at least one row.
- ANY operator returns true if any subqueries values meet the condition.
- ANY must be preceded by the comparison operators.
- VERIFY Command: You can use the VERIFY command to confirm the changes in a SQL statement having new & old values defined with Set Verify On/OFF.
- FEEDBACK Command: It represents the no. of records returned by a query.
- Equi Join– It is a join condition containing the equality operator. The Equi Join is represented by the (=) sign. It retrieves information using the equality condition.
- Non-Equi Join– It is an inner join statement that uses an unequal operation like <>, >, <, BETWEEN, != to match rows from the different tables.
- Self Join– In this Join, a table is joined with itself.
- Cross Join- Also known as Cartesian product or Cartesian Join Cartesian product. It is a join of every row of a table to every row of another table.
- Inner Join– It returns tables’ rows that satisfy the join condition.
- Outer Join– It is similar to the Equi Join, but Oracle also returns a non-matched row from the table.
- Left Outer Join– It displays all the matching records of both tables & records in the left side table of the Join.
- Right Outer Join– It displays all the matching records of both tables & records in the right-side table of join.
- Full Outer Join-It returns all rows from both left & right-side tables of the join, extended with null if they don’t meet the join condition.
- Natural Join– It is a join that compares common columns of both the tables with each other.
- Anti Join– It returns rows from the first table where there are no matches in the second table. It is only available when performing a NOT IN subquery.
- Semi Join– It is a join where the EXISTS clause is used with the subquery. It is called a semi-join because even if the duplicate rows are returned in a subquery, only a set of matching values in an outer query is returned.
- Exclusive lock (X): It ensures that a row or page will be reserved exclusively for a transaction that imposes the exclusive lock until the transaction holds that lock. An exclusive lock is imposed when it wants to modify a row or page data. It can only be imposed if no other exclusive or shared lock is imposed on the target already. It means that only one exclusive lock can be imposed on a row or page. Once imposed, no other locks can be imposed on that locked resource.
- Shared lock (S): When imposed, the shared lock reserves a row or page accessible only for reading; thus, all the other transactions will be prevented from modifying the locked record until the lock is active. A shared lock can be imposed by various transactions simultaneously over the same row or page so that several transactions can share data reading. The reading process itself will not affect the actual row or page data. Also, a shared lock will enable you to write operations, but no DDL changes will be allowed.
- Update lock (U): It is similar to an exclusive lock but designed to be more flexible. An update lock can be imposed on a record that has a shared lock already. It imposes another shared lock on a target row. Once the transaction which holds an update lock is ready to change data, the update lock gets transformed to an exclusive lock. The update lock is asymmetrical in regards to the shared locks. It can be imposed on a record with a shared lock, but the shared lock cannot be imposed on a record that has an update lock already.
- Intent locks (I): A transaction uses the intent lock to inform another transaction about its intention to acquire the lock. The main purpose is to ensure seamless data execution by preventing another transaction from acquiring the lock in the hierarchy object.
| TRUNCATE | DELETE |
|---|---|
| It removes & discards all the rows from a table & releases the storage space used by that table. | It also removes all the rows from the table but does not release any storage space used by that table. |
| TRUNCATE Command is relatively faster. | The DELETE command is a bit slow. |
| Truncate is a DDL statement that cannot be rollback. | Delete is a DDL statement that can be rollback. |
| Database Triggers do not fire on the TRUNCATE command. | Database Triggers fire on the DELETE command. |