Oracle PL/SQL Interview Questions and Answers

What is the advantage of using packages for storing PL/SQL objects?

Packages offer several advantages when you call a packaged subprogram for the first time, the whole package is loaded into memory. So, later calls to related subprograms in the package require no disk I/O. 
Packaged public variables and cursors persist for the duration of a session. So, they can be shared by all subprograms that execute in the environment. 
You can specify public (visible and accessible) or private (hidden and inaccessible) in Package.

Define exception and How will you raise an exception in PL/SQL procedure?

In PL/SQL, a error condition is called an exception. Exceptions can be system defined or user defined.

Examples of system defined exceptions include division by zero and out of memory. Some common system exceptions have predefined names, such as ZERO_DIVIDE and STORAGE_ERROR.
You can define exceptions of your own in the declarative part of any PL/SQL block, subprogram, or package. Unlike system defined exceptions, user-defined exceptions must be declared and must be raised explicitly by RAISE statements. 

The following example illustrates the scope rules: 

DECLARE
due EXCEPTION; 
BEGIN
RAISE due; 
EXCEPTION
WHEN due THEN 
Null;
END; 
What is the difference between Procedure and Function?

A function is a subprogram written to perform certain computations ,
Functions must return a value (using the RETURN keyword), but for stored procedures this is not compulsory. Stored procedures can use RETURN keyword but without any value being passed. 
Functions could be used in SELECT statements, provided they don't do any data manipulation. However, procedures cannot be included in SELECT statements. 

What is PL/SQL ?
SQL is a declarative language that allows database programmers to write a SQL declaration and hand it to the database for execution. As such, SQL cannot be used to execute procedural code with conditional, iterative and sequential statements. To overcome this limitation, PL/SQL was created. PL/SQL is Oracle's Procedural Language extension to SQL.using plsql we perform Conditional Control ,Iterative Sequential Control Statements.it is commonly used to write data-centric programs to manipulate data in an Oracle database.

What is the difference between SQL and PL/SQL?
Both SQL and PL/SQL are languages used to access data within Oracle databases. SQL is a limited language that allows you to directly interact with the database. You can write queries (SELECT), manipulate objects (DDL) and data (DML) with SQL. PL/SQL is a programming language that includes all the features of most other programming languages. its easily integrate with SQL. SQL is executed one statement at a time. PL/SQL is executed as a block of code. SQL tells the database what to do (declarative), not how to do it. In contrast, PL/SQL tell the database how to do things (procedural).
What is the Difference between PL/SQL Table & Nested Table?
PL/SQL Table: Index by Tables are not Stored in Database. Nested Table: Nested Tables are Stored in Database as Database Columns.
What is the Sequence of Firing Database Triggers?

a) Before Statement Level Trigger
b) Before Row Level Trigger
c) After Row Level Trigger
d) After Statement Level Trigger

What is Instead Of Trigger?
This trigger is used to perform DML operation directly on the underlying tables, because a view cannot be modified by normal DML Statements if it contains joins or Group Functions. These triggers are Only Row Level Triggers. The CHECK option for views is not enforced when DML to the view are performed by Instead of Trigger.
Give some important Oracle supplied packages?

DBMS_SQL: It is used to write Procedures & Anonymous blocks that use Dynamic SQL.

DBMS_JOB: Using it, we can submit PL/SQL programs for execution, execute PL/SQL programs on a schedule, identify when programs should run, remove programs from the schedule & suspend programs from running.

DBMS_OUTPUT: This package outputs values & messages from any PL/SQL block.

UTL_FILE: With this package, you can read from & write to Operating system files

UTL_HTTP: This package allows to make HTTP Requests directly from the database.

Give some most often used system defined exceptions?

a) NO_DATA_FOUND (Select Statement returns no rows)
b) TOO_MANY_ROWS (Single row Select statement returns more than 1 row)
c) INVALID_CURSOR (Illegal cursor operations occurred)
d) CURSOR_ALREADY_OPEN (If cursor is opened & we are trying to reopen it)
e) INVALID_NUMBER (Conversion of Character to number fails) f) ZERO_DIVIDE
g) DUP_VAL_ON_INDEX (Attempted to insert a duplicate value)

What is a mutating and constraining table?

“Mutating” means “changing”. A mutating table is a table that is currently being modified by an update, delete, or insert statement. When a trigger tries to reference a table that is in state of being changed, it is considered “mutating” and raises an error since Oracle should not return data that has not yet reached its final state. Another way this error can occur is if the trigger has statements to change the primary, foreign or unique key columns of the table off which it fires.

Can one call DDL statements from PL/SQL?
One can call DDL statements like CREATE, DROP, TRUNCATE, etc. from PL/SQL by using the “EXECUTE IMMEDATE” statement.

Latest Updates

Height and Distance

An aeroplane flying at a height of 300 m above the ground passes vertically above another plane at an instant when the angles of elevation of the two planes from the same point on the ground are 60º and 45º respectively. What is the height of the lower plane from the ground?

From the top of a building 90 m high, the angles of depression of the top and the bottom of a tree are 30º and 45º respectively. What is the height of the tree?

Trigonometry

What is the value of sinx √( 1 /1+cosx + 1 /1-cosx ) ?

What is cos4 A - sin4 A / cos2 A - sin2 A equal to?

If 7sin2 x +3cos2 x = 4, 0 < x < 90º ,then what is the value of tan x?

If x = a cosθ + b sinθ and y = a sinθ - b cosθ then what is x2 + y2 equal to?

Average

The mean of 5 numbers is 15. If one more number is included, the mean of the 6 numbers becomes 17. What is the included number?

The mean marks obtained by 300 students in a subject are 60. The mean of top 100 students was found to be 80 and the mean of last 100 students was found to be 50. The mean marks of the remaining 100 students are?

In an asymmetrical distribution, of the mean and median of the distribution are 270 and 220 respectively, then the mode of the data is?

Let a, b, c, d, e, f, g be consecutive even numbers and j, k, l, m, n be consecutive odd numbers. What is the average of all the numbers?

Alligation or Mixture

25 kg of alloy X is mixed with 125 kg of alloy Y. If the amount of lead and tin in the alloy X is the ratio 1 : 2 and the amount of lead and tin in the alloy Y is in the ratio 2 : 3, then what is the ratio of lead to tin in the mixture?

Simplification

The ratio of two numbers is 1 : 5 and their product is 320. What is the difference between the square of these two numbers?

Trigonometry

What is the value of cot 4π/3 ?

Indian Politics

Article-24 of the Indian Constitution ‘Prohibition of employment of children in factories, etc’ deals with?

Article-134A of the Indian Constitution ‘Certificate for appeal to the Supreme Court’ deals with?

Chemistry

Who invented Aspirin?

Physics

A larger force on a rotating body results in larger?

What is the unit of the physical quantity, magnetic flux density?