Gmail - PL - SQL Faq and Exception Handling... SET 1
Gmail - PL - SQL Faq and Exception Handling... SET 1
SET 1
1 message
Infosys Limited India has opportunities for talent with experience in
Oracle PL/SQL
SQL
Please click the link to view detailed job description And to apply
🔥https://infy.com/2szNz2H
Doubts you may reach me on.,
🔥🔥https://bit.ly/reachRaghu
Top crossing repeated 50+ QA and Exception handling scenarios
Here are 50+ frequently asked PL/SQL interview questions and answers which will definitely help you out to
crack one of the toughest interviews.
Q1. How can you Rollback a particular part of a procedure or any PL/SQL Program?
It can be done using Savepoints during definition of a PL/SQL program.
Q10. How can you take an Input from a User of the Database?
You can take it using the Input Operator. This is as follow:
val1:=&val1;
Q13. What is the difference between a Rollback Command and a Commit Command?
A Commit command is used to save the current transaction in the database in which modification is done to the
database using Database Manipulation Language (DML) commands. A Rollback command is however used to
undo the modifications done by the DML commands previously.
Q18. How can you assign a Name to an Un-Named PL/SQL Exception Block?
You can assign a name to an Un-Named Exception using Pragma, also known as Exception_init.
Q22. Why is closing the Cursor required during explicit cursor development?
It is important because it will consume system memory while it is in active state and if it is not closed or
terminated then it won’t let the other things in the memory as memory will be occupied and later on it will be full.
Hence, deletion is necessary.
Q26. What is the Difference between Runtime Errors and Syntax Errors?
A Runtime Error is handled with the help of Exception Handling Mechanism in a PL/SQL Block whereas a Syntax
Error such as a spelling mistake is efficiently detected by the SQL Compiler.
Q30. What is the method to find out whether a Cursor is open or not?
The Cursor Status Variable can be used to find out whether the Cursor is open or not. It is %ISOPEN.
Q33. What are the different Loop Control Structures used in PL/SQL?
The different Loop Control Structures in PL/SQL are as follows:
1. Exit
2. Exit-When
3. Continue
4. Goto
Q37. Explain about Package in short.
A Package is a Schema Object which assembles logically relate PL/SQL Datatypes and Sub-Programs. It is
actually a combination of Procedures, Functions, Record Type and Variables. It enhances Application
Development and this provides Modular Programs. It also provides Encapsulation which hides data from
Unauthorized Users.
Q38. What are the disadvantages of Cursors and is there any alternative to it?
The processing of Cursors is very slow as compared to Joins. Hence, Joins can be an alternative to Cursors.
Q39. What is the method to display messages in Output Files and Log Files?
The Output Files and Log Files can be used to display messages by using the following: Fnd_file.put_line.
Q40. What is the difference between Grant command and Revoke command?
A Grant command permits the End-User to perform certain activities onto the database whereas a Revoke
command prevents the End-User from making any changes to the Database.
Char however preserves the memory location mentioned in the variable declaration even if it is not used. The
maximum storage capacity for a Character variable is 255 Bytes.
Q46. What is a Mutating Table Error and how can you solve it?
It occurs if the Trigger tries to update a row that is currently being used. This is solved either by using the
Temporary Tables or by the Views.
Q47. Enlist the packages provided by the Oracle for use by the Developers?
Oracle provides the packages such as Dbms_Transaction, Dbms_Alert, Dbms_Job, Dbms_Ddl, Dbms_Output,
Dbms_Utility, Dbms_Lock, Dbms_Sql, Dbms_Pipe and Utl_File.
So this was the list of all the important PL/SQL interview questions and answers that are very frequently asked in
the interviews. If you found any information incorrect or missing in above list then please mention it by
commenting below.
An exception is a condition which executes when an error occurs during execution of a PL/SQL program. PL/SQL
provides a feature that lets the programmers to handle these exceptions in the exception block in a PL/SQL
program. Exception block contains the methods (defined by the programmer) which can provide a particular
action that needs to be taken to come out of this error or exception and prevent the program from terminating
abnormally. This mechanism is known as error handling or exception handling in PL/SQL.
1. System-defined Exceptions
2. User-defined Exceptions
System-defined Exceptions
These are pre-defined exceptions situated in Oracle SQL. It is involuntarily raised or executed on encountering a
program that violates any Oracle SQL rules.
1. Named Exceptions
These are system defined exceptions which are pre-defined in the Oracle SQL and normally have a name for
reference intention. Few of the named exceptions are as follows:
a. ZERO_DIVIDE: This error occurs when a user tries to divide a number by zero.
b. NO_DATA_FOUND: This error occurs when a user fires a query that doesn’t return anything.
c. CURSOR_ALREADY_OPEN: This error occurs when you try to access a Cursor which is already open or which is
already being used by any other program.
d. TOO_MANY_ROWS: This error is raised when you try to fetch more than a single row into a variable or a record.
e. LOGIN_DENIED: This error is raised when a user tries to log into the Oracle database with a wrong username or
a password.
f. INVALID_CURSOR: This error occurs when you perform an invalid task on a cursor like fetching data from a
cursor that is closed.
g. STORAGE_ERROR: This error occurs when PL/SQL database runs out of memory or memory gets
malfunctioned.
2. Unnamed Exceptions
These are the system defined exceptions that the Oracle provides to its users. These exceptions don’t have a
naming system to its block structure. However, such exceptions do have an error code and an error message
associated to it.
Such exceptions are handled either by associating the exception code to a name and using it as a named
exception or by using the WHEN other THEN exception handler mechanism.
However, Oracle provides us a feature to assign a name to an unnamed System exception which includes the
usage of a Pragma which is also known as an Exception_Init. This mechanism is used to link the Oracle system
error code to user defined exception name.
1 DECLARE
2 Exception_Name Exception;
3 Pragma
4 Exception_Init (Exception_Name, Error_Code);
5 Begin
6 Execution Section....
7 Exception
8 WHEN Exception_Name THEN
9 Exception Handler....
10 END;
User-defined Exceptions
The user-defined exceptions are the ones that are developed or programmed by the programmer. These are
explicitly declared in the declaration section and explicitly raised in the execution section.
A PL/SQL exception definition contains parts such as exception type, error code/ number and an error message
for the end-user. Every exception whether it is user-defined or pre-defined (System) has an error code associated
with it.
1 Declare
2 Declaration Section
3 Begin
4 Execution Section
5 Exception
6 Exception Section…
7 When ExceptionA Then
8 ExceptionA-Handling Statements
9 When ExceptionB Then
10 ExceptionB-Handling Statements
11 When ExceptionZ Then
12 ExceptionZ-Handling Statements
13 End;
Example
1 declare
2 admin_id integer;
3 admin_name varchar2(20);
4 begin
5 select ano,aname into admin_id,admin_name from Admin
6 where ano=admin_id;
7 dbms_output.put_line(admin_name);
8 exception
9 When NO_DATA_FOUND Then
10 dbms_output.put_line('Administrator Details Unmatched');
11 When OTHERS Then
12 <div style="margin:0px;padding:0px 5px;border:0px;vertical-
13 align:baseline;font-family:inherit;background:0px
14 center;height:inherit;font-size:inherit!important;line-height:inh