Oracle Interview Questions and Answers
What are the PL/SQL Statements used in cursor
DECLARE CURSOR name, OPEN cursor name, FETCH
cursor name INTO or Record types, CLOSE cursor name.
What are the components of a PL/SQL Block ?
Declarative part, Executable part and Exception part.
What is a database trigger ? Name some usages of
database trigger ?
Database trigger is stored PL/SQL program unit
associated with a specific database table. Usages are
Audit data modifications, Log events transparently,
Enforce complex business rules Derive column values
automatically, Implement complex security
authorizations. Maintain replicate tables.
What is a cursor ? Why Cursor is required ?
Cursor is a named private SQL area from where
information can be accessed. Cursors are required to
process rows individually for queries returning multiple
What is a cursor for loop ?
Cursor for loop implicitly declares %ROWTYPE as loop
index, opens a cursor, fetches rows of values from active
set into fields in the record and closes when all the
records have been processed.
e.g.. FOR emp_rec IN C1 LOOP
salary_total := salary_total +emp_rec sal;
What will happen after commit statement ?
Cursor C1 is
ename from emp;
open C1; loop
Fetch C1 into
The cursor having query as SELECT .... FOR UPDATE gets
closed after COMMIT/ROLLBACK.
The cursor having query as SELECT.... does not get
closed even after COMMIT/ROLLBACK.
How packaged procedures and functions are called from
a. Stored procedure or anonymous block
b. an application program such a PRC *C, PRO* COBOL
c. SQL *PLUS??
a. PACKAGE NAME.PROCEDURE NAME (parameters);
variable := PACKAGE NAME.FUNCTION NAME (arguments);
EXEC SQL EXECUTE
PACKAGE NAME.PROCEDURE NAME (parameters)
variable := PACKAGE NAME.FUNCTION NAME (arguments);
c. EXECUTE PACKAGE NAME.PROCEDURE if the procedures does
not have any out/in-out parameters. A function can not
What is a stored procedure ?
A stored procedure is a sequence of statements that
perform specific function.
What are the components of a PL/SQL block ?
A set of related declarations and procedural statements
is called block.
What is difference between a PROCEDURE & FUNCTION ?
A FUNCTION is always returns a value using the return
A PROCEDURE may return one or more values through
parameters or may not return at all.
What is difference between a Cursor declared in a
procedure and Cursor declared in a package specification
A cursor declared in a package specification is global
and can be accessed by other procedures or procedures in
A cursor declared in a procedure is local to the
procedure that can not be accessed by other procedures.
What are the cursor attributes used in PL/SQL ?
%ISOPEN - to check whether cursor is open or not
% ROWCOUNT - number of rows fetched/updated/deleted.
% FOUND - to check whether cursor has fetched any row.
True if rows are fetched.
% NOT FOUND - to check whether cursor has fetched any
row. True if no rows are featched.
These attributes are proceeded with SQL for Implicit
Cursors and with Cursor name for Explicit Cursors.
What are % TYPE and % ROWTYPE ? What are the advantages
of using these over datatypes?
% TYPE provides the data type of a variable or a
database column to that variable.
% ROWTYPE provides the record type that represents a
entire row of a table or view or columns selected in the
The advantages are :
I. Need not know about variable's data type
ii. If the database definition of a column in a table
changes, the data type of a variable changes
What is difference between % ROWTYPE and TYPE RECORD ?
% ROWTYPE is to be used whenever query returns a
entire row of a table or view.
TYPE rec RECORD is to be used whenever query returns
columns of different table or views and variables.
E.g. TYPE r_emp is RECORD (eno emp.empno% type,ename emp
ename %type );
e_rec emp% ROWTYPE
cursor c1 is select empno,deptno from emp;
e_rec c1 %ROWTYPE.
What are the different types of PL/SQL program units
that can be defined and stored in ORACLE database ?
Procedures and Functions,Packages and Database Triggers.
What are the advantages of having a Package ?
Increased functionality (for example,global package
variables can be declared and used by any proecdure in
the package) and performance (for example all objects of
the package are parsed compiled, and loaded into memory
What are the uses of Database Trigger ?
Database triggers can be used to automatic data
generation, audit data modifications, enforce complex
Integrity constraints, and customize complex security
What is a Procedure ?
A Procedure consist of a set of SQL and PL/SQL
statements that are grouped together as a unit to solve
a specific problem or perform a set of related tasks.
What is a Package ?
A Package is a collection of related procedures,
functions, variables and other package constructs
together as a unit in the database.
What is difference between Procedures and Functions ?
A Function returns a value to the caller where as a
Procedure does not.
What is Database Trigger ?
A Database Trigger is procedure (set of SQL and PL/SQL
statements) that is automatically executed as a result
of an insert in, update to, or delete from a table.
Can the default values be assigned to actual parameters?
Can a primary key contain more than one columns?
What is an UTL_FILE.What are different procedures and
functions associated with it?
UTL_FILE is a package that adds the ability to read and
write to operating system files. Procedures associated
with it are FCLOSE, FCLOSE_ALL and 5 procedures to
output data to a file PUT, PUT_LINE, NEW_LINE, PUTF,
FFLUSH.PUT, FFLUSH.PUT_LINE,FFLUSH.NEW_LINE. Functions
associated with it are FOPEN, ISOPEN.
What are ORACLE PRECOMPILERS?
Using ORACLE PRECOMPILERS, SQL statements and PL/SQL
blocks can be contained inside 3GL programs written in
C,C++,COBOL,PASCAL, FORTRAN,PL/1 AND ADA. The
Precompilers are known as Pro*C,Pro*Cobol,... This form
of PL/SQL is known as embedded pl/sql,the language in
which pl/sql is embedded is known as the host language.
The prcompiler translates the embedded SQL and pl/sql
statements into calls to the precompiler runtime
library. The output must be compiled and linked with this
library to creator an executable.
Differentiate between TRUNCATE and DELETE?
TRUNCATE deletes much faster than DELETE
It is a DDL statement
It is a DML statement
It is a one way trip, cannot ROLLBACK
One can Rollback
Doesn't have selective features (where clause)
Doesn't fire database triggers
It requires disabling of referential constraints.
What is difference between a formal and an actual
The variables declared in the procedure and which are
passed, as arguments are called actual, the parameters
in the procedure declaration. Actual parameters contain
the values that are passed to a procedure and receive
results. Formal parameters are the placeholders for the
values of actual parameters
Page Numbers :