You are on page 1of 13

Qno Ques Ans

1 What is loan life cycle?


2 What does bank do in case of non performing loans?
3 What is securitisation
4 What is the difference between procedure and functions?
5 Why procedures cannot be used within sql statement?
6 what are triggers?
7 What are collections ? Explain their types
8 Can collections exists in physical form in database
9 What are cursors? Different types of cursors and their attributes
10 What is bulk collect and what is limit operator
11 What is ROWNUM? How do you get rownum between 700 to 750
12 What are joins? What are different type of joins
13 Give examples of outer joins
14 Can dml statement be used in functions Y
15 what are user defined exceptions? How to raise the user defined exception
16 What is difference between DML and DDL statements
17 What is difference between truncate and delete in respect of memory management in database. Y
18 What are factless dimenssions
19 What are subqueries and co related sub queries?
20 have you worked in performance tuning, what are the steps you follow for it.
21 What is explain plan? and how you will use it.
22 What are views? What are materialized views? Difference between view and materialized views?
23 What is autonomous
Suppose transaction?
a table contains fname and lname fields and it contains duplicate values for these columns, so how will
24 you find the latest duplicate values in this table
25 What is rank and dense rank
26 What is partition by clause

27
28
29

30
31
32 What is AWR, ADDM, OEM?
33 What is difference between NVL and NVL2 ?
34 Can we declare procedure and functions of same name in package
35 What error numbers are reserved for USER_EXCEPTIONS?
36 What is integrity constraints?
37 What are bulk bind?
38 What is compiler directive in Oracle
39 Explain UTL_FILE package and its functions
Ans No

2
3
4
5

6
7

9
9

10
11
12
13
14
15
16
17
21
23
24
25
26
28.1
28.2
29.1
30.1
30.2
30.3
31.1
31.2
31.3

32
Answer

Generally NPL problems are resolved in two ways:


1. Centralization – This happens when all the concerned parties including the banks, regulators and government get together
generally takes the form of a central organization/agency such as an Asset Management Company.
Securitization is the financial
2. Decentralization practice involves
– This approach of pooling various
steps takentypes of contractual
by the debt The
affected banks. suchdecentralized
as residentialapproach
mortgages, commercial
is common m
for ba
card debt obligations (or other non-debt assets which generate receivables) and selling their related cash flows
lending. In this approach, the banks are left alone to manage their own bad loans by giving them incentives, legislative powers, to third party inv
may be described
advantages.
Function must returnas abonds,
value,pass-through
but in Storedsecurities,
Procedureorit collateralized debt obligations
is optional( Procedure can return(CDOs).
zero orInvestors are repaid from the pr
n values).
collected
Worldwide,from
the the underlying
most common debt
and and redistributed
successful through
approach the
towards capital
NPL structure
management of the
is new
the financing.
establishment
Function takes one input parameter it is mandatory ,but Stored Procedure may take 0 to n input parameters.. Securities
of Asset backed by mo
Management
mortgage-backed
companies
Procedures
Functions canuse
doesn'tsecurities
public or (MBS),
bank
necessarily
be called funds while
from Procedureto those
remove
return thewhereas backed
NPAs
data that's by
from other
the
why cannot
Procedures types
bank of
books.
be used
cannot receivables
insidefrom
be called are asset-backed
sql statement securities (ABS).
Function. directly, but it can be used indire
function and calling
Oracle allows you tothat function
define inside sql
procedures thatstatement
are implicitly executed when an INSERT, UPDATE, or DELETE statement is issued
These procedures are called database triggers.
Triggers are similar to stored procedures, discussed in Chapter 14, "Procedures and Packages". A trigger can include SQL and
execute as a unit and can invoke stored procedures. However, procedures and triggers differ in the way that they are invoked. W
executed by a user, application, or trigger, one or more triggers are implicitly fired (executed) by Oracle when a triggering INSER
statement is issued, no matter which user is connected or which application is being used.

Let's start with Nested Tables, they are the most common form of collection and so represent a useful basis of comparison.

