PL/SQL Interview Questions Flashcards
What is PL/SQL
PL/SQL is a procedural language which has interactive SQL, as well as procedural programming language constructs like conditional branching and iteration.
Difference between %ROWTYPE and TYPE Record
%ROWTYPE is used when a query returns an entire row of a table or view.
TYPE RECORD is used when a query returns column or different tables or views
TYPE r_emp is RECORD (sno smp.smpno%type, snake smp sname %TYPE)
e_rec smp %ROWTYPE
Cursor c1 is select smpno,dept from smp;
e_rec c1 %ROWTYPE
Explain use of a cursor
Cursor is a named private area in SQL from which information can be accessed. When multiple records exist they require is record to be processed individually
Cursor code example for loop
FOR smp_rec IN C1 LOOP
Totalsal:=totalsal + 100;
ENDLOOP;
Explain the use of Database Triggers
A PL/SQL program unit associated with a particular DB table. It is used for:
- Audit data modifications
- Log events transparently
- Enforce complex business rules
- maintain Replica Tables
- Derive column values
- Implement Complex security authorizations
What are two types of Exceptions
Error handle part of PL/SQL Block
- user_defined
- Predefined
Show some predefined exceptions
DUP_VL_ON_INDEX
ZERO_DIVIDE
NO_DATA_FOUND
TOO_MANY_ROWS
CURSOR_ALREADY _OPEN
INVALID_NUMBER
INVALID_CURSOR
PROGRAM_ERROR
TIMEOUT_ON_RESOURCE
STORAGE_ERROR
LOGON_DENIED
VALUE_ERROR
etc.
Explain Raise_application_error
It is a procedure of package DBMS_STANDARD that allows issuing of user_defined error messages from DB trigger or stored sub-program