Professional Documents
Culture Documents
Declaration part: PL/SQL enforces the declaration of variables before their use in
executable portion.
All variables (or) constants have to be declared in this block.
Syntax: variable name data type;
Executable part: this is main section of the block, all the procedural and SQL
statements are defined here.
Exception handling part: this is used for responding to runtime errors encountered by a
program.
MANDATORY BLOCKS IN PL/SQL: executable block in PL/SQL is the mandatory
block other two blocks declarative and exception blocks are optional blocks.
Lob types: (large objects) Bfile (variable stores locator of the file)
BLob (for storing large raw data like graphics or
sound data)
Clob(stores location, which provides location of
data)
PL/SQL TABLES: these are temporary array like objects used in pl/sql block.
These can have one column & a primary key.
These are declared in the declarative part of any block, sub program
Or package.
Syntax: STEP1: type<name of type> is table of<col def> index by binary-integer.
STEP2: <pl/sql-tablename> <type name>
NESTED TABLES: similarly to PL/SQL block along with adding the ability to store
nested tables within a database table will be there.
10.WHAT IS PRAGMA?
Pragmas are compiler directives, it serves as instructions to the pl/sql compiler.
The compiler will act on the pragma during the compilation of the block.
11.WHAT IS EXCEPTION HANDLING IN PL/SQL& TYPES OF EXCEPTION?
Exception handling is used to handle the errors according to users way and functions
It will be used to generate error messages and replacing default messages.
These are 2 types standard & user defined exceptions.
STANDARD EXCEPTIONS 0R BUILT IN EXCEPTIONS: -
Oracle package standard had defined exceptions for certain common errors
Some of them are:
Too-many-rows (ora-01422)
No-data-found (ora-1403)
Value-error (ora-06502)
Zero-divide (ora-01476)
Invalid-number (ora-01722)
Dup-value-on-index (ora-00001)
Program-error (ora-06501)
USER DEFINED EXCEPTIONS: The user defines these exceptions and these are used
to take care of abnormal conditions that are application specific.
12.EXPLAIN SQL CODE & SQLERRM?
These are functions, which return error code and error message of the recent error.
SQL CODE: it returns error code as negative number.
For NO-DATA-FOUND it returns ‘+100’.
SQL ERRRM: it returns length of the messages in 512 characters, which includes code,
message, tablename&column name.
Syntax: ercode: =sqlcode;
Er msg: =sqlerrm;
Insert into error table values (errcode, ermsg);
13.WHAT IS RAISE-APPLICATION-ERROR?
This is a procedure used to generate user-defined errors.
Syntax: raise-application-error (errorcode, errormessage, true/false);
Error code- (range is –20000 to-20999).
Error message (length is 2048 bytes).
True/false- true indicates error is put in stack
False is mentioned then the error replace all the previous errors.
14. What is a cursor?
Cursor is a named private SQL area from where information can be accessed. Cursors
are required to process rows individually for queries returning multiple rows.
16.For Update Of Clause: -when declaring the cursor itself we will be mentioning for
update clause then we can update the records inside of the cursor.
17.Where Current Of Clause: -
Variable declaration;
Constant declaration;
Begin
PL/SQL subprogram body;
Exception
Exception block;
End;
19.FUNCTION: - A procedure is a logically grouped set of SQL and PL/SQL statements
that perform a specific task. It returns a value.
Functions having
Declaration block
Executable block
Exception block
Syntax: - CREATE OR REPLACE FUNCTION function name {IN}
Return data type {IS, AS}
Variable declaration;
Constant declaration;
Begin
PL/SQL subprogram body;
Exception
Exception block;
End;
27.COMPONENTS OF PACKAGE: -
A package has usually two components
Specification
Body
A package specification declares the types, memory variables, constants, exceptions,
cursors and subprograms that are a variable for use.
A package body fully defines cursors, procedures and thus implements the specification.
34.TRIGGERS:
Trigger is a pl/sql block, which will fire automatically whenever some event occurs
like insert, update and delete.
Types of triggers: -
Event
Insert
Update level
Delete
Row level
Time statement level
Before
After
36.TRIGGER PREDICATES?