A nested table is a variable which can hold more than one instance of something, often a record from a database table. They m

type emp_nt is table of emp%rowtype;


emp_rec_nt emp_nt;
They are useful whenever we want to store multiple instances of data against which we want to do the same thing. The classic
COLLECT to store multiple records:

select *
bulk collect into emp_rec_nt
from employees;
Let's start with Nested Tables, they are the most common form of collection and so represent a useful basis of comparison.

A nested table is a variable which can hold more than one instance of something, often a record from a database table. They m

type emp_nt is table of emp%rowtype;


emp_rec_nt emp_nt;
They are useful whenever we want to store multiple instances of data against which we want to do the same thing. The classic
COLLECT to store multiple records:

select *
bulk collect into emp_rec_nt
from employees;
This gives us a source of data we can loop round; crucially we can navigate backwards as well as forwards, even skip to the en
things we cannot do with a cursor. Nested tables can be collections of any data type, including composites such as PL/SQL rec

An Index By table is better called (as the docs do) an Associative Array . These are simple collections of single attributes with a
have indexes but their indexes are just row counts. With an associative array the index can be meaningful, i.e. sourced from a d
for caching data values for later use. The index can be a number, or (since 9iR2) a string which can be very useful. For instance
of salaries which is indexed by the employee identifier.

type emp_sal_aa is table of emp.sql%type


index by emp.empno%type;
l_emp_sales emp_sal_aa;
Note that I could have declared that array using INDEX BY BINARY_INTEGER but it is clearer to use the %TYPE syntax instea
Elements of that array can identified by an index value, in this case EMPNO:

l_emp_sals(l_emp_no) := l_emp_sal;
Other than caching reference tables or similar look-up values there aren't many use cases for associative arrays.

Variable arrays are just nested tables with a pre-defined limit on the number of elements. So perhaps the name is misleading: th
There's little we can do with VArrays which we can't do with nested tables (except constrain the number of elements and it's pre
do that). They are declared like this:

type emp_va is varray(14) of emp%rowtype;


emp_rec_va emp_va;
We can use bulk collect to populate a VArray ...

select *
bulk collect into emp_rec_va
from employees;
However we must be certain the query will return at most the number of elements specified in the VArray's declaration. Otherwi
22165.

There are no known use cases for variable arrays. Okay that's a bit harsh, but almost all of the time you will use nested tables i
advantage of VArrays over nested tables is that they guarantee the order of the elements. So if you must get elements out in th
them use a VArray.

A nested table can be stored in a database column and so it could be used for simplifying SQL operations where you join a sing
table. An associative array cannot be stored in the database.

Oracle creates a memory area, known as context area, for processing an SQL statement, which contains all information needed
statement, for example, number of rows processed, etc.

