All Rights Reserved @code4change
All Rights Reserved @code4change
INTRODUCTION
a. What is the difference b/w sql and plsql?
Sql: sql is a query lang that allows you to issue a single query or execute a single
inser/update/delete
Pl/sql: it is oracles programmng lang which allows you to write a full program
(loops, variables, etc) to accomplish multiple selects/inserts/ updates/ deletes.
2. DATATYPES
a. What is the diff b/w %rowtype and type records
%ROWTYPE: is used when you need to work with complete record
TYPERECORD: is used to create your own datatype with specified number of
values to hold
Suppose if a table has 20 columns and we need to work with 7 columns
3. BLOCKS
4. CONTROL STATEMENTS
a. What are the conditional statements?
5. LOOP
6. CURSORS
a. If a cursor is open, how can we find a pl/sql program?
Use the %isopen cursor status variable
b. Tell me about cursors?
A cursor is a temporary work area created in the system memory when a sql
statement is executed. A cursor contains information on a select statement and
the rows of data accessed by it
This temporary work area is used to store the data retrieved from database and
manipulate this data. A cursor can hold more than one row, but can process only
one row at a time. The set of rows that cursor holds is called active set
c. What is diff b/w cursor and ref cursor?
Ref cursor: ref cursor is basically a datatype, it is normally declared as
type r_cursor is REF CURSOR. It supports dynamic change of query
Cursor: it is a static cursor in which query is assigned at designing time and
cannot changed at run time
d. What is diff b/w weak and strong ref cursor?
e. What is diff b/w select and cursor?
A select statement make used of cursor implicitly to fetch data from data base
The cursor follow a three stage process of getting data from the database. The
process is
Open cursor
Fetch cursor
---------------------------------------------------------------------------------------------------------------------------------------------------------------All rights reserved @code4change
Close cursor
7. EXCEPTIONS
a. Tell me something about exceptions?
b. What are exception? Tell me some seeded exceptions?
Exceptions are notifications that identify issues that need resolution. Oracle
collaborative planning generates an exception whenever an actual process does
not match the required process
c. What is difference b/w raise and Raise_application_error?
Raise statement is used to explicitly raise an exception with in a pl/sql block. It
immediately stops normal execution of a pl/sql block and transfers control to an
exception handler. It can be used to raise user defined and predefined exception
d. What is SQLCODE & SQLERRM?
SQLCODE shows the error code
SQLERRM shows the error message
Begin
Dbms_output.put_line (error code:||SQLCODE);
Dbms_output.put_line (error message:||SQLERRM);
End;
e. What is exception of prorogation?
A PL/SQL program is an anonymous block, a procedure or a function. This
program or highest level block can call other procedures or functions or nest an
anonymous block with in block . each pl/sql block can have its own exception
section, or it can be totally void of exception handler
To determine the appropriate exception-handling behavior, pl/sql fallows rules
Scope: the pl/sql blocks in which an exception can be raised and hadled
Propagation- the way in which an exception is passed back through enclosing
blocks until it is handled or is resolved to be an unhandled exception.
8. SUBPROGRAMS
a. What are advantages of procedure and function?
A function will return a value, a value can be one of many things including ref
cursor, pl/sql tables, etc. adding to that , it is possible to use a function in sql
statements, whereas procedures cannot be used
---------------------------------------------------------------------------------------------------------------------------------------------------------------All rights reserved @code4change
Procedures are used to execute business logic, where we can return multiple
values from procedure using OUT or INOUT parameter
b. What are formal and actual parameters?
Formal parameters: it is a term used to refer to a parameter defined in the
procedure or function declaration section
Ex: procedure raise_sal(emp_id integer, increase real) is
Actual parameter: it is a term used to refer to a parameter provided by calling
statement to a procedure or a function
Ex: raise_sal (emp_num, amount)
9. PACKAGES
a. Explain polymorphism in pl/sql
Polymorphism is a feature of object-oriented programming, is the ability to
create variable, function, or an object that has more than one form
Consider the below package
Create or replace package addition
Is
Function adding (n integer, m integer) return integer;
Function adding (n date, m integer) return date;
End addition
In oracle procedureal programming also supports polymorphism in the form of
program unit overloading inside a package, member function type etc.
Information hiding with packages, you can specify which types, items, and
subprograms are public (visible and accessible) or private (hidden and
inaccessible).
For example if a package contains four subprograms, three might be public
and one private. The package hides the implementation of the private
subprogram so that only the package is affected if the implementation changes.
This simplifies maintenance and enhancement. Also, by hiding implementation
details from users, you protect the integrity of the package.
c. What is the diff b/w procedure and package?
Procedure: it can be called standalone and process list of action (although
function can also do the same) to perform. The only diff with respect to function
is that it do not require any placeholder column to hold the return value.
Package: if any package component called the whole package gets compiled and
remain loaded in the memory until flushed out (restart or using pragma
serially_reusable). Therefore whenever any function/procedure called the
response time is fast
Draw backs
1. Procedure cant be called inside select/where statement
2. If package procedure/function needs to be used only once,
unnecessary the whole package gets loaded in memory.
d. What is forward declaration and where can we use this?
10.TRIGGERS
a. How may triggers can be applied on a table?
12 types of triggers we can apply on a table
Insert/update/delete--------3
Before/after--------------------2
Rowlevel/statement level2
Hence 3*2*2
Trigger