PL stands for Procedural Language which is an extension to SQL where the developer writes the complex database interaction by using the procedures, control structures like branching and iteration, modules and functions. It supports both dynamic and static SQL.
In this article, you can go through the set of Oracle PL/SQL interview questions most frequently asked in the interview panel. This will help you crack the interview as the topmost industry experts curate these at HKR training.
Let us have a quick review of the Oracle PL/SQL interview questions.
Ans: The benefits of PL/SQL Packages are.
Ans: Tracing the code is a technique that measures performance during the runtime. The different methods for tracing the code includes the following:
Ans: Yes. The IF statement is used as a DECODE in versions 9 and above.
DECODE (number, 0, 'Sunday',
'No match') result FROM weekdays;
It is the attribute that declares a variable of the same data type as of a table column.
It is the attribute that declares a variable of type RECORD which has the same structure as that of a table row. The row is a RECORD that contains fields having the same data types and names as that of columns of a table or view.
Ans: The trigger is a stored procedure which invokes automatically when an event occurs. The event could be any of these DML commands like insert, update, delete, etc.
create trigger [trigger_name]
[before | after]
[for each row]
Ans: There are two different types of cursors available in PL/SQL.
Implicit cursor: PL/SQL applies these implicit cursors for the DML commands such as INSERT, UPDATE, DELETE and SELECT statements which return a single row.
Explicit cursor: It is created by the programmer for queries that return more than a single row.
FETCH INTO ;
Ans: The outcome of the statement is saved in 4 cursor attributes. They are.
Ans: Comments are the text which is used while implementing the code to enhance the readability such that a reader is able to understand the code. These comment codes are not executed. There are two types of comments in PL/SQL.
Single line comment: This comment starts with double “–”.
num NUMBER(2); — it is a local variable.
Multi-line comment: This comment starts with “/*” and ends with “*/”.
num := &p_num; /* This is a host variable used in program body */
Ans: The three modes of parameters are.
The actual parameters are the variables or an expression which is referred to as parameters that appear in the procedure call statement.
In this above example, “emp_num” and “amount” are the two actual parameters.
The formal parameters are the variables which are declared in the procedure header and are referenced in the procedure body.
PROCEDURE raise_sal( emp_id INTEGER) IS
SELECT sal INTO cur_sal FROM emp WHERE empno = emp_id;
In the above example, “emp_id” acts as a formal parameter.
Ans: In PL/SQL, the exception is raised when an error occurs. In other terms, to handle unpredicted events such as when the PL/SQL scripts are terminated unexpectedly than an error-handling code is included in the program. In PL/SQL, all exception handling code is placed in an EXCEPTION section. There are three types of Exception Handling in PL/SQL.
Ans: A View is a logical representation of data subsets from one or more tables. It is a logical table that is based on a SQL table or another view. A view doesn’t contain the data of its own but is like a window through which data from tables can be viewed or changed. The tables on which a view is based are called Base Tables. The View is stored as a SELECT statement in the data dictionary. View definitions can be retrieved from the data dictionary table: USER_VIEWS.
The views are used for the following purposes.
CREATE PROCEDURE get_customer_details @age nvarchar(30), @city nvarchar(10)
SELECT * FROM customers WHERE age = @age AND city = @city;
avg NUMBER :=0 ;
sum NUMBER :=0 ;
count NUMBER :=0 ;
n := &enter_a_number;
count := count+1;
sum := sum+n;
n := &enter_a_number;
avg := sum/count;
DBMS_OUTPUT.PUT_LINE(‘the average is’||avg);
Select * from emp where sal= (select max(sal) from emp)
Select max(sal) from emp where sal not in (select max(sal) from emp)
Function: A function is specified with a return type and must return a value specified in that type. The main purpose of a PL/SQL function is to compute and return a single value.
Procedure: A procedure doesn’t have a return type and it doesn’t return any value, but it can have a return statement which stops its execution and returns to the caller. A procedure returns multiple values, unlike a general function.
Package: A package is a group of functions, procedures, variables, and record TYPE statements. It is a schema object which groups logically related PL/SQL types, items, and subprograms. It provides modularity for application development. It is used for hiding the information from unauthorized users.
SET SERVER OUTPUT ON
FOR i IN REVERSE 1..99
IF Mod(i,3) = 0 THEN
Cursor c1 is select ename, sal from emp;
fetch c1 into v_ename, v_sal;
exist when c1 % notfound;
dbms_output.put_line(v_name ||’ ‘||v_sal);
Ans: The PLV msg allows for.
Ans: PL/Vision offers two packages for managing the transaction processing in PL/SQL. It is PLVcmt and PLVrb.
PLVcmt: This package wraps the logic and complexity to deal with commit processing.
PLVrb: This package provides a programmatic interface to roll-back activity in PL/SQL.
Ans: Use the J format string.
SQL > select to_char(to_date('29-Mar-2013','dd-mon-yyyy'),'J') as julian from dual;
Ans: MERGE is used to combine multiple DML statements into one.
merge into tablename
when not matched then
when matched then
Ans: The spool command is used for printing the output of SQL statements in a file.
select emp_name, emp_id from emp where dept='accounts';
PLVprs: It is an extension for string parsing for PL/SQL, and the functionality of string parsing works at the lowest level.
PLVprsps: It is the highest level package used in parsing the PL/SQL source code into separate atomics. It relies on other parsing packages to get the work done.
Batch starts on 22nd May 2021, Weekend batch
Batch starts on 26th May 2021, Weekday batch
Batch starts on 30th May 2021, Weekend batch