A cursor is a pointer to this context area. PL/SQL controls the context area through a cursor. A cursor holds the rows (one or mo
statement. The set of rows the cursor holds is referred to as the active set.

You can name a cursor so that it could be referred to in a program to fetch and process the rows returned by the SQL statemen
two types of cursors:
1. Implicit cursors
2. Explicit cursors

Implicit Cursors
Implicit cursors are automatically created by Oracle whenever an SQL statement is executed, when there is no explicit cursor fo
Programmers cannot control the implicit cursors and the information in it.
Explicit Cursors
Explicit cursors are programmer defined cursors for gaining more control over the context area. An explicit cursor should be def
of the PL/SQL Block. It is created on a SELECT Statement which returns more than one row.
DECLARE
statement. The set of rows the cursor holds is referred to as the active set.
exception_name EXCEPTION;
BEGIN
You can name a cursor so that it could be referred to in a program to fetch and process the rows returned by the SQL statemen
IF condition THEN
two types of cursors:
RAISE exception_name;
1. Implicit cursors
END IF;
2. Explicit cursors
EXCEPTION
WHEN exception_name THEN
Implicit Cursors
statement;
Implicit cursors are automatically created by Oracle whenever an SQL statement is executed, when there is no explicit cursor fo
END;
Programmers cannot control the implicit cursors and the information in it.
You can use the above syntax in raising the Oracle standard exception or any user-defined exception. In the next section, we w
Explicit
DECLARE Cursors
raising a user-defined exception. You can raise the Oracle standard exceptions in a similar way.
Explicit
c_limit cursors
PLS_INTEGER are programmer := 10000;defined cursors for gaining more control over the context area. An explicit cursor should be def
of the PL/SQL Block. It is created on a SELECT Statement which returns more than one row.
User-defined Exceptions
One
PL/SQL method allows of fetching
you to define data your is anown Oracle bulk collect.
exceptions With Oracle
according to the bulkneedcollect,
of yourthe PL/SQL
program. A engine
user-definedtells the SQL engine
exception musttobecolle
dec
In CURSOR
PL/SQL, you employees_cur
can refer to the most recent implicit cursor as the SQL cursor, which always has the attributes like %FOUND, %
place
explicitly,
IS them in a either
using collection. a RAISE statement or the procedure DBMS_STANDARD.RAISE_APPLICATION_ERROR.
%ROWCOUNT. The SQL cursor has additional attributes, %BULK_ROWCOUNT and %BULK_EXCEPTIONS, designed for use
Oracle SELECTprovides a LIMIT clause for BULK COLLECT that allows you to limit the number of rows fetched from the database. The
employee_id
The
For each syntax
FROM for returned byan
declaring
row employees exception
a query, the is −
ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects t
FETCH
joined cursor
rows. The BULK COLLECT
first row selected INTO ...
has a ROWNUM[LIMIT rows]; of 1, the second has 2, and so on.
Main WHERE department_id = department_id_in;
differences between Data Definition Language (DDL) and Data Manipulation Language (DML) commands are:
DECLARE
SELECT * from
where rows can EXCEPTION;
( my-exception be any literal, variable, or expression that evaluates to an integer (otherwise, the database will raise a VALUE_
I. TYPE
Autonomous
DDL
Example vs. employee_ids_t
DML: transactions
DDL statements IS used
are TABLE
arewhen OFyou
used for wan to roll-back
creating and definingsomethe code while continuing
Database structure.toDML process an errorare
statements logging procedur
used for mana
Explain
select Planrownum
m.*, Usage r
LIMIT
The
When employees.employee_id%TYPE;
is
a SQLvery
following useful
example
statement with BULK
illustrates COLLECT,
is passedrefers the concept.
to theto because
server This it helps
program
the Cost you
asks manage
Based Optimizerfor a how
customer
(CBO) muchID, memory
when
usesthe the
database your
user program
enters
statistics to and will
an used
invalid
create to
ID,process
the exc
an executio
https://www.techonthenet.com/oracle/joins.php
Thefromtermtable_name
"automous mMark transaction" the ability ofALTER,
PL/SQL temporarily suspend current transaction begin another,
What
II.
that
navigate is
Sample
you High
need Water
Statements:
to query DDL
and in Oracle?
statements
process 10,000 are CREATE,
rows of data. You DROP,
could useTRUNCATE,
BULK COLLECT RENAME to etc.
retrieve DML all statements
those rows are
and SELECT
populate
)
(which willthrough be the
not approach data. Once
rolled-back
https://www.techonthenet.com/oracle/joins.php
l_employee_ids
UPDATE,
However, MERGE,
this employee_ids_t;
CALL willetc. if the
consume
you've
outer highlighted
lotscode ofthat aborts).
memory
a problem
in The
querytransaction
second
theisPGA
the first thing
for that
you should
is known as an do is EXPLAINtransaction.
autonomous the statement Thetoauc
DECLARE
thewhereCBO
functions r >has700 created.
and
independently r < This
750 from will theoften
parentreveal code. the query not using thesession.
relevantIfindexes,
this code orisindexes
run by many separate
to support Oracle
the query aresc
Answer:
performance
BEGIN
Yes
Plan c_idwe
Table can , may
customers.id%type
but that degradefunction because
:= cannotofbe
&cc_id; PGAcalled swapping.
in select statement
III.
The Number
c_name
OPENexplain of Rows:
customerS.Name%type;
employees_cur;
plan process DDL statements
stores data work
in the on whole table. This
PLAN_TABLE. CREATE tablewill canabe create a new
located table.
in the DROP
current will remove
schema the whole
or a shared schematab
An
1.
records
RANK autonomous
High
c_addr water
in a mark
table. transaction
is
DML
customers.address%type; the has thecan
maximum
statements following
amount work of characteristics:
ondatabase
one or blocks
more used
rows. so
INSERT far by
cana segment.
insert one This
or mark
more cannot
rows. be
DELETE reset
canby delete
remove
SQL*Plus as follows.
The -- user
LOOPbasicdefineddescription exception for the RANK analytic function is shown below. The analytic clause is described in more detail here.
2.
IV. Delete
WHERE
-- ex_invalid_id
Creating Table
a operation
clause: DDL
EXCEPTION;
shared PLAN_TABLE won't resetprior
statements HWM.
do not
to 11ghave a WHERE clause to filter the data. Most of DML statements support filtering th
create FETCH or employees_cur
replace function yrofsrv(empid number)
BEGIN
RANK()
SQL> CONN OVERsys/password
([ query_partition_clauseAS SYSDBA ] order_by_clause)
There
3.
V.
return BULK
are
TRUNCATE
Commit:
IF c_id
DENSE_RANK number
<= COLLECT
many
0 times
will
Changes
THEN resetdoneINTO
when HWM. by youl_employee_ids
a might
DDL want to use
statement can an notautonomous
be rolled back. transaction
So theretoiscommit
no needortoroll backa some
issue COMMIT changes to a table c
or ROLLBACK
Connected
create or replace function emprecord (empid number) return sys_refcursor
The
is LIMIT
transaction's
statement.
RAISE
basic c_limit;
We final outcome.
need tofor
ex_invalid_id;
description run the COMMIT
DENSE_RANK or ROLLBACK analytictofunction
confirmisour shownchanged below. after
Therunning
analytica clause
DML statement.
is described in more detail he
SQL>
is
select @$ORACLE_HOME/rdbms/admin/utlxplan.sql
a.fname, a.lname ,rowid
4. The
ELSE high water mark level is just a line separate the used blocks and free blocks.
yrofsvc_p
SQL>
p_record
from
We GRANT
test1
use anumber;
a compiler ALL
SYS_REFCURSOR; ON
directivesys.plan_table
inINTO
PL/SQL TO(calledpublic; a 0;
pragma) to
VI.
SQL> EXIT
Transaction:
SELECT
DENSE_RANK()CREATE WHEN Since
name, l_employee_ids.COUNT
OVER([
PUBLIC each
address DDL statement
c_name,
query_partition_clause
SYNONYM plan_table =
isc_addr
permanent, wetell
] order_by_clause)
FOR
Oracle
can
sys.plan_table; not run thatmultiple
our transaction is autonomous.
DDL statements in a group An like
autonomous
Transaction.tranD
begin
where
begin
autonomous
The rowid=(select
blocks scope.
above the max(rowid)
TheHWM PL/SQL level from
compiler
is freetest1 where
is
blocks, a.fname=fname
instructed
they are to mark
ready a
to and
routine
use. a.lname=lname
as autonomous group
(i.e. by fname,lname
independent) by having
the count(fna
AUTONMOU
select
a
The
In
select FROM
Oracles.name,g.grade
Transaction.
DENSE_RANK Then
customers
11g a shared
nvl(e.emp_id,l.emp_id) we
functioncan
PLAN_TABLECOMMIT
acts like theor ROLLBACK
RANK function
is created
emp_id,nvl(e.emp_name,'Not this
by default, group
except
but as a
thatcan
you
Available') transaction.
it assigns Eg.
consecutive
still create We
a local can
emp_name,nvl(l.location,'Not insert
ranks,from
version data in
soAvailable')
of this
the two tables
is notusing
table like and
olympic com
me
the "utlxpla
location
select
from
open
The
from the trunc(sum(months_between(nvl(end_date,sysdate),start_date)/12))
calling
p_record
blocks
employee1 below code.
forthe
s,grades HWM level is used blocks, they are already used.
gl_employee_ids.COUNT into yrofsvc_p custom.employee wh
from FORALL
WHERE
PARTITION
return employee2 idindx
= e IN
c_id;
BYcustom.employee
segregate 1 .. sets,and thiswhere
enables you to be able to work(ROW_NUMBER(),COUNT(),SUM(),etc) on related set inde
select
where
VII. *yrofsvc_p;
Triggers:from
s.marks
join After
DBMS_OUTPUT.PUT_LINE
AUTOTRACE
full UPDATE
outer between
DDL
-employees
The
location1 Easy g.low
l statements g.high;
no triggers
('Name:
emptransactions,
Option? '||emp_id=empid;
are fired. But after DML statements relevant triggers can be fired.
c_name);
end;
As
return an example
p_record;
DBMS_OUTPUT.PUT_LINE of autonomous ('Address: ' let's
|| assume that you need to log errors into a Oracle database log table. You need
c_addr);
Switching
on SETbecause
on
e.emp_id=l.emp_id emp.salary
the AUTOTRACE =resulting error, but you don't causes
parameter in SQL*Plus anerror
explain to be to performed
rollback. on every query.
/transaction
end;ENDbyIF;1; emp.salary of the want the log code Here is an example of a PL/SQL er
order
automous transaction:
select yrofsrv(11)
/SQL> SET AUTOTRACE from dual;
ON
select
EXCEPTION * from+runners emp.salary r where * 0.15
not exists(select 1 from races where winner_id=r.id) order by id;
selectWHERE emprecord(11) emp.employee_id from dual; = l_employee_ids(indx);
/ WHEN
END
ex_invalid_id THEN
LOOP;
SELECTdbms_output.put_line('ID
M.EMP_ID must be greater than zero!');MANAGER,AVG(E.MONTHLY_SALARY) "AVERAGE SALARY
MANAGER_ID,M.EMP_NAME
SELECT M.EMP_NAME
close employees_cur;
WHEN no_data_found THEN MANAGER,SUM(DECODE(E.EMP_GENDER,'M',1,0)) "MALE
FROM EMPLOYEE E,EMPLOYEE M
EMPLOYEES",SUM(DECODE(E.EMP_GENDER,'F',1,0))
END; "FEMALE EMPLOYEES", COUNT(*) "TOTAL NO OF EM
dbms_output.put_line('No such customer!');
WHERE
FROM E.MANAGER_ID=M.EMP_ID
WHENEMPLOYEE
SELECT others
* FROM THEN E,EMPLOYEE
EMPLOYEE E1 WHERE M 2=(SELECT COUNT(*) FROM EMPLOYEE E WHERE E.MONTHLY_SA
GROUP
WHERE BY M.EMP_ID,M.EMP_NAME
E.MANAGER_ID=M.EMP_ID
dbms_output.put_line('Error!');
ORDER
GROUP
END; BY
BY M.EMP_ID;
M.EMP_NAME
/ORDER BY M.EMP_NAME;
When the above code is executed at the SQL prompt, it produces the following result −

AWR
Enter is Automatic
value workload
for cc_id: -6 (let'sRepository, ADDM
enter a value -6) - Automatic Database Diagnostic Monitor use to analyse AWR report
OEM
old 2:stands for Oracle Enterprise
c_id customers.id%type manager
:= &cc_id;
AWR
new 2:(Automatic Workload Repository)
c_id customers.id%type := -6; is a built-in repository (in the SYSAUX tablespace) that exists in every Oracle Database
ID must be greater than zero!

PL/SQL procedure successfully completed.


s, the Oracle Database makes a snapshot of all of its vital statistics and workload information and stores them in the AWR
em in the AWR

You might also like