You are on page 1of 7

PLSQL Interview Question with Answer

1. What is PL/SQL.?

- It is a procedural language which is extension to SQL.

- The purpose of PL/SQL is to combine query language and procedural


programming language.

- A bundle of sql queries will execute in single call.

- Implement bussiness logic

-- 2. What is Cursor.?

- Cursor is a SQL private area where the query get passed and executed.

- It is a pointer to the memory location which holds the information about the
SQL statement and its resultset.

- Cursor is two types :


- Implicit Cursor
- Explicit Cursor

- Implicit Cursor can return eaxctly single row. It is constructed and managed by
PL/SQL, but can get information from
its attributes.

- Explicit cursor can return multiple rows. It is constructed and managed by us.
We can open, fetch and close cursor as we want.

-- 3. What is Exception.?

- An error which interrupts the normal flow of program instructions

- Exception which handle the error in run-time and compilation time.

- In PL/SQL , Exception block that raises the Exception which helps us to find out
the error and resolve it.

- We can handle exception by using some of Pre-defined and User defined


exception.

--
PLSQL Interview Question with Answer

4. What is Stored Procedure.?

- Procedure is a Named PL/SQL Sub Program which is compiled and stored in


database.

- Procedures performs an action and mostly used to implement business logics.

- It is complied once and can be executed multiple times for Repeated Usage.

- There are two types of procedure


- Static Procedure - Without Arguments
- Dynamic Procedure - With Arguments

-- 5. What is Functions.?

- Function is named PLSQL sub program which compiled and stored in the
database.

- Function is mostly used to Compute values and to fetching some data from
table.

- Function must return one value and Function header contains return clause.

- Function can be executed in SQL SELECT statement.

-- 6. What is Pragma Autonomous_Transaction.?

- PRAGMA AUTONOMOUS_TRANSACTION is a independent session.


It can be executed without dependency of other subprograms.

- We have to use COMMIT, whenever your subprogram have PRAGMA


AUTONOMOUS_TRANSACTION
It act like independent.

- PRAGMA is a key and AUTONOMOUS_TRANSACTION is independent


event.

-- 7. What is Package.?

- Package is a schema object which will groups logically related procedure and
function.
PLSQL Interview Question with Answer

- A package will contain two mandatory parts

- Package specification
- Package body or definition

- We can declare global variable,


cursor and
exception inside the package
specification part.

- if you execute any procedure or function inside the package, the rest of the
program also get loaded into memory.

-- 8. What is Trigger.?

- Triggers are stored procedure, which are automatically executed or fired when
some events occur

- Triggering Events Like:

- DML Statemnts [INSERT, UPDATE, DELETE]


- DDL Statements [CREATE, ALTER]
- SYSTEM EVENT [STARTUP, SHUTDOWN]
- USER EVENT [LOG ON, LOG OFF]

- We cant execute trigger, it executes implicitly whenever the particular event


takes place.

-- 9. What is Refcursor.?

- Ref Cursor is an acronym of Reference to a Cursor.

- Ref cursor is a datatype. It used for multiple SQL statements in the PL/SQL
Block.

- Ref cursor is used to pass the resultset from one sub program to another sub
program.

- Types of Ref cursor.

- Strong Ref cursor - With Fixed Return type.


- Weak Ref cursor - Without Fixed Return type.
PLSQL Interview Question with Answer

- Sys Refcursor - Oracle Builtin Weak ref cursor.

-- 10. What is Collection.?

- Collection is a ordered group of logically related information.

- It is a high level datatype used to store multiple values as single variable can be
declared by using TYPE keyword.

- There are three collection types −

- Index-by tables or Associative array


- Nested table
- Variable-size array or Varray

-- 11. What is Bulk Collect.?

- Bulk Collect is used to process large volume of data.

- It mainly reduces context switches between SQL and PL/SQL engine and allows
SQL engine to fetch all the records
at once.

using bulk collect we fetch records bulk.

- When we use BULK COLLECT in SELECT statement, as BULK COLLECT


fetches the record in BULK so the INTO clause should always contain a collection type variable.

-- 12. What is Dynamic SQL.?

- The SQL statements will be created and executed at run-time based on the
requirement is called Dynamic SQL.

- The advantage of Dynamic SQL is that we can use DDL statement in PLSQL
block.

- These sql statements are executed by using EXECUTE IMMEDIATE keyword


and SQL statement should be inside the strings.
PLSQL Interview Question with Answer

-- 13. What are all Cursor attributes.?

1. %ISOPEN - Returns true if cursor is open, otherwise false.

2. %FOUND - Returns true if record was fetched successfully, otherwise


false.

3. %NOTFOUND - Returns true if record was not fetched successfully,


otherwise false.

4. %ROWCOUNT - Returns the number of rows fetched from the cursor at the
point of time.

-- 14. What is parametarized cursor.?

- While declaring the cursor we can add parameter and passed them into the query
whenever the cursor are opened.

- It define only datatype of parameter and not need to define its length.

-- 3. What are the types Of Exception.?

1. Pre-defined Exception.-> This exception will get raised if certain database rule is violated by
the program.

2. User-defined Exception.-> In this Exception, User can create own exception and handle the
error. It must be declared and
raised explicitly using RAISE statement.

3. Application_Error. -> We declare a user defined exception with your own


customized error number and message and
display it in application.

4. Pragma Exception_Init.-> It is used to handle unnamed exceptions in oracle.

15 What are the types of Pre defined exception.?

- NO_DATA_FOUND - It raised when SELECT INTO statement returns


no rows.
TOO_MANY_ROWS - It raised when SELECT INTO statement returns
more than one rows.
PLSQL Interview Question with Answer

- DUP_VAL_ON_INDEX - It raised when duplicate values are attempted to insert in a


column having UNIQUE index

CURSOR_ALREADY_OPEN - It raised when we try to open cursor which is already open

INVALID_CURSOR - It raised when we attempt cursor operation which is not


declared/opened.

VALUE_ERROR - It raised when arithmetic, conversion, size constraints


error occurs.

PROGRAM_ERROR - It raised when there is any internal error.

ACCESS_INTO_NULL - It raised when a NULL object automatically assigned a


value.
...
...
OTHERS - It is used to raise all remaining exception which we dont know.
- This exception which is used most.
- In others we can know the error message
and error code by using
- SQLERRM - SQL Error Message.
- SQLCODE - SQL Error Code.

-- 16. What is Local Procedure.?

- Procedure within a sub program(In DECLARE block).

- Scope of the procedure is only with in the particular block.

-- 17. What is Procedure Overloading.?

- Procedure can have same name but the Number of Parameters must be different
or order of the data type is different.

- Only local or packaged subprograms, or type methods, can be overloaded.

- You cannot overload standalone subprograms.

--18. What is Package Overloading?

- If the procedure and function name are having same, thenn Number of
Parameter must be different or
PLSQL Interview Question with Answer

order of the data type should be different.

--

19. What is Forward Declaration in Package?

- We have to declare the procedure or function name into the package


specification.

- But Inside the package body, We can include procedure or function which is not
declare in the specification
It is called forward declaration package.

- Program will be get success while compilation, but not executed which is not
declared in the specification part.

-- 20. Global Variable and Local Variable:

Global Variable : It is the variable inside the package specification.

Local Variable : It is the variable inside the subprograms of package body.

You might also like