Sie sind auf Seite 1von 341

Autonomous transactions

What is an autonomous transaction?


Asked by: sidd_130 | Member Since Oct-2012 | Asked on: Oct 6th, 2012
View all questions by sidd_130

Answer Question
Showing Answers 1 - 2 of 2 Answers
VASU
Answered On : Oct 20th, 2012
BY USING AUTONOMOUS TRANSACTION
WE GET THE FOLLOWING ADVANTAGES
WE PROCEDURE HAVING TRANSACTIONS STATEMENTS WE CALL PROCEDURE AUTOMATICALLY EFFECT
THE ABOVE TRANSACTIONS ALSO TO OVERCOME THAT PROBLEM WE HAVE TO USE AUTONOMOUS
TRANSACTION..
Answer Question

Login to rate this answer.


Sonal
Answered On : Nov 7th, 2012
The AUTONOMOUS_TRANSACTION pragma changes the way a subprogram works within a transaction. A
subprogram marked with this pragma can do SQL operations and commit or roll back those operations,
without committing or rolling back the data in the main transaction.

A trigger or procedure can be marked as autonomous by declaring it as PRAGMA


AUTONOMOUS_TRANSACTION;.

Keyword Pragma signifies that the statement is a pragma (compiler directive). Pragmas are processed at
compile time, not at run time.

Oracle collections
What are the types of collection in PL/SQL? What is the advantage of nested tables?
Asked by: sidd_130 | Member Since Oct-2012 | Asked on: Oct 6th, 2012
View all questions by sidd_130

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


pawan
Answered On : Nov 6th, 2012

Varrays,nested tables,index by tables are oracle collection.Index by tables also known as associative
array similar to hashtables in java. Varrays are like arrays in java static in nature need to define
maximum size at time of declaration.Nested tables are like nested class in java holding a table as a
column of a table.

what is the use of nocopy parameter in oracle procedure


Hi,
What is nocopy parameter in oracle procedure. what is the use of it. In which situation,we can use the
nocopy parameter.
Thanks,
Saravanan.
Return back to PL/SQL
Answer Question

Showing Answers 1 - 11 of 11 Answers


subbaraovangalli
Answered On : Mar 26th, 2007
View all questions by subbaraovangalli View all answers by subbaraovangalli
no copy parameter is an argument in a procedure
it says to oracle to pass the variable value back to the user as quickly as possible.
Answer Question

Login to rate this answer.


Jegadeesan
Answered On : Mar 26th, 2007
NOCOPY is a IN OUT COPY Which is used avoid the overhad of copying IN OUT Parameter Values. If
IN OUT parameter returns huge records we can specify the NOCOPY to copy the values.

The PLSQL Engine first makes a copy of the record and then during program executing makes a
changes to that copy.

Regards
Jegadeesan
Answer Question

Login to rate this answer.


tharik
Answered On : Mar 27th, 2007
View all answers by tharik

NOCOPY will instruct Oracle to pass the argument as fast as possible. This can significantly enhance
performance when passing a large value.
Answer Question
Login to rate this answer.
vmahawar
Answered On : Apr 18th, 2007
NOCOPY Parameter in Oracle Procedure is used to pass arguments to the any procedure and function as
Reference to improve the performance of the code.
This is done in case the arguments like records, pl/sql tables are passed to the called procedures.
Answer Question

Login to rate this answer.


sippsin
Answered On : Jul 22nd, 2008
View all answers by sippsin
Ussually IN paramter is pass by value and OUT/IN OUT are pass by refererence....

If one wants to send the IN paramter too as pass by reference he could add NOCOPY
parameter....

advantage is always less memory usage

disadvantage is when there is a change happened to the Reffered value and a rollback occurs in the
procedure the change of value would be retained.... it could not be rolled back....

so I beleive that it is always safe to work without the NOCOPY parameter.....


Answer Question

Login to rate this answer.


ratna82
Answered On : Oct 10th, 2008
View all answers by ratna82

When a parameter is passed as an IN variable, it is passed by reference. Since it will not change, PL/SQL
uses the passed variable in the procedure/function. When variables are passed in OUT or INOUT mode,
a new variable is define, and the value is copied to the passed variable when the procedure ends. If the
variable is a large structure such as a PL/SQL table or an array, the application could see a performance
degradation cause by copying this structure.
The NOCOPY clause tells to PL/SQL engine to pass the variable by reference, thus avoiding the cost of
copying the variable at the end of the procedure. The PL/SQL engine has requirements that must be met
before passing the variable by reference and if those requirements are not met, the NOCOPY clause will
simply be ignored by the PL/SQL engine.
Answer Question
1 User has rated as useful.

Login to rate this answer.


amianan
Answered On : Nov 10th, 2008
View all answers by amianan

TO PASS OUT AND INOUT Parameters by refrenece instead of value.


Answer Question

Login to rate this answer.


vanishavadlya
Answered On : Oct 29th, 2009
View all answers by vanishavadlya

Three types of parameter modes


1) IN parameter mode- This mode is used to pass values to the calling module when invoked. The value
of IN parameter can't be changed in the module.

2) OUT parameter mode -This mode is used to return a value to the main block. The value of OUT
parameter can change anywhere in the program.

3) IN OUT parameter mode-This mode is used to pass values to the calling module and return a value to
the main block. The value of IN OUT parameter can change anywhere in the program.

In Call By value, the copy of actual parameter is passed to the formal parameter, So any changes to the
formal parameter doesn't affect the actual parameter.

In Call By reference, the address of actual parameter is passed to the formal parameter, so any changes
to the formal parameter will change the actual parameter also, because both of them are pointing to the
same memory location. Here no copying is required.

The IN parameter is passes by reference, so we can't change the value of IN parameter inside the
module, It acts as a constant, But the OUT and IN OUT parameters are passed by value, we can change
the values of OUT & IN OUT parameters if you use the hint NOCOPY with OUT Parameter and IN OUT
Parameter then ::: call by reference

Answer Question
2 Users have rated as useful.

Login to rate this answer.


debjit20
Answered On : Apr 8th, 2010
View all answers by debjit20
When a parameter is passed as an IN variable, it is passed by reference. Since it will not change, PL/SQL
uses the passed variable in the procedure/function. When variables are passed in OUT or INOUT mode, a
new variable is define, and the value is copied to the passed variable when the procedure ends. If the
variable is a large structure such as a PL/SQL table or an array, the application could see a performance
degradation cause by copying this structure. The NOCOPY clause tells to PL/SQL engine to pass the
variable by reference, thus avoiding the cost of copying the variable at the end of the procedure. The
PL/SQL engine has requirements that must be met before passing the variable by reference and if those
requirements are not met, the NOCOPY clause will simply be ignored by the PL/SQL engine.
Answer Question

Login to rate this answer.


ptmich
Answered On : Feb 28th, 2012
View all answers by ptmich

sipsin: Actually the reverse is true. Usually the IN parameter is passed by reference and the OUT/IN OUT
parameters are passed by value.
Answer Question

Login to rate this answer.


Saket
Answered On : Apr 3rd, 2012
Pass by reference: "IN" Case
Pass by value : "Out" or "IN OUT" Case which have the overhead of copying the value to new procedure
parameter.
In order to make to Pass by reference we will use NOCOPY
Pass by reference: "OUT NOCOPY" or "IN OUT NOCOPY" which deals which the actual reference value.
Answer Question

Login to rate this answer.


Himansu
Answered On : Nov 6th, 2012
In procedure,Function there are three types of parameter is there. eg-IN, OUT, INOUT.
IN parameter is call by reference and OUT & INOUT are call by value. Always call by reference is faster
than call by value. We use NOCOPY to convert call by value to call by reference.

Actually it is more useful when we are passing a large record or a large table.
Answer Question

State the difference between implict and explict cursor's


Asked by: Interview Candidate | Asked on: Jul 25th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 10 of 10 Answers


D. Madhusudhana Rao ( 9885626575)
Answered On : Jul 25th, 2006
Implicit Cursor are declared and used by the oracle internally. whereas the explicit cursors are declared
and used by the user. more over implicitly cursors are no need to declare oracle creates and process and
closes autometically. the explicit cursor should be declared and closed by the user.
Answer Question
3 Users have rated as useful.

Login to rate this answer.


senthil
Answered On : Jul 26th, 2006

Any other differences


Answer Question

Login to rate this answer.


Suresh
Answered On : Jul 28th, 2006

More over Explicit Cursors were used to retrieve values from two or more rows.
Answer Question
1 User has rated as useful.

Login to rate this answer.


gouthami kodangal
Answered On : Aug 13th, 2006

implicit cursors are definfined by the oracle server whenever the operations are on single row where as
for operations on mutiple rows the programmer declare cursors explisitly.
Answer Question

Login to rate this answer.


SP
Answered On : Feb 9th, 2007

Every Select statement is an implicit cursor. As others have said, you do not need to worry about how the
rows are managed. In explicit cursors you can do further work while looping. There is a better chance
that the Explicit cursor statement is cached to a better extent that the implicit cursor statement, therefore
the more times you run it (the explicit cursor) the better the performance gets.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 4th, 2008
Implicit cursors are faster and result in much neater code so there are very few cases where you
need to resort to explicit cursors.

Implicit cursors are declared by PL/SQL implicitly for all DML and PL/SQL SELECT
statements, including queries that return only one row. Explicit cursors for queries that return
more than one row, explicit cursors are declared and named by the programmer and manipulated
through specific statements in the block’s executable actions.
Answer Question
1 User has rated as useful.

Login to rate this answer.


satyam_Ora
Answered On : May 8th, 2008
View all questions by satyam_Ora View all answers by satyam_Ora

PL/SQL uses two types of cursors: implicit and explicit. PL/SQL declares a cursor implicitly for all SQL
data manipulation statements, including queries that return only one row. However, for queries that
return more than one row, you must declare an explicit cursor, use a cursor FOR loop, or use
theBULK COLLECT clause.

Answer Question

Login to rate this answer.


KSPRADEEEP
Answered On : Oct 17th, 2012
Cursors are two types (1) Implicit cursor and (2) Explicit cursor
Implicit cursors are Oracle predefined cursors. It will automatically open,fetch and close the cursor
respectively.It will returns only one record at a time. If you want return more than one record it will raise
error .Too_many_rows.

Explicit cursors are user-defined cursors.If we use explicit cursor user need to open,fetch and close the
cursor by using explicit cursor we can return more than one records..

The main difference between Implicit and Explicit cursors is by using implicit we can execute only record
where as Explicit returns more than one records. implicit cursor is do open the cursor and fetching data
and closing cursor where as Explicit is User defined user needs open cursor and fetching data and close
the cursor.
Answer Question

Login to rate this answer.


VASU
Answered On : Oct 20th, 2012
Implicit cursors returns only single record..where as explicit cursor multiple records. But it process record
by record.
Answer Question

Login to rate this answer.


chiatanya
Answered On : Nov 5th, 2012
Implicit cursors are automatically generated,when a sql statement is processed where as

Explicit cursors are user defined.

Stored Procedure Vs Function


What is the impact of using a stored proc or a function on the performance? Which has abetter
performance ? Also, why is it not possible to use DML in the functions called from a select query?
Asked by: priyanka_sharma | Member Since Sep-2012 | Asked on: Sep 20th, 2012
View all questions by priyanka_sharma

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


Miguel
Answered On : Nov 2nd, 2012

A function is a store procedure indeed, and you can use autonomous transactions to do some DML
Answer Question

Login to rate this answer.

What is difference between a PROCEDURE & FUNCTION ?


A FUNCTION is always returns a value using the return statement. A PROCEDURE may return
one or more values through parameters or may not return at all.

Asked by: Interview Candidate | Asked on: Sep 2nd, 2005

 First

 Previous

 Next
 Last

Return back to PL/SQL

Answer Question

Editorial / Best Answer


Answered by: krishnaindia2007
View all answers by krishnaindia2007

Member Since Sep-2007 | Answered On : May 3rd, 2008

1. Function is mainly used in the case where it must return a value. Where as a procedure may or may
not return a value or may return more than one value using the OUT parameter.
Â
2. Function can be called from SQL statements where as procedure can not be called from the sql
statements

3. Functions are normally used for computations where as procedures are normally used for executing
business logic.

4. You can have DML (insert,update, delete) statements in a function. But, you cannot call such a function
in a SQL query.

5. Function returns 1 value only. Procedure can return multiple values (max 1024).

6.Stored Procedure: supports deferred name resolution. Example while writing a stored procedure that
uses table named tabl1 and tabl2 etc..but actually not exists in database is allowed only in during creation
but runtime throws error Function wont support deferred name resolution.

7.Stored procedure returns always integer value by default zero. where as function return type could be
scalar or table or table values

8. Stored procedure is precompiled execution plan where as functions are not.


Â
9.A procedure may modify an object where a function can only return a value The RETURN statement
immediately completes the execution of a subprogram and returns control to the caller.
Showing Answers 1 - 38 of 38 Answers

Taral Desai

Answered On : Sep 2nd, 2005

functions can be useed in select or update or delete statement while procedure can't.
Answer Question
Login to rate this answer.

Sunil Yadav

Answered On : Oct 19th, 2005

A Function can be used in the Sql Queries while a procedure can not be used in sql queries .that cause a
major difference b/w function and procedures .
Answer Question

1 User has rated as useful.

Login to rate this answer.

promila

Answered On : Nov 10th, 2005

View all answers by promila

We can use DDL in Procedure using Execute Immediate statement while tht is not possible in functions
Answer Question

Login to rate this answer.

Zafar Imam Khan

Answered On : Nov 11th, 2005


A function always return a values while procedure can return one or more values through Parameters.
A function can call directly by sql statement like select "func_name" from dual while procedure cannot.
Answer Question

Login to rate this answer.

marisamy

Answered On : Dec 2nd, 2005

Dml statement cannot be used in function,but it used in procedure.


Answer Question

Login to rate this answer.

Haripriya
Answered On : Dec 23rd, 2005

A function returns a value where as a proceedure does not return a value


Answer Question

Login to rate this answer.

prem123

Answered On : Mar 8th, 2006

View all questions by prem123 View all answers by prem123

procedure can call in another project but function work in same project .
Answer Question

Login to rate this answer.

aseemnaithani

Answered On : Mar 15th, 2006

View all questions by aseemnaithani View all answers by aseemnaithani

We can't have any DDL,DML and TLC command inside a function, if that function is called from
aquery.But if the function is not called from query then we can have all transactional statement(DDL,DML
and TLC ) inside a function.
Answer Question

Login to rate this answer.

jaidev_ncc

Answered On : Mar 17th, 2006

View all answers by jaidev_ncc

function can return a single values at maximum, where as in case if procedure returns one or more than
one value and might not return a even a single value........
Answer Question

Login to rate this answer.

prafull.vn
Answered On : Mar 19th, 2006

View all questions by prafull.vn View all answers by prafull.vn

Moral of the story is that,


Functions can be part of any valid Pl/SQL Expression but
Procs cannot be .. We need to call procs standalone...:)
Answer Question

Login to rate this answer.

Deepika S Verma

Answered On : Mar 31st, 2006

The Main Difference Between function and procedure is


[1] function return value whereas procedure can return one , more than one or no value
[2] the other difference which is a advantage of function over procedure is
function can be called in a SQL statement as a UDF(user defined function) but procedure cannot
Also You can use DDL statements in functions & procedure by using execute_immediate package in latest
version and for parse_sql packaege in old oracle version. So regarding using of DDL or DML statments in
function or procedure , there is no difference in that context
Answer Question

1 User has rated as useful.

Login to rate this answer.

Vikas Rathore

Answered On : Apr 13th, 2006

you can use DDL stmt inside function.


Answer Question

Login to rate this answer.

Krishna Gupta

Answered On : Aug 24th, 2006

1. A function return single value through return statement but procedure can return one or more than
one values through parameter.
2. function use through select statement while procedure can not.
Answer Question

Login to rate this answer.

Rajasekar

Answered On : Sep 29th, 2006

Functions are basically pre-compiled, but procedures are not. Thats why we are able to call functions
from select statement but not procedure. In that case, functions are fater than proceduers. Please correct
me if i am wrong.
Answer Question

Login to rate this answer.

kiran

Answered On : Oct 17th, 2006

A Function can return a single value using return statement, whereas a Procedure cannot return using
return statement but can return using parameters, i.e., a procedure can return one or more values.A
Function can be called inside the select statement, whereas the Procedures cannot called inside the select
statement,procedures are standalone.
Answer Question

Login to rate this answer.

Muhammad Asif Siddiqui

Answered On : Nov 30th, 2006

A can not be executed or exist as a standalone entity while PROCEDURE hasn't got any of such
limitations. A PROCEDURE can contian one or more FUNCTION.
Answer Question

Login to rate this answer.

gautam

Answered On : Dec 13th, 2006

Function can create and return a table where as procedure can not return a table
Answer Question

Login to rate this answer.

Rajesh

Answered On : Feb 19th, 2007

function and procedure both return value But fuction return onlyfor caller. PROCEDURE returns for all of
them.
Answer Question

Login to rate this answer.

Sujaatha

Answered On : Feb 26th, 2007

Both are nothing but set of statement which will perform some operations... More over both are same...in
C we call it as functions.. in Pascal & COBOL..we call it as procedures..But the d/f b/w this two is function
will return a value to call function...but procedure wont return any value to call function....
Answer Question

Login to rate this answer.

think

Answered On : Apr 4th, 2007

both are precompiled but act differently like for exe: functions can be called at any point of queries but u
cant do the same with procedure and so on
Answer Question

Login to rate this answer.

abhi

Answered On : May 2nd, 2007


Procedures are stored in precompiled form and hence are faster than function

Function occupies less memory space as compared to procedure.


We cant use DDL, DML, TCL statements within a fuction if it is called by some SQL query or if it is used in
some SQL query.

Fuctions are used to return a value whileprocedures are used to performa task.

Functions can have out parameter which can take the return type
Answer Question

Login to rate this answer.

prabhat saxena

Answered On : Jun 15th, 2007

By default function are return type where as procedure can't


Function support the select statement where as procedure can't
Procedure support DML, DDL where as function can't
Answer Question

Login to rate this answer.

narendra

Answered On : Jul 11th, 2007


Hi Rajasekhar,
What you are saying is wrong. Both functions and prcodures are pre complied statements. Even we can
call a procedure or function in any package body if they are declared properly.
Answer Question

Login to rate this answer.

Srinivasa Reddy

Answered On : Jul 17th, 2007


Procedure take in, out, inout parameters,
Function accept only in parameter only.
Toexecute procedures parameters required
Toexecute functions parameter optional
Answer Question
Login to rate this answer.

sureshbala

Answered On : Aug 14th, 2007

View all answers by sureshbala

The following solutions are possible

1) A function should return a value as default. whereas a procedure may or may not return a value in
demand.
2) Functions can be integrated in a SQL select statement. But it cannot be applied to procedures.
3) A function can becalled inside a procedure whereas the vice versa is not applicable.
Answer Question

Login to rate this answer.

madhu

Answered On : Oct 31st, 2007

Hi We can use execute immediate in the function also


Answer Question

Login to rate this answer.

Vijay Jadhav

Answered On : Nov 26th, 2007

Function should return atlestsingle value (it is a barden), wherePROCEDURE is not.


Answer Question

Login to rate this answer.

malik.aman

Answered On : Dec 4th, 2007

View all answers by malik.aman

Function can return at most one value at a time while procedure can return more than one value at a
time You can use function within Sql Statement and you cannot use stored procedure with in Sql
Statement
Answer Question

Login to rate this answer.

g_sidhu

Answered On : Jan 31st, 2008


Procedures:

Execute as a PL/SQL statement


Do not contain RETURN clause in the header
Can return none, one, or many values
Can contain a RETURN statement

Functions:

Invoke as part of an expression


Must contain a RETURN clause in the header
Must return a single value
Must contain at least one RETURN statement
Answer Question

Login to rate this answer.

krishnaindia2007

Answered On : May 3rd, 2008

View all answers by krishnaindia2007

1. Function is mainly used in the case where it must return a value. Where as a procedure may or may
not return a value or may return more than one value using the OUT parameter.

2. Function can be called from SQL statements where as procedure can not be called from the sql
statements

3. Functions are normally used for computations where as procedures are normally used for executing
business logic.

4. You can have DML (insert,update, delete) statements in a function. But, you cannot call such a
function in a SQL query.

5.Function returns 1 value only. Procedure can return multiple values (max 1024).

6.Stored Procedure: supports deferred name resolution. Example while writing a stored procedure that
uses table named tabl1 and tabl2 etc..but actually not exists in database is allowed only in during
creation but runtime throws error Function wont support deferred name resolution.
7.Stored procedure returns always integer value by default zero. where as function return type could be
scalar or table or table values

8. Stored procedure is precompiled execution plan where as functions are not.

9.A procedure may modify an object where a function can only return a value The RETURN statement
immediately completes the execution of a subprogram and returns control to the caller.
Answer Question

1 User has rated as useful.

Login to rate this answer.

vinothkumar.g

Answered On : Sep 30th, 2011


one most important diff is
-> In procedure exception handle is mandatory but in function Exception handling is not mandatory.
Answer Question

Login to rate this answer.

MANIKANDAN

Answered On : Dec 21st, 2011


1. Procedure and function both used to perform some mathematical and business calculation.

2. Procedure may return one or more values(max 1024) through parameter but function must return only
one values through return statements.

3. Function can use DDL and DML SQL statements, But procedure used for calculation and updation
operation.
Answer Question

Login to rate this answer.

Susil Kumar Nagarajan

Answered On : Jan 20th, 2012


1. A function is expected to return values and can be assigned to a variable

Example : substr() is a string function which is expected to return a value


Can be assigned to a variable:
var1 := substr(Susil Kumar,1,5);

Procedure cannot be assigned to a variable.

2. A function can be called inside a procedure. Reverse is not possible unless you use Execute Immediate
to generate dynamic code which is executed during runtime.

3. Global variables can only be declared in Pacakage

4. If you want to do overloading of functions or procedures, you should seal them in a package. If not,
you cannot overload functions or procedures

5. Though functions allow insert statements in it, it throws error when you use the function in select
statement. Procedure goes good with Insert statements.
Answer Question

Login to rate this answer.

jagat

Answered On : May 28th, 2012


The Main Difference Between function and procedure is

[1] function return value whereas procedure can return one , more than one or no value

[2] the other difference which is a advantage of function over procedure is

function can be called in a SQL statement , but procedure cannot

Also You can use DDL statements in functions & procedure by using execute_immediate package in latest
version and for parse_sql package in old oracle version. So regarding using of DDL or DML statements in
function or procedure , there is no difference in that context

Dropping a type in Oracle


Can a type body be dropped without dropping the type specification?
Asked by: sidd_130 | Member Since Oct-2012 | Asked on: Oct 6th, 2012
View all questions by sidd_130

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


ramya
Answered On : Oct 31st, 2012

When you drop a type body, the object type specification still exists, and you can re-create the type
body. Prior to re-creating the body, you can still use the object type, although you cannot call the
member functions.

Oracle locks
With what ways can we find out instance locks?
Asked by: sidd_130 | Member Since Oct-2012 | Asked on: Oct 6th, 2012
View all questions by sidd_130

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


Jose George
Answered On : Oct 22nd, 2012

v$lock contains details of locks


difference between truncate and delete
Asked by: Interview Candidate | Asked on: Jun 9th, 2006

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 11 of 11 Answers


Nagabhushan S N
Answered On : Jun 9th, 2006

TRUNCATE
It's a DDL command and delete the complate table data and no rollback possible.It also resets the HIGH
WATERMARK which will imporve subsequent query performance.
DELETE
This is DML statement and require commit to make changes permanant.Can be used to delete selective
rows from table.Does not reset the High Watermark of the table.
Answer Question
1 User has rated as useful.

Login to rate this answer.


pankaj_gauba
Answered On : Jun 22nd, 2006
View all questions by pankaj_gauba View all answers by pankaj_gauba

Nagabhushan S N is right.
Answer Question

Login to rate this answer.


Vithal Patil
Answered On : Jun 23rd, 2006

TRUNCATE
It is possible to Delete data permanantly from the table without commit.
After deletion don't have rollback option.
DELETE
Require commit to make changes permanantly after delete command.
and also u can select particular row to delete with where conditions.
here after deletion have rollback option
Answer Question
Login to rate this answer.
D.Madhu
Answered On : Jun 29th, 2006
Delete

With Rollback Facility

DML Operation.

No Auto Commit.

Truncate

Without Rollback Facility

DDL Operation

Auto Commit
Answer Question

Login to rate this answer.


harshali patil
Answered On : Jun 1st, 2007
Truncate:
truncate require no commit
Delete:
delete require commit
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
1. Delete creates a rollback segment and cane be rollback. It is DML statement. Truncate is a DDL
statement and can not be rollback.

2. Delete command deletes records one by one where as truncte removes all the records at a time.

3. Truncate does not allow conditional remove of records where as delete allows conditional remove of
records

4.Trigger fires on delete statement where as trigger do not fires on truncate statement.
Answer Question
1 User has rated as useful.

Login to rate this answer.


cajie
Answered On : Oct 26th, 2009
View all answers by cajie

More difference are as below:

1) TRUNCATE fires 2 COMMIT before firing and after deleting the rows. The COMMIT fired before,
commits all the open uncommitted transactions.

2) TRUNCATE does not write into redo/undo logs which makes it faster than DELETE.

Correct me if I am wrong.

Cajie
Answer Question

Login to rate this answer.


geek.hari
Answered On : Dec 28th, 2009
View all answers by geek.hari
Delete will need an explicit commit or rollback to end the transaction. It will perform a redo log entry.
Truncate has inherent commit in it. It will not perform any redolog entry.
Answer Question

Login to rate this answer.


Gourvendra Singh
Answered On : Oct 9th, 2012
Major Differences are:
Delete: Delete command will delete either full table records or make a conditional deletion on the table.
Truncate: It will delete all the records of the table.
Delete: Delete will write the records in redo log buffer before deleting the records and erase the entry
from the redo log buffer once the transaction is committed or rollback.
Truncate: Truncate will delete the records directly from the table and records cannot be rollbacked. This
is why truncate runs faster then delete.
Truncate: It will reset the watermark of the table.
Answer Question

Login to rate this answer.


jose george
Answered On : Oct 15th, 2012
in addition to others

truncate is DDL hence would implicitly commit before executing


Delete is DML
truncate resets the High water mark
delete does not reset the high water mark

Answer Question

Login to rate this answer.


VASU
Answered On : Oct 20th, 2012
By using delete we have to delete particular records only..
If we use truncate we cannot retrieve the data permanently...

What is a cursor for loop ?


Cursor for loop implicitly declares %ROWTYPE as loop index,opens a cursor, fetches rows of values
from active set into fields in the record and closeswhen all the records have been processed. eg. FOR
emp_rec IN C1 LOOP salary_total := salary_total +emp_rec sal; END LOOP;
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


kishorebabukm
Answered On : Sep 20th, 2005
The for loop in cursors are used to make less statements to write cursor.
if u are opening a cursor normally using the open cursor ,then
open cursor_name;
fetch cursor_name into variable loop
exit when cursor_name%notfound ;
end loop;
close cursor
in the above statement u have to explicitly open and close the cursor, and also write exit statement to
end the cursor loop
if we write the same using for loop then compare the statements.
for varible in cursor_name loop
statements
end loop;
the above for loop does not need a open and close explicitly since those are involved in the for loop itself.
and also never require the loop to explicitly end using any condition, since it ends the loop if there are no
more rows in the memory.
Answer Question
1 User has rated as useful.

Login to rate this answer.


rashid
Answered On : Sep 20th, 2006

cursor for loop is use for automatically open ,fetch,close


Answer Question

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
A cursor FOR loop processes rows in an explicit cursor. It is a shortcut because the cursor is
opened, rows are fetched once for each iteration in the loop, the loop exits when the last row is
processed, and the cursor is closed automatically. The loop itself is terminated automatically at
the end of the iteration where the last row is fetched.
The record is implicitly declared.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007

Cursor for loop implicitly declares a loop index as %rowtype. It uses result of query to determine
dynamically no of times the loop is to be repeated. It performs open, fectch , close operations implicitly.
Answer Question
1 User has rated as useful.

Login to rate this answer.


sk.mca6
Answered On : Feb 17th, 2011
View all questions by sk.mca6 View all answers by sk.mca6
>By using cursor for loops we can improve performance of the application .
>it avoids explict cursor life cycle(open,fetch,close).
>in cursor for loop the index variable behaves like a record type variable..which is auto initialized.
>we can also use select stmt in place of cursorname
ex:
for i in (select * from emp) --inline _cursor style
loop -- i record type variable..emp%rowtype
......
end loop;
but here we cant controle the loop explicitely.
Answer Question
Login to rate this answer.
PRADEEP
Answered On : Oct 17th, 2012
If we use explicit cursor we need to open the cursor and fetching the data and close the cursor.

If we use cursor for loop cursor will open the cursor and fetching data and close the cursor automatically.
Answer Question

Login to rate this answer.


vasu
Answered On : Oct 20th, 2012

Cursor for loop is the one by using this we need not to perform open, close, fetch operations of a cursor..
Answer Question

Login to rate this answer.


Populating Tables in Oracle 11g
How do you populate tables or data in Oracle 11g step by step?
Asked by: Interview Candidate | Asked on: Nov 9th, 2011

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


oracle2066
Answered On : Dec 28th, 2011
View all answers by oracle2066
You can can populate table B by joining from table A

Create table b as select from table A.


Or
dpimp
or
Rolling upgrades.

Answer Question
Login to rate this answer.
Jose George
Answered On : Oct 16th, 2012
Depending on the situation one can use
external tables
or
UTL_FILE package
Answer Question

Login to rate this answer.


Jose George
Answered On : Oct 17th, 2012

We can use SQL Loader too


Answer Question

What is a database trigger ? Name some usages of database trigger ?


Database trigger is stored PL/SQL program unit associated with a specific database table. Usages
are Audit data modifications, Log events transparently, Enforce complex business rules Derive
column values automatically, Implement complex security authorizations. Maintain replicate tables.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


tm1966_muthu
Answered On : Feb 17th, 2006
View all answers by tm1966_muthu
A database trigger is a stored procedure that is invoked automatically when a predefined event occurs.
Database triggers enable DBA's (Data Base Administrators) to create additional relationships between
separate databases.
For example, the modification of a record in one database could trigger the modification of a record in a
second database.
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
A database trigger is a named pl/sql block associated with a table and fires automatically when an event
occurs or something happens.

Data auditing , Implementing complex business rules, security are main uses of database triggers.
Answer Question
3 Users have rated as useful.

Login to rate this answer.


KSPRADEEP
Answered On : Oct 17th, 2012
Trigger is data base object .Trigger is block of code it is executed automatically when dml operations are
fired .

by using trigger we can do the auditing and perform a operation(modifications) on a tables (using dml
operation)
Answer Question

Login to rate this answer.


What are the modes of parameters that can be passed to a procedure ?
IN,OUT,IN-OUT parameters.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


rajjava
Answered On : Sep 15th, 2005
View all questions by rajjava View all answers by rajjava

1.in:
in parameter mode is used to pass values to subprogram when invoked.
2.out:
out is used to return values to callers of subprograms
3.in out:
it is used to define in and out
Answer Question

Login to rate this answer.


Bonthu
Answered On : Feb 11th, 2006

1> IN
2> OUT
3>INOUT.
Cheers,
Bonthu
Answer Question

Login to rate this answer.


Santanu Maity
Answered On : Jun 14th, 2006
IN value pass by reference
Out value pass by value
INOUT value pass by value
Answer Question

Login to rate this answer.


bavani
Answered On : Oct 23rd, 2006

in - pass by value like constant values


out - uninitialized variable
inout -initialized variable
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008

IN (default): Passes a constant value from the calling environment into the procedure
OUT :Passes a value from the procedure to the calling
environment
IN OUT :Passes a value from the calling environment into the procedure and a
possibly different value from the procedure back to the calling environment
using the same parameter
Answer Question
2 Users have rated as useful.

Login to rate this answer.


KSPRADEEP
Answered On : Oct 17th, 2012
Two modes of parameters are available to pass the parameter In and Out, the default parameter is IN.
In : Lets you pass a value to subprogram being called.It can not be changed inside the
parameter(Constant)
Out:Lets the subprogram pass a valu to caller in side the subprogram. out parameter is an uninitialized
variable.
How many number of triggers can be created on a table?
Asked by: Interview Candidate | Asked on: Mar 8th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 8 of 8 Answers


nilkanth
Answered On : Mar 8th, 2006

12 triggers max
Answer Question

Login to rate this answer.


Deepika S Verma
Answered On : Apr 1st, 2006

Till oracle 7.0 only 12 triggers could be associated with a given table, but in higher versions of Oracle
there is no such limitation.
Answer Question
1 User has rated as useful.

Login to rate this answer.


rajanipriya
Answered On : Jun 6th, 2006
View all questions by rajanipriya View all answers by rajanipriya

how can we have more that 12 trigger combinations.


Its only (update , delete, insert) ,( before , after) ,, row level and statemant level triggers. what pther
combinations are possible??
please suggest
Answer Question

Login to rate this answer.


sunil
Answered On : Jun 7th, 2006

Hi,
There is no limit on number of triggers on one table.
you can write as many u want for insert,update or delte by diff names.
Sunil.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Padma
Answered On : Oct 5th, 2006

if table has got n columns. we can create n triggers based on each column.
Answer Question

Login to rate this answer.


DEEPAK MAHAPATRA
Answered On : Sep 5th, 2007

Higher version of Oracle doesn't have any limitation of the number of trigger. Earlier 12 number of
triggers were fired per table.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
With Oracle 10g : any number of trigger can be written on a table.
With Oracle 9.0 or below� :� � max 12
Answer Question

Login to rate this answer.


KSPRADEEP
Answered On : Oct 17th, 2012
max 12 trigger can be created on a table.
Row level triggers and Statement level triggers
Before and After
Insert and Delete and Update
2*2*3=12
Answer Question

Login to rate this answer.


1) Why it is recommonded to use INOUT instead of OUT parameter type in a
procedure?

2) What happen if we will not assign anything in OUT parameter type in a


procedure?
Asked by: Interview Candidate | Asked on: May 19th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Narender Reddy
Answered On : May 19th, 2006

Hi,OUT parameter will be useful for returning the value from subprogram, value can be assigned only
once and this variable cannot be assigned to another variable.IN OUT parameter will be used to pass the
value to subprogram and as well as it can be used to return the value to caller of subprogram. It acts as
explicitly declared variable. Therefore it can be assigned value and its value can be assigned to another
variable.So IN OUT will be useful than OUT parameter.
Answer Question

Login to rate this answer.


Arun Arumugam
Answered On : Jul 1st, 2006

1) IN OUT and OUT selection criteria depends upon the program need.if u want to retain the value that is
being passed then use seperate (IN and OUT)otherwise u can go for IN OUT.2)If nothing is assigned to a
out parameter in a procedure then NULL will be returned for that parameter.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
1.There is no hard and fast rule about this. Whether to use INOUT or OUT depends upon the situation.

2. If not assigned anything to OUT parameter it retuns NULL value.


Answer Question
2 Users have rated as useful.

Login to rate this answer.


KSPRDEEP
Answered On : Oct 17th, 2012
In parameter means it will insert the values
OUT parameters means it will print out put (pass values to output). If we not assigning any value to out
parameter it will take (print) NULL value.

INOUT means it take values as input and out put


How to avoid using cursors? What to use instead of cursor and in what cases to
do so?
Asked by: moviefan456 | Member Since Aug-2006 | Asked on: Aug 9th, 2006
View all questions by moviefan456

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


oranachs
Answered On : Aug 17th, 2006
View all questions by oranachs View all answers by oranachs

hai
just use subquery in for clause
ex:
for emprec in (select * from emp)
loop
dbms_output.put_line(emprec.empno);
end loop;
no exit statement needed
implicit open,fetch,close occurs
try this and send me the reply on ora.nachs@yahoo.com
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Venkat
Answered On : Sep 21st, 2006

I think the answer is:


If your select statement retruns only one value, you can avoid using cursor:
for instance:
select fname into v_fname
from emp where empno = 10;
(here assueme that the empno is PK)
in your procedure or package or function you can declare the variable v_fname and directly use the
abovesql statement instead of declaring a cursor,opening, ...
Thanks.
Venkat
Answer Question

Login to rate this answer.


Venkat9999
Answered On : Sep 21st, 2006

I think the answer is:


If your select statement retruns only one value, you can avoid using cursor:
for instance:
select fname into v_fname
from emp where empno = 10;
(here assueme that the empno is PK)
in your procedure or package or function you can declare the variable v_fname
and directly use the above sql statement instead of declaring a cursor,opening,
...
Venkat
Answer Question

Login to rate this answer.


Jagadish V
Answered On : Nov 24th, 2006
if you need to perform manipulations from the output of the select statement which results multiple rows
,the cursor need to be used.
Answer Question

Login to rate this answer.


Tanveer Islam Siddiqui
Answered On : Nov 24th, 2006

U have 2 options to do it..


1st) Use Pl/SQL Table...
2nd) Create Temporary Table and use it in place of Table...
Answer Question

Login to rate this answer.


Thulasidas
Answered On : Nov 26th, 2006

Well there may be several ways for not to use a cursor. But a good programming practice suggests the
use of cursors as much as possible for performance and efficiency purpose.
Answer Question

Login to rate this answer.


srinivas
Answered On : Nov 29th, 2006

insted of using cursor we will use attribute data types %type and %rowtype to load data in pl/sql
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 8th, 2008
View all answers by krishnaindia2007

You can use bulk binding to avoid cursors. It improves performance by minimizing context switches sql
and pl/sql. When you are hadling large volume of data then better to use bulk binding.
Answer Question
1 User has rated as useful.

Login to rate this answer.


KSPRADEEP
Answered On : Oct 17th, 2012
Yes we can ..
Instead of cursor we using bulk collection or bulk binding or using %type and %rowtype
what is a cluster and what is the real time use and business reasons to use
Clustering
Asked by: subbaraovangalli | Member Since Mar-2007 | Asked on: Apr 4th, 2007
View all questions by subbaraovangalli View all answers by subbaraovangalli

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


g_sidhu
Answered On : Feb 5th, 2008

Clustering is a method of storing tables that are intimately related and often joined together into the
same area on disk. For example, instead of the BOOKSHELF table being in one section of the disk and the
BOOKSHELF_AUTHOR table being somewhere else, their rows could be interleaved together in a single
area, called a cluster. The cluster key is the column or columns by which the tables are usually joined in a
query (for example, Title for the BOOKSHELF and
BOOKSHELF_AUTHOR tables).
Answer Question
1 User has rated as useful.

Login to rate this answer.


KSPRADEEP
Answered On : Oct 17th, 2012

Cluster are groups of one or more tables physically stores together to share common columns and are
often used together
What is the need of primary key as opposed to using not null and unique ?
we can create a column with' not null+unique' with out using primary key
Asked by: sreeraghava.nara | Member Since Jun-2008 | Asked on: Jun 16th, 2008
View all questions by sreeraghava.nara

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


stshekhar
Answered On : Jun 22nd, 2008
View all answers by stshekhar

One simple diff : there can only one primary key per table but not null+unique can be multiple on one
table.
Answer Question
3 Users have rated as useful.

Login to rate this answer.


KD09714
Answered On : Jul 1st, 2008
View all questions by KD09714 View all answers by KD09714
1) Primary key creates clustered index by default which actually reorders the row in a table based on
index while unique key creates non-clustered index.

2) Replication of table possible only if it contains primary key.


Answer Question
4 Users have rated as useful.

Login to rate this answer.


KD09714
Answered On : Jul 1st, 2008
View all questions by KD09714 View all answers by KD09714
1) Primary key creates clustered index by default which actually reorders the row in a table based on
index while unique key creates non-clustered index.

2) Replication of table possible only if it contains primary key.


Answer Question
1 User has rated as useful.

Login to rate this answer.


ashu.gupta
Answered On : Jul 2nd, 2009
View all answers by ashu.gupta
Along with the answers mentioned above

To add cascading is only possible when it follow primary key - foriegn key constraint.
Answer Question

Login to rate this answer.


Radha
Answered On : Jul 14th, 2011
We can create NOTNULL and UNIQUE constraints on single column. Which indirectly means a Primary
Key.
But only a Primary Key column can be used as Foreign key column.

Primary key provides a default index in it. But we don't have this advantages on the column which we
have NOTNULL and Unique Key instead of Primary Key.
Answer Question

Login to rate this answer.


PRADEEP
Answered On : Oct 17th, 2012
Primary key: set of columns is uniquely identified a rows of a table.

It does not allow both nulls and duplicate values.

If we use null values it will allow duplicate values but it does not allow null values.

If we use unique key it does not allow duplicate value but it allows null values.

The main difference is if we use primary key it does not allow both null and duplicate values.
What are % TYPE and % ROWTYPE ? What are the advantages of using these
over datatypes?
% TYPE provides the data type of a variable or a database column to that variable. % ROWTYPE
provides the record type that represents a entire row of a table or view or columns selected in the
cursor. The advantages are : I. Need not know about variable's data typeii. If the database definition
of a column in a table changes, the data type of a variable changes accordingly.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 13 of 13 Answers


StoneColdSteveAustin
Answered On : Oct 10th, 2005
View all answers by StoneColdSteveAustin
eg:
ename employees.emp_id%type;
here ename is the variable to be declared.
employees is the table name
emp_id is the column for that table.
%type indicates to assign the datatype of emp_id column in employees table for the ename variable.
Answer Question

Login to rate this answer.


Sebastian Thomas
Answered On : Jan 18th, 2006

Advantage is, if one change the type or size of the column in the table, it will be reflected in our program
unit without making any change.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Lavanya Chowdary
Answered On : May 6th, 2007
View all answers by Lavanya Chowdary

%type is used to refer the column's datatype where as %rowtype is used to refer the whole record in a
table.
Answer Question
1 User has rated as useful.

Login to rate this answer.


satish.m.v
Answered On : May 21st, 2007
View all answers by satish.m.v
%Type is defined as a difination for a perticular columm, It is a scalar type.

EX:
V_EMPNOEMP.EMPNO%Type;
Where as

%ROW TYPE is a defination for a table or it is a composite type.

Ex:
V_EMP EMP.%ROWTYPE.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Yestha Bapna
Answered On : Aug 14th, 2007
%TYPE can be used with the column name preceded with table name to decide the datatype and length
of the variable at runtime. In this case there is no dependency on changes made to the data structure.

%ROWTYPE can be used to declare the variable having the same no. of variables inside it (ROWTYPE) as
no. of columns there in the table. In this case columns selected with SELECT statement must match with
variables inside the rowtype variable. If not then induvidually refer these variables inside the ROWTYPE
variables
Answer Question
1 User has rated as useful.

Login to rate this answer.


sunilbidgar
Answered On : Apr 18th, 2008
View all answers by sunilbidgar
%Type - With %Type attribute we can inherit the datatype of another variable or an attribute of table
into currently declared variable.
eg.

declare
var1 production.invoice.itemno%type;

%Rowtype - With %rowtype attribute we can inherit the datatypes entire variable into a record varible
from another record variable or from all attributes of table into currently declared record variable.
eg.

declare
record1 production.invoice%rowtype;

here u can refer any attrbute as record1.itemno

Advantage is u need not to change the pl/sql code even if table attribute changes.
u need not to remember detail datatypes of table while coding pl/sql
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007

%TYPE is used to declare a variable with the same type as that of a database table column.%ROWTYPE
is used to declare a record as same type found in database table.These two provides data independence
and allows you to adopt database changes due to new business requirements.You need not know
datatype and size in advance.
Answer Question
1 User has rated as useful.

Login to rate this answer.


ajayraj
Answered On : Dec 15th, 2010
View all answers by ajayraj
% TYPE is used to define a varibale as same data type of the column of associated table.
%ROWTYPE provides a record type that represents a row in database table.

The benefit of %TYPE and %ROWTYPE is when u are fetching the data from a table in procedure and
after that data type of column or size is changed then no need to modify the procedure.
Answer Question

Login to rate this answer.


nirmal1in
Answered On : Dec 25th, 2010
View all questions by nirmal1in View all answers by nirmal1in
The %TYPE is used to define the varible of particular type for column exist on the table.
The %ROWTYPE is used to define variable of row type of table.

- It is good practice to use %TYPE and %ROWTYPE instead of defining varible of simple type. In case of
any change in the data type of columns and no need to make any changes to code.
- %ROWTYPE can be used to fetch complete row instead ofdefining varible for each field to hold the data
while processing.

Answer Question

Login to rate this answer.


Jitendra
Answered On : Feb 28th, 2012
ename variable will create with the data type of emp_id column of the employees table

for eg. if emp_id is of numeric type than ename should be numeric.


Answer Question

Login to rate this answer.


Kishore.Dondla
Answered On : Jun 29th, 2012

We Can USE These Data Types in Stored Procedures ,function and Packages as IN Parameter.
Answer Question

Login to rate this answer.


Yaseen
Answered On : Aug 9th, 2012

if using %type and %rowtype , no need to know the the data type of the table column . and once the
development is finished , the type of column is changed it will not effect the coding.
Answer Question

Login to rate this answer.


PRADEEP
Answered On : Oct 16th, 2012
%rowtype is associated entire table(if we want to declare all columns then we need to declare
%rowtype).

%type is associated with one column .(if we want to declare entire column then we need to declare
%type).
explian rowid,rownum?what are the psoducolumns we have?
Asked by: Interview Candidate | Asked on: Jul 28th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 12 of 12 Answers


krish
Answered On : Jul 28th, 2006

ROWID - Hexa decimal number each and every row having unique.Used in searching
ROWNUM - It is a integer number also unique for sorting Normally TOP N Analysys.
Other Psudo Column are
NEXTVAL,CURRVAL Of sequence are some exampls
askrish@hotmail.com
Answer Question
3 Users have rated as useful.

Login to rate this answer.


D. Madhusudhana Rao ( 9885626575)
Answered On : Aug 1st, 2006

psoducolumn in the sence which is not created by the user explicitly but user can use those things
explicityly.
examples
rowid,rowno,currval,nextval,sysdate,uid,level.
RowID: While storing in the database oracle generates one id for each row.
you can call based upon the rowid .ex: select * from emp where rowid=....
RowNo : This no is also generated by oracle itself. but you cant call based upon this one in select clause
Answer Question

Login to rate this answer.


Sphurti
Answered On : Aug 14th, 2006

I would like to add one more point here ,


Rowid is permanent for the life time whereas rownum is not. What i mean is till the time the record is
present in the table, the value of ROWID of a particular row in a table will always be same whereas the
value of ROWNUM will vary.
Answer Question

Login to rate this answer.


Gyaneshwar VC
Answered On : Sep 4th, 2006

Even ROWID is also not permanent for life time.Because If one exports and imports the table data then
ROWID changes.
Answer Question
1 User has rated as useful.

Login to rate this answer.


sunflower
Answered On : Feb 22nd, 2007
Rowid is a unique identifier, when a row is inserted into the table it generates a row id and will be
removed when the row is deleted.

For each row returned by the query a Rownum, pseudocolumn is returned in which order oracle selects
the rows from the table. Using rownum one can even limit the number of rows selected from the table.

Ex: select * from emp where rownum<10;


Answer Question
1 User has rated as useful.

Login to rate this answer.


askvenki
Answered On : Jul 19th, 2007
View all answers by askvenki
rowid is hexadecimal format which is parmently stored with row
rownum while retreivng data oracle attach row num for each row
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 4th, 2008
Row id: Hexadecimal string representing the unique address of a row in its table. This datatype
is primarily for values returned by the ROWID pseudocolumn.
Rownum: For each row returned by a query, the ROWNUM pseudocolumn returns a number
indicating the order in which Oracle selects the row from a table or set of joined rows. The first
row selected has a ROWNUM of 1, the second has 2, and so on. You can use ROWNUM to limit
the number of rows returned by a query, as in this example:
SELECT * FROM employees WHERE ROWNUM < 10;

A pseudocolumn behaves like a table column, but is not actually stored in the table. You can
select from pseudocolumns, but you cannot insert, update, or delete their values. This section
describes these pseudocolumns:
- CURRVAL and NEXTVAL
- LEVEL
- ROWID
- ROWNUM
Answer Question
3 Users have rated as useful.

Login to rate this answer.


johnjerry
Answered On : Oct 9th, 2009
View all answers by johnjerry
My 2 cents:
Rowid contains hexa-decimal number

 bits 1 to 32 (bytes 1 to 4): data object id (0-4294967295)


 bits 33 to 44 (byte 5 and half byte 6): file number inside the tablespace (0-4095) - file id
 bits 45 to 64 (half byte 6 and bytes 7 and 8): block number inside the file (0-1048575) - block id
 bits 65 to 80 (bytes 9 and 10): row number inside the block (0-65535)
When printed, each field is displayed in radix 64 (A-Za-z0-9+/): OOOOOOFFFBBBBBBRRR
Answer Question

Login to rate this answer.


Radha
Answered On : Jul 14th, 2011
Row ID: Code defined by the database for unique identification of each row. It is 18 alphabetical
characters in length.

Row NUM: A sequence number used to retrieve rows from the table.

Some other Pseudo columns are - Level, Rowscn, UID, User, Sysdate.
Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11
Pseudocolumn - a column that is not stored in a table, yet behaves like a table column.

ROWID - a global unique address for a row in a database.


ROWNUM
Returns a number indicating the order in which Oracle selects the row from a table or set of joined rows.
The first row selected has a ROWNUM of 1, the second has 2, and so on.

If using ORDER BY with ROWNUM then the rows will be reordered by the ORDER BY clause, means the
sequence of rows will be different. it is better to use ROW_NUMBER() analytic unction.

Example:
SELECT * FROM emp WHERE ROWNUM < 11 ORDER BY ename;

Fix:
SELECT * FROM (SELECT * FROM emp ORDER BY empno) WHERE ROWNUM < 11;

ROW_NUMBER() analytic function example:


SELECT * FROM ( SELECT deptno, ename, sal ,ROWNUM ,ROW_NUMBER() over (order by sal desc,
ename) as rno FROM emp ) --WHERE rno <= 4
/

Answer Question

Login to rate this answer.


Dilip
Answered On : Sep 3rd, 2012

Here I am providing all the psudo columns of Oracle ROWNUM, ROWID,NEXTVAL, CURRVAL, SYSDATE,
USER, LEVEL
Answer Question

Login to rate this answer.


PRADEEP
Answered On : Oct 16th, 2012
rowid is octal decimal values it is stored permanently in a oracle database. It will created while creating a
table.

rownum is also octal decimal number but it is for only specific time span it will arise after completed a
task.
Transaction management in triggers
Can we give COMMIT or ROLLBACK within a trigger?
Asked by: sidd_130 | Member Since Oct-2012 | Asked on: Oct 6th, 2012
View all questions by sidd_130

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


rashmi m
Answered On : Oct 10th, 2012

no triggers cannot use COMMIT and ROLLBACK . And the procedures and functions called by the triggers
also cannot use the COMMIT and ROLLBACK.
Answer Question

Login to rate this answer.


Arun
Answered On : Oct 16th, 2012
Although you cant give commit or rollback in trigger directly, still there are ways to give them
You can use the autonomus transactions to do that
Global temporary tables
What is a global temporary table?
Asked by: sidd_130 | Member Since Oct-2012 | Asked on: Oct 6th, 2012
View all questions by sidd_130

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


Aijaz
Answered On : Oct 14th, 2012
Global temporary tables are the permanently created tables for a timed session.
Only the data in the table is temporary but the table is permanent in the Oracle database .
Answer Question
Debugging PL/SQL programs
How can we debug stored procedures in PL/SQL?
Asked by: sidd_130 | Member Since Oct-2012 | Asked on: Oct 6th, 2012
View all questions by sidd_130

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


srikanth goduru
Answered On : Oct 10th, 2012

Using dbms_ouptput.put_line and logging different parts of the procedure.


Oracle Joins
There are 2 tables, A and B having 3 rows each. What will be result on executing the following query?
:SQL > select * from A,B
Asked by: sidd_130 | Member Since Oct-2012 | Asked on: Oct 6th, 2012
View all questions by sidd_130

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


srikanth goduru
Answered On : Oct 10th, 2012

A Cartesian product is the result of an unrestricted join of two or more tables. The result set of a three
table Cartesian product will have x * y * z number of rows where x, y, z correspond to the number of
rows in each table involved in the join. SO select * from a,b will result in 3x3= 9 rows
Finding object dependencies
How can we find out the dependencies on a table?
Asked by: sidd_130 | Member Since Oct-2012 | Asked on: Oct 6th, 2012
View all questions by sidd_130

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


srikanth goduru
Answered On : Oct 10th, 2012

check the table dba_dependencies and see what other tables are affected.

What is Raise_application_error ?
Raise_application_error is a procedure of package DBMS_STANDARD which allows to issue an
user_defined error messages from stored sub-program or database trigger.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Raghavendra
Answered On : Nov 15th, 2006

Raise_application_error is used to create your own error messages which can be more descriptive than
named exceptions.
Syntax is:-
Raise_application_error (error_number,error_messages);
where error_number is between -20000 to -20999..
Answer Question
3 Users have rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
You can use this procedure to issue user-defined error messages from stored subprograms.
You can report errors to your application and avoid returning unhandled exceptions.
Syntax: raise_application_error (error_number,message[, {TRUE | FALSE}]);
Answer Question

Login to rate this answer.


SARANYA
Answered On : Jul 25th, 2011

i know that the error no in raise_application_error are non standard but tell me on what basis we are
giving those numbers? is that simply a number or it some implicit meaning ?
Answer Question

Login to rate this answer.


Ashutosh
Answered On : Oct 8th, 2012
Their classes of errors and diff. errors are divided among these classes simply because of ease in
classification,
For defining errors and error message with raise_application_error procedure by users the class of error
number ranges from 20000 to 20999.
That is only numbers from this interval can be used to defining your own error code
Bulk binding
What are the advantages of bulk binding in PL/SQL?
What is Simple Cursor? and What is Parametrized cursor?
Explain what is Simple Cursor and What is Parameterized Cursor? And Difference between both??
Asked by: sateeshkonthala | Member Since Sep-2010 | Asked on: Nov 21st, 2011
View all questions by sateeshkonthala View all answers by sateeshkonthala
 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


sreemon
Answered On : Jan 4th, 2012
Every SQL statement executed by Oracle has a Private SQL area that contains info about SQL
statement and the set of data returned.

In PL/SQL, a cursor is a name assigned to a specific


private SQL area of a specific SQL Statement.
There can be either, Static Cursor whose SQL statements is determined at compile time, or Dynamic
Cursor, whose SQL statement is determined at runtime.

Note: Dynamic Cursors are implemented using Oracle built in package DBMS_SQL.

Implicit Cursors:
----------------
Any SQL statement that is executed directly or in an PL/SQL block i.e. execution section or in exception
section, during which it is associated with a work area in memory of oracle (SGA). This is done using
implicit cursor by Oracle.

We do not need to declare implicit cursor hence not be


opened, fetched and closed.

Explicit Cursors:
-----------------

They are the SELECT statement that is declared explicitly in the declaration section of current block or in
a package
specification.

Further we can use open, fetch and close in execution section or exception section of the block or
program to utilize declared cursor.
To use an explicit cursor we need to declare it in
declaration section of block or package specification.

There are three sub types of explicit cursors:

* Simple Cursor (without parameter)

CURSOR emp_cur IS
SELECT emp_id
FROM emp;

* Parameterized Cursor - That accepts arguments

CURSOR emp_cur (dept_in [IN] NUMBER) IS


SELECT emp_id
FROM emp
WHERE dept = dept_in ;
* Returning Cursor - A cursor header that contains
a return clause

CURSOR emp_cur (dept_in [IN] NUMBER) IS


RETURN emp%ROWTYPE
SELECT *
FROM emp;

Hope so, above paragraphs explain cursors very well and in details.
Answer Question

Login to rate this answer.


Amol Kulkarni
Answered On : Jun 13th, 2012

A cursor is a private sql area used to stored intermediate data from the sql statements.whenever an sql
statement is fired an cursor get open indirectly which is called as implicit cursor and whenever an user
want to process data based on some sql statements result he has to explicitly define a cursor known as
explicit cursor, A simple cursor is where no parameters are used where as a parametrized cursor is a
cursor where the query result are based explicitly on the parameters passed to the cursor
Code
1. DECLARE
2. CURSOR C1(ENO NUMBER) IS
3. SELECT * FROM EMP
4. WHERE EMPNO=ENO;
5. BEGIN
6.
7. FOR I IN C1(&ENO) LOOP
8. DBMS_OUTPUT.PUT_LINE(ENAME);
9. END LOOP;
10. END;
11.
12.
13.
Answer Question

Login to rate this answer.


Srinivasan Konar
Answered On : Aug 23rd, 2012
The difference between simple and parameterized cursor is as follows:

Simple Cursor - A cursor having a simple or a complex SQL query and which will have conditions based
on given variables or hard-coded.

Parameterized Cursor - such types of cursors will accept parameters i.e. values of the where clause in the
cursor query will depend on the passed parameters.
Answer Question

Login to rate this answer.


abinay
Answered On : Oct 5th, 2012

Cursors having some private area.which is used for store the data from sql statements.Normal cursors we
don't have use any parameters.but parametrized cursors are used the parameters,which is executed
based upon the parameter.
How do you set table for read only access ?
if i am updating one record in a table at that time no other user can't able insert ,update the record in
same table How is it possible
Asked by: nitin_kumat | Member Since May-2006 | Asked on: Mar 20th, 2007
View all questions by nitin_kumat View all answers by nitin_kumat

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


ily_saravanan
Answered On : Mar 25th, 2007
View all questions by ily_saravanan View all answers by ily_saravanan
If you update or delete the records in the table, at the same time, no body can update or delete the
same records which you updated or deleted because oracle lock the data which u updated or deleted.
Answer Question

Login to rate this answer.


sandeep katta
Answered On : Apr 20th, 2007

You can use view for this purpose because you can set view as read only.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 3rd, 2008
View all answers by krishnaindia2007
If a transaction is updating data in a database, it gets an exclusive lock on that part of the database. No
other transaction can read or change this data.
Answer Question

Login to rate this answer.


sippsin
Answered On : Jul 22nd, 2008
View all answers by sippsin
you can select the table for updation

for eg: select * from emp for update;

no you can do the update/insert anything you want...

any other user or session would be able to do any insert/update to the same table only after you release
the table by commit or rollback.....
Answer Question
1 User has rated as useful.

Login to rate this answer.


dinesh.smhdr
Answered On : May 11th, 2011
View all answers by dinesh.smhdr

alter table tablename read only;


Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11
Specify READ ONLY to put the table in read-only mode. When the table is in READ ONLY mode, you
cannot issue any DML statements that affect the table or any SELECT ... FOR UPDATE statements. You
can issue DDL statements as long as they do not modify any table data. Operations on indexes
associated with the table are allowed when the table is in READ ONLY mode.
Specify READ WRITE to return a read-only table to read/write mode.

Read only:
ALTER TABLE SALES READ ONLY;

Back to read/write:
ALTER TABLE SALES READ WRITE;
Answer Question

Login to rate this answer.


priya dharan raj
Answered On : Nov 15th, 2011
View all answers by priya dharan raj
just grant select previlage on that particular table
Answer Question

Login to rate this answer.


velan
Answered On : Sep 11th, 2012
There are couple of ways
1) If there are user other than owner accessing this table then you can "grant select on TABLE_NAME"
2) Otherwise you DBA can create a role which will have only the privillege to only create table and assign
this role to the user then even the owner of the table cannot manipulate the table data.
Answer Question

Login to rate this answer.


Smruti R Das
Answered On : Sep 26th, 2012

GRANT SELECT ON table_name TO user_name


Answer Question

How can I get recent 10 records out of 100 records


HI all table contain some 1000 records, today I inserted 100 records into table, so I want first 10 records
data from 100 records how can I retrieve
Asked by: vinay.juri | Member Since Nov-2011 | Asked on: Nov 24th, 2011
View all questions by vinay.juri

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 20 of 20 Answers


JayaRam Kandimalla
Answered On : Dec 3rd, 2011
View all answers by JayaRam Kandimalla

Use this
Code
1. WHERE rownum < 11
Answer Question

Login to rate this answer.


Mark Haynes
Answered On : Dec 5th, 2011
View all questions by Mark Haynes View all answers by Mark Haynes

The problem with the question is it is too vague. How are you ordering the inserts because if the inserts
were done in a batch, all 100 records at once, then all 100 records will be "most recent". You could just
as well randomly pick any 10 records from the 100 inserted records and claim that random selected 10
was the "most recently" inserted records. Equally, rownum is meanless since rownum returns a number
indicating the order in which Oracle selects the row from a table, not the order it was insert. You can not
reliably control the order Oracle stores the rows inserted in a table, even if they seem to be inserted
sequentially. If you inserted the same 100 records again, the 10 "most recent" or the 1st 10 records via
rownum might not be the same as the previous 100 records insert/(10 most recent or 1st 10) records -
even if the data in both cases was the same. Assuming you had inserted the records in such a way that
some column, call it column "ord", contained the ordinal record of inserts such a way that ord = 1 was
the 1st record inserted and ord = 100 was the last record inserted then:
Code
1. SELECT t.*
2. FROM <table name> t
3. WHERE t.ord < 11
4.
5. would give you the 1st 10 inserted records, AND :
6.
7. SELECT t.*
8. FROM <table name> t
9. minus
10. SELECT t.*
11. FROM <table name> t
12. WHERE t.ord < 91
would give the 10 most recently inserted records.
Answer Question

Login to rate this answer.


Susil Kumar Nagarajan
Answered On : Jan 21st, 2012

Analytic function will serve the purpose. See below SQL.


Code
1. SELECT *
2. FROM
3. (SELECT *
4. FROM
5. (SELECT rowid,
6. e.*,
7. rank() over (ORDER BY rowid ASC) rowid_rank
8. FROM employee e
9. )
10. WHERE rowid_rank >
11. (SELECT COUNT(1)-100 FROM employee
12. )
13. ORDER BY 1 ASC
14. )
15. WHERE ROWNUM < 11;
16.
Answer Question

Login to rate this answer.


sajal
Answered On : Feb 9th, 2012
Code
1. SELECT * FROM
2. (SELECT rowid,e.*,rank() over(ORDER BY rowid DESC) AS rank FROM emp e )
3. WHERE rank<=10 ORDER BY rowid
Answer Question
1 User has rated as useful.

Login to rate this answer.


Balapradee Reddy
Answered On : Feb 14th, 2012
Code
1. SELECT * FROM (SELECT * FROM table_name ORDER BY dbms_random.value) WHERE rownum<
= 10;
Answer Question

Login to rate this answer.


Mohammad Sarwar
Answered On : Feb 17th, 2012

select * from (select * from emp e order by rowid desc) where rownum<=10
Answer Question

Login to rate this answer.


Mark Haynes
Answered On : Mar 1st, 2012
View all questions by Mark Haynes View all answers by Mark Haynes
The following is basicly a pharse of a responses given by Thomas Kyte, from the Blog "Ask Tom Oracle?",
on a similar topics. The comments by Tom highlight the problem with thinking Rowid and/or Rownum -
which is being used most of the solutions to this question - will not be the answer.

What is your definition of the "first 10 records of data"?


You know, the "first 10 records of data" inserted may very well be the first 10 records returned by
"select
* from t", it may be the 100th thru 109th, it may be the 1000th thru 1009th, it may in fact be ANY 10
records.

The "first 10 records of data", there isnt such a concept. There is no such thing as "first 10 records of
data" or "last 10 records of data" there are just rows.

Records are not returned in order of anything. You would have to SORT the data in order to have a "first"
and "last".

If you want the "first 10 records of data" inserted, you need to have a timestamp or sequence number
assigned to each record as they are inserted, then you will get the "first 10 records of data". It is the
ONLY way.

You MUST have some column that you can order by.

Rowid - wont work. The rowid is not "generated" in as much as "derived", it is the address of the row on
disk.
Rowids are not "sequential" things, they say WHERE a row exists, not when a row was inserted or
anything like that. Since space can and will be reused, rowids can and will be "reused". A rowid implies
NOTHING other than the location of the row physically. It does not imply age, order of insertion, or
anything like that.

Rownum -- doesnt work either, it just doesnt work. Rownum is a psuedo column, its value is assigned as
rows are output.

Reference:
"Fetching last record from a table"
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:912210644860

"Rownum"
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:948366252775
Answer Question
2 Users have rated as useful.

Login to rate this answer.


satish
Answered On : Mar 5th, 2012
Code
1. SELECT * FROM emp sample(10);
Answer Question

Login to rate this answer.


Prabu T
Answered On : Apr 29th, 2012
SELECT t.* FROM < table name > t minus SELECT t.* FROM < table name > t WHERE t.ord < 91 instead
of above query, why don't we use the following query, SELECT t.* FROM < table name > t WHERE t.ord
>= 91
Code
1. SELECT t.*
2.
3. FROM <table name> t
4.
5. WHERE t.ord >= 91
Answer Question

Login to rate this answer.


deepika verma
Answered On : May 1st, 2012
Code
1. SELECT *
2. FROM (SELECT ROWNUM, a.*
3. FROM < TABLE name > a
4. ORDER BY ROWID DESC)
5. WHERE ROWNUM BETWEEN 1 AND 100
Answer Question

Login to rate this answer.


Suvarna
Answered On : May 9th, 2012

select top 10 * from ;


Answer Question

Login to rate this answer.


Suvarna
Answered On : May 9th, 2012

select * from where rownum <=10;


Answer Question

Login to rate this answer.


Gunjan David
Answered On : May 13th, 2012
View all questions by Gunjan David View all answers by Gunjan David

@deepika you CANt use rownum keyword in BETWEEN OPERTAOR.......


Answer Question

Login to rate this answer.


ptmich
Answered On : May 27th, 2012
View all answers by ptmich
Code
1. SELECT top 10 * FROM TABLE
2. ORDER BY rowid DESC;
3.
Answer Question
Login to rate this answer.
vithal budhe
Answered On : May 29th, 2012

SELECT * FROM EMP where rownum<10 ORDER BY HIREDATE DESC;


Code
1. SELECT * FROM EMP WHERE rownum<10 ORDER BY HIREDATE DESC;
Answer Question

Login to rate this answer.


Mark Haynes
Answered On : May 29th, 2012
View all questions by Mark Haynes View all answers by Mark Haynes
Ok, perhaps the message is not coming across clear enough.

The person asking the question is asking for the the "recent 10 records out of 100 records" out of the
"100 records" ... "inserted" ... "today" ... "I want first 10 records data from 100 records"

TODAY - RECENT ... these are orders of TIME, the TIME at which the record was inserted into the table.
The "recent 10 records"/"first 10 records" are records that have been ordered BY THE TIME INSERTED.

ROWID is location, it is the location of the row on the disk.

ROWID ... DOES NOT EQUAL ... TIME INSERTED


Let me say this again, ROWID ... DOES NOT EQUAL ... TIME INSERTED
And again, ROWID ... DOES NOT EQUAL ... TIME INSERTED

All the previous queries that are using:


... RANK() OVER (ORDER BY ROWID ASC)
... RANK() OVER (ORDER BY ROWID DESC)
... ORDER BY ROWID DESC

Are wrong, they do not answer the question since:

ROWID ... DOES NOT EQUAL ... TIME INSERTED


Let me say this again, ROWID ... DOES NOT EQUAL ... TIME INSERTED
And again, ROWID ... DOES NOT EQUAL ... TIME INSERTED

To get the "recent 10 records"/"first 10 records" insert "today", you need a column or columns that have
some order related to the time the record was inserted.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Badal
Answered On : May 31st, 2012
it will display top 9 employee details except the 1st one means from the second position it will display try
this code
Code
1. SELECT * FROM EMP WHERE rownum<10 ORDER BY SAL DESC;
Answer Question

Login to rate this answer.


Manoj Kumar
Answered On : Aug 28th, 2012
Code
1. SELECT * FROM (SELECT * FROM emp ORDER BY <created_date> DESC) WHERE rownum <11
Answer Question

Login to rate this answer.


kapil joshi
Answered On : Sep 15th, 2012

select * from employees where rownum<10;


Answer Question

Login to rate this answer.


Can e truncate some of the rows from the table instead of truncating the full table.
Asked by: Interview Candidate | Asked on: Feb 9th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


Mohit Kumar Verma
Answered On : Feb 21st, 2006

No , it is not possible. Truncate is a DDL Command and we can not where clause in Truncate.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Unmesh
Answered On : May 10th, 2006

You can truncate few rows from a table if the table is partitioned. You can truncate a single partition and
keep remaining.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Girish Bhatia
Answered On : Jul 18th, 2006

Unmesh can you explain how is it possible with example.


Answer Question

Login to rate this answer.


Sourajit
Answered On : Dec 28th, 2006

Here is the example:


CREATE TABLE parttab (
state VARCHAR2(2),
sales NUMBER(10,2))
PARTITION BY LIST (state) (
PARTITION northwest VALUES ('OR', 'WA')
TABLESPACE uwdata,
PARTITION southwest VALUES ('AZ', 'CA')
TABLESPACE uwdata);

INSERT INTO parttab VALUES ('OR', 100000);


INSERT INTO parttab VALUES ('WA', 200000);
INSERT INTO parttab VALUES ('AZ', 300000);
INSERT INTO parttab VALUES ('CA', 400000);
COMMIT;

SELECT * FROM parttab;

ALTER TABLE parttab


TRUNCATE PARTITION southwest;

SELECT * FROM parttab;


Answer Question
2 Users have rated as useful.

Login to rate this answer.


leelakrishna302
Answered On : Jun 15th, 2012
View all answers by leelakrishna302

We cannot
Answer Question

Login to rate this answer.


Vishal R Bhadange
Answered On : Aug 12th, 2012
Yes.
Yes we can truncate some of the rows from the table, But table should be partitioned & all the rows to be
deleted should be present in one single partition...
Can we insert multiple nulls through unique constraints ?
Asked by: sachinkshd | Member Since Jul-2012 | Asked on: Jul 17th, 2012
View all questions by sachinkshd

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


santanu
Answered On : Jul 19th, 2012

yes
Answer Question

Login to rate this answer.


Dharmendra Patel
Answered On : Jul 20th, 2012

Yes we can insert multiple nulls as each nulls have different ROWID
Can we write commit or rollback in trigger ?
Asked by: sachinkshd | Member Since Jul-2012 | Asked on: Jul 17th, 2012
View all questions by sachinkshd

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


Noel
Answered On : Jul 17th, 2012

No. Triggers run as part of transaction. In Oracle you can create an autonomous transaction inside of a
trigger if you really need one.

What will happen after commit statement ?


Cursor C1 is Select empno, ename from emp; Begin open C1;
loop Fetch C1 into eno.ename; Exit When C1 %notfound;--
--- commit; end loop; end; The cursor having query as SELECT ....
FOR UPDATE gets closed after COMMIT/ROLLBACK. The cursor having query as SELECT.... does not
get closed even after COMMIT/ROLLBACK.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 18 of 18 Answers


kishorebabukm
Answered On : Sep 20th, 2005

The cursor having query will get closed, because once the for update clause is fired it locks all the rows
which is been modified and once it encounters a commit/rollback it automatically comes out of that
session, and will be processing a fresh loop altogether.
Answer Question
Login to rate this answer.
Bhanu
Answered On : Oct 19th, 2005

DDL statements cannot be included in the pl/sql block. Hence giving commit is not allowed.
Answer Question

Login to rate this answer.


hanthur
Answered On : Feb 23rd, 2006
View all answers by hanthur

The changes will be permanently written to hard disk. No undo(rollback) is possible.


Answer Question

Login to rate this answer.


sunil
Answered On : Jun 12th, 2007

All the Database Locks are Released after commit....


Answer Question

Login to rate this answer.


Prajyot Shelar
Answered On : Jun 28th, 2007
When u will executed this statement into the server that's time commit mechanism will start to save a
record as permanently into the database.
COMMIT statement it's part of TCL Language.
Answer Question

Login to rate this answer.


askvenki
Answered On : Jul 18th, 2007
We cannot give commit inside a loop statement. Then we have to commit out side loop
Answer Question

Login to rate this answer.


vickyjp
Answered On : Jul 20th, 2007

If the data set is too big commiting with-in the cursor loop might lead to the `Snapshot too old Error`.
Answer Question

Login to rate this answer.


bambino chakma
Answered On : Aug 12th, 2007

after the commit statement, the cursor get closed ...as the result no further rows can be fetched even
though there are rows to be fetched.
Answer Question

Login to rate this answer.


ANY
Answered On : Nov 12th, 2007
CURSOR WONT CLOSE AFTER COMMIT TRY THIS CODE

DECLARE
CURSOR C IS
SELECT * FROM EMP
WHERE ROWNUM <4;
R C%ROWTYPE;
BEGIN
OPEN C;
LOOP
FETCH C INTO R;
DBMS_OUTPUT.PUT_LINE (R.EMPNO);
EXIT WHEN C%NOTFOUND;
UPDATE EMP
SET SAL = SAL-1;
COMMIT;
END LOOP;
CLOSE C;
END;
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
Commit will not close a cursor.
Commit makes database changes permanent and releases all the locks on that table.
Answer Question

Login to rate this answer.


anjanjali15
Answered On : Jul 22nd, 2008
View all answers by anjanjali15
COMMIT will not close a Cursor.
Also there is no DML operations to COMMIT.
It will give error eno.ename must be declared.
Answer Question

Login to rate this answer.


sharmasl
Answered On : Mar 16th, 2009
View all answers by sharmasl
In this PL/SQL Block the curosrfetch the records in both the variable till the time it get record. After
fetching all the records when the condition %not found is true it execute the commit and save all the
record which is fetched at the time of execution.
Answer Question

Login to rate this answer.


rachit_srivastava
Answered On : Aug 17th, 2009
View all answers by rachit_srivastava
Use of COMMIT statement end your current transaction and make permanent all changes performed in
the transaction.
A transaction is a sequence of SQL statements, usually COMMIT is used for DML statements.

Cheers!!
Answer Question

Login to rate this answer.


kinkyfellow
Answered On : Nov 18th, 2009
View all answers by kinkyfellow

Commit in this context will not do anything except the commiting the changes into database, done using
DML statements. However, if the cursor is created with FOR UPDATE clause, it will raise runtime
exception as commit, in that case, would also release all locks and thus close the cursor implicitly and
user will get ORA-1002 "fetch out of sequence " error as after the loop is executed one time, with the
commit statement, the cursor will be closed and fetch into statement will fail.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Dilip Lakshetty
Answered On : Mar 27th, 2011
View all answers by Dilip Lakshetty

Whenever User executes COMMIT statement?

The log writer makes redo log entries in redo log files after that message comes commit complete.

later DBWR writes changes into db files permanently from db buffer.


Answer Question

Login to rate this answer.


technofreek
Answered On : May 26th, 2011
View all questions by technofreek View all answers by technofreek
I want to modify the code mentioned in the thread as:
DECLARE
CURSOR C IS
SELECT * FROM EMP
WHERE ROWNUM <4;
R C%ROWTYPE;
BEGIN
OPEN C;
LOOP
FETCH C INTO R;
EXIT WHEN C%NOTFOUND;
DBMS_OUTPUT.PUT_LINE (R.EMPNO||'-'|| R.SAL);
UPDATE EMP
SET SAL = SAL-1
where empno = r.empno;
DBMS_OUTPUT.PUT_LINE (R.EMPNO||'-'|| R.SAL);
END LOOP;
COMMIT;
CLOSE C;
END;

Also by using commit the changes made by update statement will be seen in database permanently.
Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11

The data will be written from redo log buffer into redo log files.
Answer Question

Login to rate this answer.


Vivek
Answered On : Jun 29th, 2012

After committing first oracle will commit the transaction into redo log file and then Data file. The data
block will remain into the memory until the logical reads are going on. Oracle use LRU algorithm to
maintain the data block into the memory. Also oracle maintain rollback segment before committing the
data to store original version of data.

What is materialized view?


Asked by: Interview Candidate | Asked on: Dec 20th, 2006

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 8 of 8 Answers


manisha Ramchandra Gharat
Answered On : Dec 21st, 2006

A materialized view is a database object that contains the results of a query. They are local copies of data
located remotely, or are used to create summary tables based on aggregations of a table's data.
Materialized views, which store data based on remote tables are also, know as snapshots.A materialized
view can query tables, views, and other materialized views. Collectively these are called master tables (a
replication term) or detail tables (a data warehouse term).
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Swapna
Answered On : Jan 10th, 2007

A materialized view or snapshot contains the results of a query of one or more tables, each of which may
be located on the same or on a remote database. Materialized viwes allows to create replications of
tables of remote data with a read-only privillage on the copy. When a materialized view is created, Oracle
creates one table and index, and in the same schema of the materialized view.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Sathish Palanivel
Answered On : Jul 13th, 2007

A materialized view is like a query with a result that is materialized and stored in a table. When a user
query is found compatible with the query associated with a materialized view, the user query can be
rewritten in terms of the materialized view. This technique improves the execution of the user query,
because most of the query result has been precomputed. The query transformer looks for any
materialized views that are compatible with the user query and selects one or more materialized views to
rewrite the user query. The use of materialized views to rewrite a query is cost-based. That is, the query
is not rewritten if the plan generated without the materialized views has a lower cost than the plan
generated with the materialized views.
Answer Question

Login to rate this answer.


sandeep5580
Answered On : Mar 29th, 2008
View all answers by sandeep5580
in addition to te previous posts, unlike a View,which refreshes automatically if the underlying base table
data is changed, the data in a Materialized view needs o be refreshed explicitly with the help of a
dbms_job.Thanks.
Answer Question

Login to rate this answer.


Ramadevioracle
Answered On : Sep 16th, 2008
View all answers by Ramadevioracle

Materialized views are schema objects that can be used to summarize, precompute, replicate, and
distribute data. E.g. to construct a data warehouse.
Answer Question

Login to rate this answer.


ashish
Answered On : Feb 7th, 2012

A materialized view have a physical memory where it can store the result of query which are combination
in joining of one or more table and view it retrieve a faster result. when we want to refresh the data
which are coming from diffrent application so it retrive the fast result. its a benefit of materialized view.
Answer Question

Login to rate this answer.


uday bhaskar rerddy
Answered On : Apr 19th, 2012
Materialized view is the local copy of remote database object.materialized view is the space demanding
object and it is read only. At the time of creating the materialized views,we can specify refresh interval
and refresh modes.

Refresh intervals represents, how the frequently the materialized view has to be refreshed. Refresh
modes are

1. Complete
2. Fast
3. Force
4. Uncommit
5. On demand
6. Differed
Answer Question

Login to rate this answer.


Sathish
Answered On : Jun 12th, 2012

Materialized views are objects that are used in base table that can be Summarized Group, and
aggregated with the base table.This materialized views are used in data-ware housing and decision
support system.
What steps should a programmer should follow for better tunning of the PL/SQL
blocks?
Difference between procedure and function?
What is the use of ref cursor return type?
Asked by: aseemnaithani | Member Since Feb-2006 | Asked on: Mar 15th, 2006
View all questions by aseemnaithani View all answers by aseemnaithani

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


gomathi
Answered On : Mar 18th, 2006

The main difference between procedure and function,function should return a value.procedure need not
Answer Question
1 User has rated as useful.

Login to rate this answer.


Antony Gubert
Answered On : Mar 20th, 2006

Ref cursor return type can be used when it's required that a procedure / function need to return set of
records.
Answer Question

Login to rate this answer.


Savithri
Answered On : Apr 2nd, 2006

Tuning can be taken care by using the Correct Index on the table.We should not use Not equal to,
Distinct on the Indexed columns.
Answer Question

Login to rate this answer.


Keshav
Answered On : May 22nd, 2006
SQL Queries Best Practices

1. Always use the where clause in your select statement to narrow the number of rows
returned.
If we dont use a where clause, the Oracle performs a full table scan on our table and
returns all of the rows.

2. Use EXISTS clause instead of IN clause as it is more efficient than IN and performs
faster.

Ex:

Replace
SELECT * FROM DEPT WHERE DEPTNO IN
(SELECT DEPTNO FROM EMP E)
With
SELECT * FROM DEPT D WHERE EXISTS
(SELECT 1 FROM EMP E WHERE D.DEPTNO = E.DEPTNO)

Note: IN checks all rows. Only use IN if the table in the sub-query is extremely
small.

3. When you have a choice of using the IN or the BETWEEN clauses in your SQL , use
the BETWEEN clause as it is much more efficient than IN.
Depending on the range of numbers in a BETWEEN, the optimizer will choose to do a
full table scan or use the index.

4. Avoid WHERE clauses that are non-sargable. Non-sargable search arguments in the
WHERE clause, such as "IS NULL", "OR", "<>", "!=", "!>", "!<", "NOT", "NOT
EXISTS", "NOT IN", "NOT LIKE", and "LIKE %500" can prevent the query optimizer
from using an index to perform a search. In addition, expressions that include a
function on a column, or expressions that have the same column on both sides of the
operator, are not sargable.

Convert multiple OR clauses to UNION ALL.

5. Use equijoins. It is better if you use with indexed column joins. For maximum
performance when joining two or more tables, the indexes on the columns to be
joined should have the same data type.

6. Avoid a full-table scan if it is more efficient to get the required rows through an
index. It decides full table scan if it has to read more than 5% of the table data (for
large tables).

7. Avoid using an index that fetches 10,000 rows from the driving table if you could
instead use another index that fetches 100 rows and choose selective indexes.
8. Indexes can't be used when Oracle is forced to perform implicit datatype
conversion.

9. Choose the join order so you will join fewer rows to tables later in the join order.
 use smaller table as driving table
 have first join discard most rows

10. Set up the driving table to be the one containing the filter condition that eliminates
the highest percentage of the table.

11. In a where clause (or having clause), constants or bind variables should always be
on the right hand side of the operator.

12. Do not use SQL functions in predicate clauses or WHERE clauses or on indexed
columns, (e.g. concatenation, substr, decode, rtrim, ltrim etc.) as this prevents the
use of the index. Use function based indexes where possible

SELECT * FROM EMP WHERE SUBSTR (ENAME, 1, 3) = KES

Use the LIKE function instead of SUBSTR ()

13. If you want the index used, dont perform an operation on the field.

Replace
SELECT * FROM EMPLOYEE WHERE SALARY +1000 = :NEWSALARY

With
SELECT * FROM EMPLOYEE WHERE SALARY = :NEWSALARY 1000

14. All SQL statements will be in mixed lower and lower case. All reserve words will be
capitalized and all user-supplied objects will be lower case. (Standard)

15. Minimize the use of DISTINCT because it forces a sort operation.

16. Try joins rather than sub-queries which result in implicit joins

Replace
SELECT * FROM A WHERE A.CITY IN (SELECT B.CITY FROM B)

With
SELECT A.* FROM A, B WHERE A.CITY = B.CITY

17. Replace Outer Join with Union if both join columns have a unique index:

Replace
SELECT A.CITY, B.CITY FROM A, B WHERE A.STATE=B.STATE (+)

With
SELECT A.CITY, B.CITY FROM A, B WHERE A.STATE=B.STATE
UNION
SELECT NULL, B.CITY FROM B WHERE NOT EXISTS
(SELECT 'X' FROM A.STATE=B.STATE)

18. Use bind variables in queries passed from the application (PL/SQL) so that the same
query can be reused. This avoids parsing.
19. Use Parallel Query and Parallel DML if your system has more than 1 CPU.

20. Match SQL where possible. Applications should use the same SQL statements
wherever possible to take advantage of Oracle's Shared SQL Area. The SQL must
match exactly to take advantage of this.

21. No matter how many indexes are created, how much optimization is done to queries
or how many caches and buffers are tweaked and tuned if the design of a database
is faulty, the performance of the overall system suffers. A good application starts
with a good design.

22. The following operations always require a sort:

SELECT DISTINCT
SELECT UNIQUE
SELECT ....ORDER BY...
SELECT....GROUP BY...
CREATE INDEX
CREATE TABLE.... AS SELECT with primary key specification
Use of INTERSECT, MINUS, and UNION set operators
Unindexed table joins
Some correlated sub-queries
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Poojitha Somareddy
Answered On : May 26th, 2006
Also the order in which the conditions are given in the 'WHERE' cluase are very important while performing a
'Select' query. The Performance Difference is unnoticed ifother wise the query is run on a Massive Database.
For example for a select statement,
SELECT Emp_id FROM Emp_table WHERE Last_Name = 'Smith' AND Middle_Initial = 'K' AND Gender
= 'Female';
The look up for matches in the table is performed by taking the conditions in the WHERE cluase in the reverse order
i.e., first all the rows that match the criteria Gender = 'Female' are returned and in these returned rows, the conditon
Last_Name = 'Smith' is looked up.
There fore, the order of the conditions in the WHERE clause must be in such a way that the last condition gives
minimum collection of potential match rows and the next condition must pass on even little and so on. So, if we fine
tune the above query, it should look like,
SELECT Emp_id FROM Emp_table WHERE Gender = 'Female' AND Middle_Initial = 'K' AND
Last_Name = 'Smith' ; as Last_Name Smith would return far more less number of rows than Gender = 'Female' as
in the former case.

How to find the nth hightest record holder from a table


Asked by: Interview Candidate | Asked on: Aug 31st, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 20 of 20 Answers


Ravi S. Pasari
Answered On : Sep 2nd, 2006

You can use the following e.g.1. SELECT * FROM ( SELECT deptno, ename , sal , ROW_NUMBER() OVER
( PARTITION BY deptno ORDER BY sal DESC ) Top3 FROM emp )WHERE Top3 <= 3/2. This will give
distinct values.SELECT * FROM ( SELECT deptno, ename , sal , DENSE_RANK) OVER ( PARTITION BY
deptno ORDER BY sal DESC ) Top3 FROM emp )WHERE Top3 <= 3/
Answer Question
1 User has rated as useful.

Login to rate this answer.


dineshchaini
Answered On : Sep 10th, 2006
View all answers by dineshchaini

Hi...
If u want to find the nth record in salary basis then.. I thnik this will work
select * from(select * from emp order by sal desc) where rownum=
Answer Question
1 User has rated as useful.

Login to rate this answer.


chandra
Answered On : Sep 13th, 2006
the query is select * from sample where rownum=(select max(rownum) from sample)
Answer Question

Login to rate this answer.


rashid
Answered On : Sep 20th, 2006

u can use inline view


select sal from(select sal from emp order by sal desc) where rownum <5;
Answer Question
1 User has rated as useful.

Login to rate this answer.


Santo
Answered On : Oct 9th, 2006

Here is the query,


suppose i have table called T1 with 2 columns say ID,SAL then
i want to find out 3rd highest salary
select a.sal from t1 a
where 3 =(select count(distinct(b.sal)) from t1 b where a.sal <= b.sal);
with Regs
Santo
Answer Question
4 Users have rated as useful.

Login to rate this answer.


Suresh
Answered On : Oct 13th, 2006

select * from ( select rownum r, sal,name from (select * from emp order by sal)) where r=
You need to give all column names in first inline view.
Answer Question

Login to rate this answer.


rampratap409
Answered On : Dec 9th, 2006
View all questions by rampratap409 View all answers by rampratap409

select * from emp where rownum <=9


minus
select * from emp where rownum <9
Answer Question

Login to rate this answer.


sankari
Answered On : Jan 9th, 2007
We can use dense_rank() built in. It will rank the result set based on the column which is given in the
over() clause.
For ex) to get the 7th highest salary we can use the following query.
select * from(
select empno,ename,salary,dense_rank() over(order by salary desc) r
from emp )where r=7
I have used this in 10g..i am sure about the below versions.
Answer Question
1 User has rated as useful.

Login to rate this answer.


sudhaker
Answered On : Jan 17th, 2007
View all answers by sudhaker

to find nth highest salary u can go with this query


select min(sal) from (select distinct sal from emp order by sal desc) where rownum<='&ar';
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 3rd, 2008
View all answers by krishnaindia2007

select max(sal) from emp a where &n = (select count(distinct sal) from emp where sal >= a.sal);
Answer Question

Login to rate this answer.


nade_rs
Answered On : Jun 25th, 2011
View all answers by nade_rs
select min(sal) from (select distinct sal from emp order by sal desc) where rownum<n;
Answer Question

Login to rate this answer.


diptisaxena
Answered On : Jul 15th, 2011
View all answers by diptisaxena

If we have a table EMP and having data as, if we want second highest sal i.e 5000 the the query will be:
Code
1. EMPNO ENAME SAL
2. 1 A 5000
3. 2 B 2000
4. 3 C 10000
5.
6. SELECT MIN(SAL) FROM (SELECT * FROM EMP ORDER BY SAL DESC)
7. WHERE ROWNUM <=2
8.
Same as nth highest query we need to put that number instead of 2.
Answer Question

Login to rate this answer.


ravindra
Answered On : Jul 27th, 2011
Code
1. SELECT * FROM(SELECT ROW NUMBER AS rno emp.*FROM emp)WHERE RANK=&n;
Answer Question

Login to rate this answer.


Nihar
Answered On : Aug 26th, 2011
SELECT * FROM Emp A
WHERE &n=(SELECT COUNT(DISTINCT(Sal)) FROM EMP B WHERE A.Sal<=B.Sal);
Answer Question

Login to rate this answer.


anitha
Answered On : Aug 31st, 2011
Code
1. SELECT * FROM emp a WHERE n = (SELECT count(DISTINCT sal) FROM emp
b WHEREa.sal<=b.sal)
2.
3. //IN n place mention 1, 2,3...
4.
Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11

It is better to use analytic functions these days as they are faster and smarter and your managers will
think high of you...
Code
1. Top n-paid IN ALL Depts - changer the orde BY dept AND sal DESC IF ant TO find
out top paid IN each dept:
2. SELECT * FROM ( SELECT deptno, ename, sal
3. , ROW_NUMBER() OVER (ORDER BY sal DESC, ename) AS row_num
4. , RANK () OVER (PARTITION BY deptno ORDER BY sal DESC) rank
5. , DENSE_RANK () OVER (PARTITION BY deptno ORDER BY sal DESC) d_rank
6. FROM emp )
7. --WHERE row_num <= 4
8. /
Answer Question

Login to rate this answer.


rohitosu
Answered On : Mar 13th, 2012
View all answers by rohitosu

This is incorrect. It will not return anything. One of the possible answer is
Code
1. SELECT salary FROM (SELECT rownum n, a.salary
2. FROM
3. (SELECT DISTINCT salary FROM person ORDER BY salary ) a)
4. WHERE n = 5 ;
Answer Question

Login to rate this answer.


rohitosu
Answered On : Mar 13th, 2012
View all answers by rohitosu
This is a nice solution but it will not work correctly if any of the row has null values in it.

This is what I did. I specified n = 1 which means I want the highest salary. then I put the NULL values
for this record in salary column. The record with NULL value always shows me as the highest salaried
employee which is incorrect.
Answer Question

Login to rate this answer.


Neeraj Siddhey
Answered On : Mar 20th, 2012

This will work:-


Code
1. SELECT DISTINCT a.salary FROM emp a, emp b
2. WHERE 9=(SELECT DISTINCT count(b.salary) FROM emp b WHERE a.salary<=b.salary);
Answer Question

Login to rate this answer.


manisha
Answered On : May 27th, 2012

use
Code
1. NVL(a.sal,0)<= NVL(b.sal,0)
Answer Question

Login to rate this answer.

When would you use Inline view in Sub query?


Asked by: Gunjan David | Member Since Jun-2011 | Asked on: May 13th, 2012
View all questions by Gunjan David View all answers by Gunjan David

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


vizzi
Answered On : May 16th, 2012

When we use a select query in the from clause, it is called as a inline view. It is used to reduce
complexity of using so many join conditions.
What is nested table in Oracle and difference between table and nested table?
Asked by: Vikramsingh | Member Since Oct-2007 | Asked on: Oct 23rd, 2007
View all questions by Vikramsingh

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


drk
Answered On : Nov 12th, 2007
A nested table can be stored as a database column. This means that the entire nested table is contained
in one row of a table and each row of the table can contain different nested table

1. Can be stored in database


2. can be manipulated using SQL
3. can be automatically null
4. individual elements can be accessed using subscript

Answer Question
2 Users have rated as useful.
Login to rate this answer.
Anu Ramakrishnan
Answered On : Nov 27th, 2007
Nested table is the collection object in oracle . It is also stored in database one in a separate file called
store file .This can be used as a column in a table like VARRAY. This is created in a database
usingcreate type command .It is used for storing a single dimensional value like VARRAY. The
difference between VARRAY and nested table is we can have numerous value single table but in case of
VARRAY we can not have more than the defined limit .
Answer Question

Login to rate this answer.


nitingalande
Answered On : Jan 13th, 2008
View all answers by nitingalande

In Oracle nested table are considered one-column database tables. Tables which are having one table as
a cell. Nested tables are like one-dimensional arrays stored in a table, but we can model nested table to
hold multi-dimensional arrays.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 19th, 2008
Nested tables are unbounded.
Initially dense but can become sparse through deletions.
Order is not preserved
Can be indexed

PL/SQL tables are singly dimensioned, unbounded,


sparse collections of homogeneous elements
Available only in PL/SQL.
Can be indexed
Answer Question

Login to rate this answer.


jagadeesh9
Answered On : Feb 24th, 2008
View all questions by jagadeesh9 View all answers by jagadeesh9
Table with in a table is called as nested table
NESTED TABLE:
stored outside the table
supports unlimited rows
DMLallowed

VARRAYS:
stored with in the table
supports limited rows
DML not allowed
Answer Question
Login to rate this answer.
krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
A Table is a basic unit of storage in oracle.

A nested table is a collection type. The main advantage of collections is instead of processing data
sequentially, we may process all the date in one step.
- It is a collection of rows stored as a column in a table.
- It is a table withing a table.
- There is no restriction on number of rows in a nested table
- There is no restriction on number of columns in a nested table.
- We can not index nested table.
- The nested table is stored as a seperate table and main table maintains a pointer to the nested table as
reference.
- Nested table stored data in no particular order
- But when you retrieve data into pl/sql variable it assigns serial number starts with 1
- Intially they are dense you may sparse later.
- Nested tables are unbounded. There is no upper limit.
Answer Question
1 User has rated as useful.

Login to rate this answer.


pankti
Answered On : Apr 6th, 2012
Nested table Unbounded
Individual element can be deleted
Stored out of line in stored table.
Support indexes.
More flexible.
Data is stored in separate table.
Stored outside the table
DML are allowed.

VArrays
Bounded
Individual element cannot be deleted.
Stored by Oracle in- line
Do not support indexes.
Not flexible than nested table.
Data is stored as single object in database.
Stored within table.
DML are not allowed
Oracle exception block
In the exception part,what will happen if u dont give (when others) where will it show error compile time
or run time
Asked by: nabiel_pathan | Member Since Feb-2011 | Asked on: Feb 13th, 2012
View all questions by nabiel_pathan

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


Giriraj Gupta
Answered On : Feb 26th, 2012

Run time
Answer Question

Login to rate this answer.


Mark Haynes
Answered On : Feb 27th, 2012
View all questions by Mark Haynes View all answers by Mark Haynes
Now, to clarify, I am taking the following statement; "in the exception part, what will happen if you don't
give the (when others) statement" to mean an exception block with no other when statements as well, in
that case, an error would show at compile time.

If there were other when statements in the exception the code would compile, if an exception occurred
and the other could not handle the error, then the handling of the error would be be moved up the
calling stack until it was either handled or the application terminated because of the un-handled run-time
error.
Answer Question

Login to rate this answer.


NAND
Answered On : Feb 27th, 2012
It will give the error at run time if it is not able to find the type of exception thrown in the current PL/SQL
block or the outer block.
It will not throw the compile time error.
Can we use commit or rollback command in the exception part of PL/SQL block?
Asked by: Interview Candidate | Asked on: Oct 19th, 2005

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 21 of 21 Answers


Sarat
Answered On : Oct 19th, 2005

No
Answer Question

Login to rate this answer.


santosh mhamunkar
Answered On : Oct 19th, 2005

yes
Answer Question
1 User has rated as useful.

Login to rate this answer.


suresh
Answered On : Nov 4th, 2005

how can u say we can use commands commit,rollback?


Answer Question

Login to rate this answer.


rishu
Answered On : Nov 8th, 2005

Yes
Answer Question

Login to rate this answer.


vardhan_81
Answered On : Nov 9th, 2005
View all questions by vardhan_81 View all answers by vardhan_81

no we can not use tcl(commit,rollback,savepoint) and ddl commands in exception block


Answer Question

Login to rate this answer.


answertoyourquery
Answered On : Nov 9th, 2005

Yes, we can use the TCL commands(commit/rollback) in the exception block of a stored
procedure/function. The code in this part of the program gets executed like those in the body without
any restriction. You can include any business functionality whenever a condition in main block(body of a
proc/func) fails and requires a follow-thru process to terminate the execution gracefully!
Answer Question
4 Users have rated as useful.

Login to rate this answer.


vinayak tripathi
Answered On : Dec 14th, 2005

Yes, u can use commit or rollback in exception block.


Answer Question
1 User has rated as useful.

Login to rate this answer.


PRATIK GHOSHAL
Answered On : Jan 8th, 2006

yes we can
Answer Question

Login to rate this answer.


Rupjit Roy
Answered On : Feb 23rd, 2006
Yes we can use commit/rollback in exception part. Example:
DECALRE
..
BEGIN
.
EXCEPTION
WHEN NO_DATA_FOUND THEN

INSERT INTO err_log(


err_code, code_desc)
VALUES(1403, No data found)

COMMIT;
RAISE;
END
Answer Question

Login to rate this answer.


Deepika S Verma
Answered On : Apr 19th, 2006

yes you can .. try this code


create table test1(x varchar2(20))
declare
x number;
begin
select sal into x from emp where ename like 'TTT%';
exception when no_data_found then
insert into test1 values('no data');
commit;
end;
/
select * from test1;
Answer Question

Login to rate this answer.


neema
Answered On : May 29th, 2006

Yes
Answer Question

Login to rate this answer.


Arup Chakraborty
Answered On : Nov 3rd, 2006

Yes, we can use Commit / Rollback in the Exception part. Declare ---Variable declaration Begin ----
Executable part Exception When others then dbms_output.put_line(sqlerrm); Rollback; END ;
Answer Question
1 User has rated as useful.

Login to rate this answer.


vandsavvy
Answered On : Jun 15th, 2008
View all answers by vandsavvy

Yes We can
Answer Question

Login to rate this answer.


aksingh283
Answered On : May 27th, 2011
View all answers by aksingh283
Yes , we can use commit or rollback in exception part of PL SQL Block .
Below is an anonymous PL SQL block , try this :

Declare
myexception EXCEPTION;
Begin
RAISE myexception;
EXCEPTION
When myexception then
insert into table_name values (......);
COMMIT;

insert into table_name values (.......);


ROLLBACK;
END;
Answer Question

Login to rate this answer.


subhash
Answered On : Jul 31st, 2011

yes we can......
Answer Question

Login to rate this answer.


geetha
Answered On : Aug 4th, 2011

no, we can't use exceptions in ddl statements.normal form sql or sql*plus,without explicitly issuing
commit or rollback statements.
Answer Question

Login to rate this answer.


Prashant
Answered On : Aug 30th, 2011

Yes, you can use commit/rollback in exception block.


Answer Question

Login to rate this answer.


Kunal Priyadarshi
Answered On : Sep 22nd, 2011
View all answers by Kunal Priyadarshi

yes.. surely.. you can use any TCL command within the exception block.
Answer Question

Login to rate this answer.


priya dharan raj
Answered On : Nov 14th, 2011
View all answers by priya dharan raj
we can use commi ,rollback inside exception block

EXCEPTION -- exception handlers begin


WHEN ZERO_DIVIDE THEN -- handles 'division by zero' error
INSERT INTO stats (symbol, ratio) VALUES ('XYZ', NULL);
COMMIT;
Answer Question

Login to rate this answer.


TIRUMALARAOKONDA
Answered On : Dec 11th, 2011
View all answers by TIRUMALARAOKONDA
Yes, we can use the commit/rollback statements in an exception blocks.
Answer Question

Login to rate this answer.


Susil Kumar Nagarajan
Answered On : Jan 20th, 2012

Yes. You can very well use COMMIT or ROLLBACK in exception block. But it is not a good idea to use, as
it will commit the previous transactions in the same PLSQL block. Make use of creating SAVEPOINTS and
commiting them when required.
Answer Question

Where would you use implicit & explicit cursors?


Asked by: Interview Candidate | Asked on: Nov 24th, 2011

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


harru
Answered On : Dec 12th, 2011

If select query is retrieving less than 200 records go for implicit cursor.
Code
1.
2. begin
3. for i in (select * from emp)
4. ----------------
5. end
Else use explicit cursor
Code
1. declare
2. cursor c1 is select * from emp_morethan200
3. begin
4. for i in c1 loop
5. ----------------

What are Oracle Hints and How do you use them ?


Explain the real-time situation where would you use Oracle Hits
Asked by: Interview Candidate | Asked on: Nov 24th, 2011

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


Lokesh M
Answered On : Dec 7th, 2011
View all questions by Lokesh M View all answers by Lokesh M
Oracle optimizer is responsible for handling different situations by making appropriate decisions based on
database statistics. It will create route path that is most appropriate to execute the code.

Oracle hints are used when there is a need to instruct or guide the Oracle optimizer to make custom
decisions instead of its own decisions which are made based on database statistics.

That means by making use of Hints we are basically giving instruction to the optimizer and telling it which
route it should follow to execute the code and thereby affecting the outcome of Oracle optimizer's
decision.

Some of the Hint types are as follows:


- Access Hints
- Join Order Hints
- Joint Operations Hints
- Parallel Execution Hints
- Optimization Hints

Jonathan Lewis states that "Hints are interception points in the optimizer code path, and must be
obeyed."
and he further adds that "Hint affects the optimizers route through its code path."

What is difference between % ROWTYPE and TYPE RECORD ?


% ROWTYPE is to be used whenever query returns a entire row of a table or view. TYPE rec RECORD
is to be used whenever query returns columns of differenttable or views and variables. E.g. TYPE
r_emp is RECORD (eno emp.empno% type,ename emp ename %type); e_rec emp% ROWTYPE
cursor c1 is select empno,deptno from emp; e_rec c1 %ROWTYPE.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


kishorebabukm
Answered On : Sep 20th, 2005

basically the %rowtype is used in case of fetching the values of the cursor irrespective of how many
columns in it and also the data types associated with the tables column.for eg.
declare
cursor c_example is select * from emp;
v_emp emp%rowtype;
begin
for v_emp in c_example loop
statements
......
end loop;
end;
the type record is a object oriented concept related to pl/sql tables, tables with datastructure format etc.
create type ty_name is record ( a number,
b varchar2(10));
this type stores data in a record fashion with 2 columns.
Answer Question
1 User has rated as useful.

Login to rate this answer.


sunilbidgar
Answered On : Apr 18th, 2008
View all answers by sunilbidgar

%rowtype is an attribute to inherit datatypes of attributes of a table into a RECORD variable. Type record
is a keyword to create record type using either explicitly specifying atrributes or by implecitly inheriting
attributes from a table or a existing cursor.
Answer Question

Login to rate this answer.


nagarajkv
Answered On : May 5th, 2008
View all answers by nagarajkv
TYPE RECORD is a composite datatype. It consits of multiple pieces of information, called fields. TYPE
RECORD fields can be defined by the user. Eg:

DECLARE
TYPE extra_book_info_t
IS RECORD (
title books.title%TYPE,
is_bestseller BOOLEAN
);

first_book extra_book_info_t;

here, 'title' is the data type defined in books table. We can declare a RECORD based on this type.

Where as %ROWTYPE is a direct link to the data type of the table.columns, EG:
DECLARE
bestseller books%ROWTYPE;

The advantage of TYPE RECORDS is you can pass these to Functions or Procedures which can reduce the
parameter size or a repitative work.
Hope this give a better explanation.
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 15th, 2008
View all answers by krishnaindia2007
%ROWTYPE is used when you need to work with complete record.
TYPE RECORD is used to create your own data type with specificed number of values to hold.
Suppose If a table has 20 columns and you need to work with only seven columns . If I use %ROWTYPE,
I get all 20 values unnecessarily. At the same time, my program will be bit clumsy if I use seven %TYPE
declarations. A better way to solve this solution is by defining my own data type, which can hold seven
values.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


iqbal
Answered On : Nov 1st, 2011

there is no need to declare v_emp as we are using for loop....


Answer Question

Login to rate this answer.


priya dharan raj
Answered On : Nov 15th, 2011
View all answers by priya dharan raj

this %rowtype is used declare record type

Schedule email in oracle


How to schedule an email in oracle reports?
Asked by: gt.sanwaliyaji | Member Since Sep-2010 | Asked on: Oct 20th, 2010
View all questions by gt.sanwaliyaji

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


zahar
Answered On : Jun 7th, 2011
View all answers by zahar

using utl_mail
Answer Question

Login to rate this answer.


KARI
Answered On : Oct 29th, 2011

UTL_MAIL: type procedure in UTL_MAIL 1)SEND (send the message without attachment)
Code
1. BEGIN
2. UTL_MAIL.SEND(sender=>'karimuth@amazon.com',recipients=>'karimuthu.bala@gmail.com
',message =>'HAPPY BIRTHDAY',subject => 'birthday wishes');
3. END
4. 2)SEND_ATTACH_RAW(FOR message WITH binary attachment)
Code
1. BEGIN
2. UTL_MAIL.SEND_ATTACH_RAW(sender=>'karimuth@amazon.com',recipients=>'karimuthu.bal
a@gmail.com',message =>'HAPPY BIRTHDAY',subject => 'birthday wishes'
3. mime_type => 'text/html',attachment => get_image('oracle.gif'),att_inline=>true,a
tt_min_type =>'image/gif',att_filename =>'oracle.gif');
4. END
3)SEND_ATTACH_VARCHAR2(for messages with text attachment)
Code
1. UTL_MAIL.SEND_ATTACH_VARCHAR2(sender=>'karimuth@amazon.com',recipients=>'karimuth
u.bala@gmail.com',message =>'HAPPY BIRTHDAY',subject => 'birthday wishes'
2. mime_type => 'text/html',attachment => get_file('test.txt'),att_inline=>flase,att
_min_type =>'text/plain',att_filename =>'test.txt');
3. END
Answer Question

How to return more than one value from a function?


What are the types of triggers?
What are the features of oracle 9i
Asked by: aseemnaithani | Member Since Feb-2006 | Asked on: Mar 15th, 2006
View all questions by aseemnaithani View all answers by aseemnaithani

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 13 of 13 Answers


gomathi
Answered On : Mar 18th, 2006

we can return only one value at a time. if we want more then one value we directly assign that value to
the variable(ii) Types of triggers(*) row level trigger(*) statement level trigger(*) Before Trigger(*) After
Trigger
Answer Question

Login to rate this answer.


aseemnaithani
Answered On : Mar 19th, 2006
View all questions by aseemnaithani View all answers by aseemnaithani

we return one more than one value by using ref cursors.


Answer Question

Login to rate this answer.


Antony Gubert
Answered On : Mar 20th, 2006

The following are some of the new features of oracle 9i....


1. Flash Back Query
2. Function based indexes
3. Materialized view enhancement etc....

Answer Question

Login to rate this answer.


harikishan
Answered On : Mar 24th, 2006

1)Use Ref cursor to retuen more than one value. 2)Till oracle 8i there are 13 types of Database triggers.
For 3 DML operations (ADD,DEL,MOD) before and after triggers Ex Before delete, After delete, Before
update after update etc that'll make 6 triggers. For each 6 row level and statemnet level that'll make 12
types of triggers. 1 instead of triggers. to manipulate complex views . from 9i onwards new triggers have
been introduced to logon and log off.3) There are 400 new features in oracle 9i . but mostly they are
into DW concepts. and for developers point of view. Merge, Flashback query, New features in DB
triggers, aditional features in Row id etc. Hope this wil helpHarikishan
Answer Question

Login to rate this answer.


pandish
Answered On : Apr 30th, 2006
View all questions by pandish View all answers by pandish

If you want to return more than 1 value & dont want to use ref curser...try this, 1. Return comma
separated varchar & then use dbms_utility.comma_to_table function to parse them.2. Try returning
variable of type pl/sql table or varray.I have not tried number 2, but should work.
Answer Question

Login to rate this answer.


Krishna Mohan
Answered On : May 12th, 2006

1. By default a function would return only one value.


2. For returning multiple values declare a ref cursor in package spec and use the same in the
function/procedure in the package body.
3. Declare multiple variables as out parameters in the function/procedure being used . This will also
return multple values.
Answer Question
1 User has rated as useful.

Login to rate this answer.


rupak
Answered On : May 24th, 2006

HI Shekhar,
can you please give me some example that how to return multiple values from a function
using a comma separated varchar and parse it. I'm stuck in that situation and found solution using varry
type. If getting the comma separated varchar would be better.
Thanks & regards
Rupak
Answer Question

Login to rate this answer.


Rajeshwaran
Answered On : Jun 3rd, 2006

More than one values can be returned to the calling environment by a function is achieved by declaring
INOUT parameters or OUT parameters in the function .
but it is not good programming practise to force a function to return more than one values...
Answer Question

Login to rate this answer.


Samir Narielwala
Answered On : Jul 30th, 2007
Hi K.Mohan,

Can you provide a simple code showing how ref cursor can be used to return more than one values from
the function? It would be very helpful.

Thanks
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
Here is the example for using out parameter in functions

CREATE OR REPLACE FUNCTION TEST_FUNC(A IN NUMBER, B IN OUT NUMBER,C OUT NUMBER)


RETURN NUMBER IS
D NUMBER(3);
BEGIN
B := B + A;
C := B;
D := A + B + C;
RETURN D;
END;

DECLARE
A1 NUMBER(3) := 10;
B1 NUMBER(3) := 20;
C1 NUMBER(3) := 30;
D1 NUMBER(3) := 40;
BEGIN
D1 := TEST_FUNC(A1,B1,C1);
DBMS_OUTPUT.PUT_LINE(A1 || ' ' || B1 || ' ' || C1 || ' ' || D1);
END;
Answer Question
1 User has rated as useful.

Login to rate this answer.


srm_ranjan
Answered On : Nov 11th, 2008
View all answers by srm_ranjan

Functions always returns One value. If you want to return more than One value, You can use the Out
parameter. Using out parameter you can get more than one value, but you cannot use that function in
Select Query.
Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11

The function always return a SINGLE value, which includes arrays. Check out the table functions
(pipelined), BULK_COLLECT, arrays etc... You can find plenty of examples.
Code
1. SET serveroutput ON
2. DECLARE
3. TYPE t_EmpNoArr IS VARRAY(20000) OF NUMBER(10) ;
4. v_RetVal t_EmpNoArr:= t_EmpNoArr();
5. --
6. FUNCTION retArray RETURN t_EmpNoArr
7. IS
8. v_empnoArr t_EmpNoArr:= t_EmpNoArr();
9. BEGIN
10. FOR i IN ( SELECT empno FROM emp1 )
11. LOOP
12. v_empnoArr.extend() ;
13. v_empnoArr(v_empnoArr.COUNT):= i.empno ;
14. END LOOP;
15. FOR j IN 1..v_empnoArr.COUNT() LOOP
16. DBMS_OUTPUT.PUT_LINE(v_empnoArr(j));
17. END LOOP;
18. RETURN v_empnoArr;
19. END retArray;
20. --
21. BEGIN
22. v_RetVal:= retArray();
23. END;
24. /
25.
Answer Question

Login to rate this answer.


RJ
Answered On : Oct 17th, 2011
There are five types of Triggers

1) Data Definition Language triggers: These triggers fire when you make changes to the objects in the
database like create, update or delete. They can be implemented to monitor the changes in the schema.
2) Data Manipulation Language Triggers:
3) Compound Triggers:
4) Instead-Of Triggers:
5) System or Database Event Triggers:
How to get the 25th row of a table.
Asked by: Interview Candidate | Asked on: Dec 20th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 11 of 11 Answers


AHMED BIN SAYEED
Answered On : Dec 21st, 2006

Hi,
to get the 25th row of a table the following query can be useful
SELECT * FROM (SELECT ROWNUM r,e.* FROM emp e)
WHERE r = 25
Answer Question
1 User has rated as useful.

Login to rate this answer.


Pradhan
Answered On : Jan 3rd, 2007

We can use this query , too:


select * from Emp where rownum < 26
minus
select * from Emp where rownum<25
Answer Question
1 User has rated as useful.

Login to rate this answer.


raghav_sy
Answered On : Jan 17th, 2007
View all answers by raghav_sy

I will share few things regarding the solutions given for this problem,among all only two queries willwork
given by Ahmed and Pradhan.
But among these two, Ahmed's is the best solution. because its a very much optimized query.
Query given by gangadharan will not solve this problem, as it is used for Nth max. analysis.
Query given by shankar will not work, because we can not use keyword ROWNUM with Equality(=).
Well one thing to note here is that, even in Ahmed's query, r is the alias for ROWNUM. and later r has
been used with equality.=).
So remember, ROWNUM can not be used with equality but after aliasing it equality condition can be
used.
and i request my frineds here, post solution and also explain a bit how its working, because how is very
important as compared to what.
Answer Question
3 Users have rated as useful.

Login to rate this answer.


Prasanna Kumar
Answered On : Feb 22nd, 2007

select * from emp where rowid=(select max(rowid) from emp where rownum<26)
Answer Question

Login to rate this answer.


Kiran_kiran
Answered On : Mar 8th, 2007
View all answers by Kiran_kiran
hai

why equality condition does'nt work with rownum, i'm giving my explanation here

the query
select * from emp where rownum=25;

it fetches first record makes it rownum 1 as it does'nt match the where criteria, the record discarded

it fetches 2nd record makes it rownum 1 again


that is why rownum=x does'nt work
Answer Question
2 Users have rated as useful.

Login to rate this answer.


abhi_only12000
Answered On : Jan 7th, 2010
View all questions by abhi_only12000 View all answers by abhi_only12000
select
title, rating from (select title,rating,dense_rank() over(order by title desc) dr from bookshelf) wheredr =2
5;
Answer Question
1 User has rated as useful.

Login to rate this answer.


Teju_hassan
Answered On : Apr 19th, 2011
View all answers by Teju_hassan
select *
from ( select column1,column2,row_number() over(order by rownum asc) abc from table)
where abc=25

The above query can be used to get the row of any number.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11

You'd better use analytic functions, so your managers would think high of you. Besides, those fn-s are
smart and fast. I would not user ROWNUM with ORDER BY as in some examples I see here... THe
ORDER BY will reorder the rows... This is my personal preference.
Code
1. SELECT * FROM ( SELECT deptno, ename, sal
2. , ROW_NUMBER() OVER (ORDER BY sal DESC, ename) AS row_num
3. , RANK () OVER (PARTITION BY deptno ORDER BY sal DESC) rank
4. , DENSE_RANK () OVER (PARTITION BY deptno ORDER BY sal DESC) d_rank FROM emp )
5. WHERE row_num = 4
6. /
Answer Question

Login to rate this answer.


Anonymus
Answered On : Oct 10th, 2011
Hi raghav_sy

Please check before commenting others mistake ahmed's query is perfect.


Answer Question

Login to rate this answer.


mohan
Answered On : Oct 14th, 2011

SELECT * FROM TABLE_NAMEWHERE (ROWID, 0) IN (SELECT ROWID, MOD(ROWID, N) FROM


TABLE_NAME);

how can we avoid duplicate rows. without using distinct command


Asked by: subbaraovangalli | Member Since Mar-2007 | Asked on: Mar 25th, 2007
View all questions by subbaraovangalli View all answers by subbaraovangalli

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 22 of 22 Answers


hindol_saha
Answered On : Mar 27th, 2007
View all questions by hindol_saha View all answers by hindol_saha
Using Self join like :
select dup.column from tab a,tab b where a.dup.column=b.dup.column and a.rowid<>b.rowid
Answer Question

Login to rate this answer.


Shiril Kumar Dubey
Answered On : Mar 27th, 2007
This code is not working perfectly.

select a.deptno
from scott.emp a
, scott.emp b
where a.deptno =b.deptno
and a.rowid<>b.rowid
/
Answer Question
1 User has rated as useful.

Login to rate this answer.


hindol_saha
Answered On : Mar 27th, 2007
View all questions by hindol_saha View all answers by hindol_saha
Ok then try it....

DELETE FROM emp WHERE ROWID NOT IN (SELECT MIN(ROWID) FROM emp GROUP BY id);
Answer Question
1 User has rated as useful.

Login to rate this answer.


hindol_saha
Answered On : Mar 27th, 2007
View all questions by hindol_saha View all answers by hindol_saha
it is working fine........what is the problem.......please describe ..........
select a.*,b.* from emp a, emp b
where a.deptno =b.deptno
and a.rowid<>b.rowid
Answer Question

Login to rate this answer.


subbaraovangalli
Answered On : Mar 28th, 2007
View all questions by subbaraovangalli View all answers by subbaraovangalli
this code is not working to avoid dup. records.
when ever we use 1) a.deptno=b.deptno and
2)a.rowid<>b.rowid then oracle satisfies both conditions due to and operator.
in emp table suppose take 10 as deptno(which is having 3 times in that table)
according to this coding 1)condition satisfies ie both tables having same deptno
2)condition satisfies so that record will not be retrived. so it is satisfied for one record with deptno as
10. what about the remaining two records having deptno as 10. the 2)condition will not satisfies for
these two records thats why these records retrived . (these r duplicate records)
Answer Question

Login to rate this answer.


hindol_saha
Answered On : Apr 5th, 2007
View all questions by hindol_saha View all answers by hindol_saha
suppose u have a table and have data like below:
table (func)
id
--
1
4
3
12
21
2
1
2
21
11
11
then try this u will get all duplicate data
select a.id from func a,func b
where a.id=b.id
and a.rowid<>b.rowid
Answer Question

Login to rate this answer.


MDP
Answered On : Apr 11th, 2007
This query will return the first row for each unique id in the table. This query could be used as part of a
delete statement to remove duplicates if needed.

SELECT ID

FROM func t1
WHERE ROWID = (SELECT MIN (ROWID)
FROM func WHERE ID = t1.ID)

Also: You can use a group by without a summary function


SELECT ID
FROM func t1

GROUP BY id
Answer Question
1 User has rated as useful.

Login to rate this answer.


Mudit Sharma
Answered On : Aug 8th, 2007
Hi,
I think this is not the right query for getting unique values of a column from a table.
Like a table EMP contains the column like DEPTNO having duplicate values.

For getting unique values of DEPTNO query will be like this:

<
select a.DEPTNO from emp a, emp b
where a.deptno=b.deptno
and a.rowid not in (select max(rowid) from emp)
group by a.deptno;
>

Regards
Mudit
Answer Question

Login to rate this answer.


bambino_chakma
Answered On : Aug 12th, 2007
View all answers by bambino_chakma
try this out!

select job from emp


where rowid in(select min(rowid)
from emp
group by job)

regards
Bambino chakma
Answer Question

Login to rate this answer.


sribala30
Answered On : Mar 21st, 2008
View all answers by sribala30
Group By can be used, to avoid duplicates.

Suppose if you have a table "T" with a column "C" having values 1,2,3,4,1,2,3,4.. .. ..

The following query returns unique values:

Select C From T Group By C;


Answer Question
2 Users have rated as useful.

Login to rate this answer.


ashwinee2
Answered On : Apr 10th, 2008
View all answers by ashwinee2
There is a very simple solution to this.

Suppose there is a table emp containing employee ids:


EmpID
1
1
2
2
2
3
3

Now you need to get the value 1,2 and 3

The query should be


SELECT EmpID from emp
group by EMPID

This will return you all distinct rows from the table
Answer Question

Login to rate this answer.


ITsforu
Answered On : Apr 13th, 2008
View all answers by ITsforu
You can use rank analytical function over all rows in your table and partition rows on row number.

select emp_id,ename from ( select emp_id,ename, rank() over (partition byemp


_id,ename order by rowid emp_rank from emp)
twhere emp_rank=1 orderby emp_id,ename
Answer Question

Login to rate this answer.


srinath1102
Answered On : Apr 22nd, 2008
View all answers by srinath1102
Hey guys, Try with UNION .

select 2 from dual


union
select 2 from dual
Answer Question

Login to rate this answer.


satyam_Ora
Answered On : May 6th, 2008
View all questions by satyam_Ora View all answers by satyam_Ora
SQL> select * from emp; ENAME ENO SALARY---------- ---------- ----------abc
1 18000def 2 15000ghi 3 22000abc 1 18000def 2 15000ghi 3
22000 Using Group by function we can avoid the duplicate records instead of using distinct keyword. SQL >
select ename,eno,salary from emp group by ename,eno,salary; ENAME ENO SALARY---------- ---------- ----
------abc 1 18000
def 2 15000
ghi 3 22000

SQL> select distinct * from emp;ENAME ENO SALARY


---------- ---------- ----------
abc 1 18000
ghi 3 22000
def 2 15000
Answer Question

Login to rate this answer.


neha2701
Answered On : May 31st, 2008
View all answers by neha2701
how abt using -

select * from emp a

UNION
select * from emp b;
Answer Question
1 User has rated as useful.

Login to rate this answer.


navin05_06
Answered On : Sep 8th, 2008
View all answers by navin05_06

Use Selfjoin in case of one table and equijoin in case of multiple tables
Answer Question

Login to rate this answer.


kondleravi
Answered On : Sep 9th, 2008
View all answers by kondleravi

select a.no from (tablename) t1 a where rowid notin (select (max(rowid) from t1 b where a.no=b.no)
Answer Question

Login to rate this answer.


sandip01
Answered On : May 24th, 2010
View all questions by sandip01 View all answers by sandip01
select * from emp b
where exists( select * from emp a
where a.name=b.name and
a.rowid > b.rowid)
Answer Question

Login to rate this answer.


neelapu
Answered On : May 27th, 2010
View all answers by neelapu
if u want to see the duplicate values in a column u can use select stmt.

if u wnat to delete the duplicate values in a column u can use delete stmt.

select deptno from emp where rowid not in (select max(rowid) from emp group by deptno);

delete from emp where rowid not in(select max(rowid) from emp group by deptno);
Answer Question

Login to rate this answer.


sandip.dhopat
Answered On : Jun 5th, 2011
View all questions by sandip.dhopat View all answers by sandip.dhopat
Use analytical function as below to delete the duplicate rows.
Delete FROM ROWID IN
(SELECT ROWID FROM
(SELECT ROWID, ROW_NUMBER() OVER (PARTITION BY EMP_NAME ORDER BY EMP_ID) RN
FROM EMP)
WHERE RN > 1));
This will delete the duplicate rows from the emp table on the basis of duplicates in employee name.
Answer Question

Login to rate this answer.


diva
Answered On : Sep 27th, 2011

select dup_col from emp group by dup_col;


Answer Question

Login to rate this answer.


Tauseef
Answered On : Oct 6th, 2011
SELECT FIRST_NAME

FROM EMPLOYEES E

WHERE ROWID = (SELECT MIN (ROWID)


FROM EMPLOYEES WHERE FIRST_NAME = E.FIRST_NAME)

It will check for each row values if it has duplicate then using rowid min of that duplicate will be avoided
Answer Question

Login to rate this answer.

Pragma Init Exception


What is Pragma Init Exception ? what is difference between user defined exception and init pragma
exception. what is the use of it.
Asked by: ily_saravanan | Member Since Oct-2006 | Asked on: Mar 22nd, 2007
View all questions by ily_saravanan View all answers by ily_saravanan

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


Taranjit Kaur
Answered On : Mar 23rd, 2007

Pragma init exception is used to associate a user defined exception with an error number and a custom
message.
Answer Question

Login to rate this answer.


Anil Hadli
Answered On : Mar 23rd, 2007
Pragma Init Exception is the Non predefined exception. It will direct the complier to add the user defined
error message to the oracle error number. It means that there are some predefined error codes which
are not having the error message explicitly the programmer has to give error message for the predefined
error code so the pragma Init Exception will direct the complier to associate the user defined error
message to predefined error codes.

Regards,

Anil Hadli.
Answer Question
1 User has rated as useful.

Login to rate this answer.


NoName
Answered On : Sep 21st, 2007

User-defined exception should be raised explicitly, While Pragma Init exception can be associated with an
Oracle inter error and be raised implicitly
Answer Question

Login to rate this answer.


Sachin Kale
Answered On : Nov 21st, 2007
Pragma is a compiler Directive that is process at compile time, Not at run time.
In pl/sql the Pragma Exception_init tells the compiler to asociate an exception name with an oracle error
number.
That lets you refer to any internal exception by name and to write specific handler for it
when you see an error stack, or sequence of error messages, the one on top that you can trap and
handle
Answer Question
1 User has rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Feb 19th, 2008
You trap a nonpredefined Oracle server error by declaring it first, or by using the OTHERS
handler. The declared exception is raised implicitly. In PL/SQL, the PRAGMA
EXCEPTION_INIT tells the compiler to associate an exception name with an Oracle error
number. That allows you to refer to any internal exception by name and to write a specific
handler for it.

How to disable a trigger for a particular table ?


Suppose if i have 8 triggers declared for a table..how to disable a single trigger from a table...
i don't want to disable all triggers for a table. I know we can disable all triggers by using "alter
table disable all triggers;". just i want to know how to disable single trigger from a table.
Asked by: Interview Candidate | Asked on: Mar 22nd, 2007

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


Pervez
Answered On : Mar 23rd, 2007
use following statement
alter trigger disable
Answer Question
2 Users have rated as useful.

Login to rate this answer.


subbaraovangalli
Answered On : Mar 26th, 2007
View all questions by subbaraovangalli View all answers by subbaraovangalli
to disable a perticular trigger on a table
alter table disable trigger
Answer Question

Login to rate this answer.


Pavan
Answered On : Apr 3rd, 2007
Thanks parweej,
alter trigger <trigger-name> disable
worked for me..

What are the disadvantages of Packages and triggers??


Asked by: Interview Candidate | Asked on: Mar 21st, 2007

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


hari_mech
Answered On : Aug 20th, 2007
View all answers by hari_mech
Disadvantages of Packages:
1. You cannot reference remote packaged variables directly or indirectly..
2. Inside package you cannot reference host variable..
3.
We are not able to grant a procedure in package..
Disadvantages of Trigger:
1. Writing more number of codes..
Answer Question

Login to rate this answer.


Kavitha
Answered On : Nov 18th, 2007
Disadvantages of Triggers

It is easy to view table relationships , constraints, indexes,


stored procedure in database but triggers are difficult to view.

Triggers execute invisible to client-application. They are


not visible or can be traced in debugging code.

It is hard to follow their logic as it they can be fired


before or after the database insert/update happens.

It is easy to forget about triggers and if there is no


documentation it will be difficult to figure out for new developers for their
existence.

Triggers run every time when the database fields are updated
and it is overhead on system. It makes system run slower.

Disadvantage of packages:

Unnecessary module loading.

Unable to load large packages into memory.

Unable to compile large packages.

Lack of synonym support.

No version control.

How do you set table for read only access ?


if i am updating one record in a table at that time no other user can't able insert ,update the record in
same table How is it possible
Asked by: nitin_kumat | Member Since May-2006 | Asked on: Mar 20th, 2007
View all questions by nitin_kumat View all answers by nitin_kumat

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


ily_saravanan
Answered On : Mar 25th, 2007
View all questions by ily_saravanan View all answers by ily_saravanan

If you update or delete the records in the table, at the same time, no body can update or delete the
same records which you updated or deleted because oracle lock the data which u updated or deleted.
Answer Question

Login to rate this answer.


sandeep katta
Answered On : Apr 20th, 2007

You can use view for this purpose because you can set view as read only.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 3rd, 2008
View all answers by krishnaindia2007
If a transaction is updating data in a database, it gets an exclusive lock on that part of the database. No
other transaction can read or change this data.
Answer Question

Login to rate this answer.


sippsin
Answered On : Jul 22nd, 2008
View all answers by sippsin
you can select the table for updation

for eg: select * from emp for update;

no you can do the update/insert anything you want...

any other user or session would be able to do any insert/update to the same table only after you release
the table by commit or rollback.....
Answer Question
1 User has rated as useful.

Login to rate this answer.


dinesh.smhdr
Answered On : May 11th, 2011
View all answers by dinesh.smhdr

alter table tablename read only;


Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11
Specify READ ONLY to put the table in read-only mode. When the table is in READ ONLY mode, you
cannot issue any DML statements that affect the table or any SELECT ... FOR UPDATE statements. You
can issue DDL statements as long as they do not modify any table data. Operations on indexes
associated with the table are allowed when the table is in READ ONLY mode.
Specify READ WRITE to return a read-only table to read/write mode.

Read only:
ALTER TABLE SALES READ ONLY;

Back to read/write:
ALTER TABLE SALES READ WRITE;
Answer Question

Login to rate this answer.


priya dharan raj
Answered On : Nov 15th, 2011
View all answers by priya dharan raj
just grant select previlage on that particular table
Answer Question

Login to rate this answer.


velan
Answered On : Sep 11th, 2012
There are couple of ways
1) If there are user other than owner accessing this table then you can "grant select on TABLE_NAME"
2) Otherwise you DBA can create a role which will have only the privillege to only create table and assign
this role to the user then even the owner of the table cannot manipulate the table data.

what is the use of nocopy parameter in oracle procedure


Hi,
What is nocopy parameter in oracle procedure. what is the use of it. In which situation,we can use the
nocopy parameter.
Thanks,
Saravanan.P
Asked by: ily_saravanan | Member Since Oct-2006 | Asked on: Mar 19th, 2007
View all questions by ily_saravanan View all answers by ily_saravanan

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 11 of 11 Answers


subbaraovangalli
Answered On : Mar 26th, 2007
View all questions by subbaraovangalli View all answers by subbaraovangalli
no copy parameter is an argument in a procedure
it says to oracle to pass the variable value back to the user as quickly as possible.
Answer Question

Login to rate this answer.


Jegadeesan
Answered On : Mar 26th, 2007
NOCOPY is a IN OUT COPY Which is used avoid the overhad of copying IN OUT Parameter Values. If
IN OUT parameter returns huge records we can specify the NOCOPY to copy the values.

The PLSQL Engine first makes a copy of the record and then during program executing makes a
changes to that copy.

Regards
Jegadeesan
Answer Question

Login to rate this answer.


tharik
Answered On : Mar 27th, 2007
View all answers by tharik

NOCOPY will instruct Oracle to pass the argument as fast as possible. This can significantly enhance
performance when passing a large value.
Answer Question

Login to rate this answer.


vmahawar
Answered On : Apr 18th, 2007
NOCOPY Parameter in Oracle Procedure is used to pass arguments to the any procedure and function as
Reference to improve the performance of the code.
This is done in case the arguments like records, pl/sql tables are passed to the called procedures.
Answer Question

Login to rate this answer.


sippsin
Answered On : Jul 22nd, 2008
View all answers by sippsin
Ussually IN paramter is pass by value and OUT/IN OUT are pass by refererence....

If one wants to send the IN paramter too as pass by reference he could add NOCOPY
parameter....

advantage is always less memory usage

disadvantage is when there is a change happened to the Reffered value and a rollback occurs in the
procedure the change of value would be retained.... it could not be rolled back....

so I beleive that it is always safe to work without the NOCOPY parameter.....


Answer Question

Login to rate this answer.


ratna82
Answered On : Oct 10th, 2008
View all answers by ratna82

When a parameter is passed as an IN variable, it is passed by reference. Since it will not change, PL/SQL
uses the passed variable in the procedure/function. When variables are passed in OUT or INOUT mode,
a new variable is define, and the value is copied to the passed variable when the procedure ends. If the
variable is a large structure such as a PL/SQL table or an array, the application could see a performance
degradation cause by copying this structure.
The NOCOPY clause tells to PL/SQL engine to pass the variable by reference, thus avoiding the cost of
copying the variable at the end of the procedure. The PL/SQL engine has requirements that must be met
before passing the variable by reference and if those requirements are not met, the NOCOPY clause will
simply be ignored by the PL/SQL engine.
Answer Question
1 User has rated as useful.

Login to rate this answer.


amianan
Answered On : Nov 10th, 2008
View all answers by amianan

TO PASS OUT AND INOUT Parameters by refrenece instead of value.


Answer Question

Login to rate this answer.


vanishavadlya
Answered On : Oct 29th, 2009
View all answers by vanishavadlya

Three types of parameter modes


1) IN parameter mode- This mode is used to pass values to the calling module when invoked. The value
of IN parameter can't be changed in the module.

2) OUT parameter mode -This mode is used to return a value to the main block. The value of OUT
parameter can change anywhere in the program.
3) IN OUT parameter mode-This mode is used to pass values to the calling module and return a value to
the main block. The value of IN OUT parameter can change anywhere in the program.

In Call By value, the copy of actual parameter is passed to the formal parameter, So any changes to the
formal parameter doesn't affect the actual parameter.

In Call By reference, the address of actual parameter is passed to the formal parameter, so any changes
to the formal parameter will change the actual parameter also, because both of them are pointing to the
same memory location. Here no copying is required.

The IN parameter is passes by reference, so we can't change the value of IN parameter inside the
module, It acts as a constant, But the OUT and IN OUT parameters are passed by value, we can change
the values of OUT & IN OUT parameters if you use the hint NOCOPY with OUT Parameter and IN OUT
Parameter then ::: call by reference

Answer Question
2 Users have rated as useful.

Login to rate this answer.


debjit20
Answered On : Apr 8th, 2010
View all answers by debjit20
When a parameter is passed as an IN variable, it is passed by reference. Since it will not change, PL/SQL
uses the passed variable in the procedure/function. When variables are passed in OUT or INOUT mode, a
new variable is define, and the value is copied to the passed variable when the procedure ends. If the
variable is a large structure such as a PL/SQL table or an array, the application could see a performance
degradation cause by copying this structure. The NOCOPY clause tells to PL/SQL engine to pass the
variable by reference, thus avoiding the cost of copying the variable at the end of the procedure. The
PL/SQL engine has requirements that must be met before passing the variable by reference and if those
requirements are not met, the NOCOPY clause will simply be ignored by the PL/SQL engine.
Answer Question

Login to rate this answer.


ptmich
Answered On : Feb 28th, 2012
View all answers by ptmich

sipsin: Actually the reverse is true. Usually the IN parameter is passed by reference and the OUT/IN OUT
parameters are passed by value.
Answer Question

Login to rate this answer.


Saket
Answered On : Apr 3rd, 2012
Pass by reference: "IN" Case
Pass by value : "Out" or "IN OUT" Case which have the overhead of copying the value to new procedure
parameter.
In order to make to Pass by reference we will use NOCOPY
Pass by reference: "OUT NOCOPY" or "IN OUT NOCOPY" which deals which the actual reference value.
Answer Question

Login to rate this answer.


Himansu
Answered On : Nov 6th, 2012
In procedure,Function there are three types of parameter is there. eg-IN, OUT, INOUT.
IN parameter is call by reference and OUT & INOUT are call by value. Always call by reference is faster
than call by value. We use NOCOPY to convert call by value to call by reference.

Actually it is more useful when we are passing a large record or a large table.

how to avoid the mutating error with sample program


Hi,
can any body give me the sample program for avoiding the mutating error. we can avoid the mutating
through the statement level trigger instead of using the statement leve trigger, i need one sample
program to avoid the mutating error by using pl/sql table.

Thanks
Saravanan.P
Asked by: ily_saravanan | Member Since Oct-2006 | Asked on: Mar 19th, 2007
View all questions by ily_saravanan View all answers by ily_saravanan

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


KiranKW
Answered On : May 2nd, 2007
View all answers by KiranKW
A mutating error comes when u r trying to do some DML operation on a table that owns the trigger....
there are a lot of options to avoid mutation .. eg, Making it autonomous transaction or making it a
statement level trigger ... or using temporary table... the following example gives how to use temporary
pl/sql table to avoid mutation error :
create table CUG (
id_cug number(12) not null primary key,
id_B number(12) not null,
type number(1),
foreign key (id_B) references CUG (id_cug)
on delete cascade);
Next we create a temporary table to avoid the "Mutating Table Problem".
drop table CUGTMP;
create global temporary table CUGTMP (
id_B number(12),
type number(1))
on commit delete rows;
The following trigger checks new rows (Inserts) in CUG
create or replace trigger bi_r
before insert on CUG
for each row
declare
l_type CUG.type%type;
begin
if (:new.type in (3,4)) then
select type into l_type from CUG
where id_cug = :new.id_B;
end if;
if (l_type != 2) then
raise_application_error(-20002,
'C and D CUGs must have a leading B');
end if;
end;
/
The following Trigger saves the new values for id_B in the temporary table.
create or replace trigger au_r
after update of id_B on CUG
for each row
begin
insert into CUGTMP (id_B,type)
values (:new.id_B,:new.type);
end;
/
The following Trigger finally checks, that C and D CUGs belong to a B CUG.
create or replace trigger au_s
after update of id_B on CUG
declare
l_id_B number(12);
l_typeCD number(1);
l_typeB number(1);
cursor cur_cugtmp is
select id_B,type
from CUGTMP;
begin
open cur_cugtmp;
loop
fetch cur_cugtmp into l_id_B,l_typeCD;
exit when cur_cugtmp%notfound;
select type into l_typeB from CUG
where id_cug = l_id_B;
if (l_typeB != 2) then
raise_application_error(-20002,
'C and D CUGs must have a leading B');
end if;
end loop;
close cur_cugtmp;
end;
/
Test insert and update
insert into CUG (id_cug,id_B,type)
values (0,0,0);
insert into CUG (id_cug,id_B,type)
values (1,0,2);
insert into CUG (id_cug,id_B,type)
values (2,0,2);
insert into CUG (id_cug,id_B,type)
values (3,1,3);
insert into CUG (id_cug,id_B,type)
values (4,2,3);
insert into CUG (id_cug,id_B,type)
values (5,1,4);
insert into CUG (id_cug,id_B,type)
values (6,2,4);
commit;
SQL> select * from CUG;
ID_CUG ID_B TYPE
---------- ---------- ----------
0 0 0
1 0 2
2 0 2
3 1 3
4 2 3
5 1 4
6 2 4
Now, we want that that the CUGs 3,4,5,6 changes the leadership to CUG 2
SQL > update CUG set id_B = 2 where id_cug in (3,4,5,6);

4 rows updated.
SQL> select * from cug;
ID_CUG ID_B TYPE
---------- ---------- ----------
0 0 0
1 0 2
2 0 2
3 2 3
4 2 3
5 2 4
6 2 4
Next we delete the "Leader" with ID_CUG = 2. All childs must be deleted automatically with the DELETE
CASCADE.
SQL> select * from cug;
ID_CUG ID_B TYPE
---------- ---------- ----------
0 0 0
1 0 2
Everything looks fine - cool isn't it ?

What is difference between PL/SQL tables and arrays?


Asked by: Interview Candidate | Asked on: Mar 7th, 2007

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


jaswanthi.p
Answered On : Mar 8th, 2007
View all answers by jaswanthi.p

array is set of values of same datatype.. where as tables can store values of diff datatypes.. also tables
has no upper limit where as arrays has.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 8th, 2008
View all answers by krishnaindia2007
PL/SQL tables are temporary array like objects used in a PL/SQL Block. The size of pl/sql table is
unconstrained. For varrays we need to specify upperbound.

Pl/sql tables can not be stored in database where as varrays can be stored in database.

We can use negetive index for pl/sql tables. In varrays negetive index is not allowed.

In pl/sql tables data need not be stored in consecutive rows. Varrays are dense and retain their order
while storing in database.

You can not perform DML operations on PL/SQL table . DML operations can be performed on Varrays.

In PL/SQL if we write select statement with INTO clause it may return two
exceptions NO_DATA_FOUND or TOO_MANY_ROW . To do you avoid these
execeptions. How do you write SQL statement in alternative way?
Asked by: ddkdhar | Member Since Jun-2006 | Asked on: Mar 1st, 2007
View all questions by ddkdhar View all answers by ddkdhar

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


Nikhil_4_Oracle
Answered On : Mar 5th, 2007

hi all,

there is no other way for NO_DATA_FOUND and TOO_MANY_ROWS


Exception. Just handle them by using Oracle Exception Handler

i.e
-------------
------------
----------
Exception
when NO_DATA_FOUND then
Dbms_output.put_line('No Record');
---------
-----------
-------------

Regards,

Nikhil.
Answer Question

Login to rate this answer.


Nikhil_4_Oracle
Answered On : Mar 6th, 2007
HI All,

There is no solution for NO_DATA_FOUND else you handle it using Exception block as i

do above...

well TOO_MANY_ROWS is programming fault, when


your select query

uses "=" operator then may be there is Too_many_rows exception, to avoid this

always use "IN" operator in u r select Query.

i.e

select empno, ename into eid, enam from emp

where deptno IN (select deptno from emp where sal>3000);

Thanks,
Nikhil.
Answer Question

Login to rate this answer.


mala
Answered On : Mar 17th, 2007
Hi All,

Yes you can handle Too_Many_Rows exception when you are writing into a PL/SQL block SELECT...INTO
statement.

Just write the SELECT...INTO statement in a CURSOR.

Regards.
Mala
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 5th, 2008
PL/SQL manages these errors by raising standard exceptions, which you can trap in the exception section
of the block with the NO_DATA_FOUND and TOO_MANY_ROWS exceptions. Code SELECT statements
to return a single row.

Answer Question

Login to rate this answer.


4e671d1f5972f2fe1d8a3215db5167fd
Answered On : May 8th, 2008
View all answers by 4e671d1f5972f2fe1d8a3215db5167fd
You may avoid too_many_rows exception using CURSORS.

In cursors if NO_DATA_FOUND then it will not raise any exception. In cursors you need to handle it using
%FOUND or %NOTFOUND cursor attributes.

Answer Question

Login to rate this answer.


binurajnair
Answered On : Jul 30th, 2008
View all answers by binurajnair
If you don't want an excpetion to be raised on a SELECT statement, you can avoid executing the
statement by having a count just before the SELECT as shown below

SELECT count(rowid)
into v_count
from tables
where conditions.

if(v_count = 1) then
SELECT column
into v_column
from tables
where conditions;
else
--Select statement not executed because it will throw exception
v_column=dummy_value;
end if;

However it is a much better practice to handle these errors using exceptions

Answer Question

Login to rate this answer.


vnraos
Answered On : Sep 5th, 2008
View all answers by vnraos
First, let us understand why these errors cropup.

1) NO_DATA_FOUND - is raised only for "select into" statements when the where clause of the query
does not match any rows.

2)TOO_MANY_rows - is raised if a "select into" statement matches more than one row.

Solution for 1- In the exception section use a handlerlike this "when no_data_found theninsert into
log_error ('no matching data')".

for 2) - This is a result of poor design or programming. One need to use a cursor.

Without closing the cursor, If you want to open it what will happen. If error, get
what is the error?
Asked by: ddkdhar | Member Since Jun-2006 | Asked on: Mar 1st, 2007
View all questions by ddkdhar View all answers by ddkdhar

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


madhaviguthula
Answered On : Mar 5th, 2007
View all answers by madhaviguthula

If you reopen a cursor without closing it first,PL/SQL raises the predefined exception
CURSOR_ALREADY_OPEN.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Sirisha
Answered On : Sep 9th, 2007

It is legal to open an already opened cursor. When we try to open an already opened cursor, the cursor
when it is initially opened is automatically closed and again opened.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 3rd, 2008
View all answers by krishnaindia2007
It throws error message
ORA-06511: PL/SQL: cursor already open
Answer Question

Login to rate this answer.


ratna82
Answered On : Oct 10th, 2008
View all answers by ratna82

CURSOR_ALREADY_OPEN ORA-06511 An attempt was made to open a cursor that was already open.
Answer Question

Login to rate this answer.


msenthil19
Answered On : Mar 18th, 2009
View all answers by msenthil19

Error will be like "Cursor already open"


In function and procedure the parameter pass is "call by value" or "call by
reference"?
Asked by: ddkdhar | Member Since Jun-2006 | Asked on: Mar 1st, 2007
View all questions by ddkdhar View all answers by ddkdhar

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


Nikhil_4_Oracle
Answered On : Mar 5th, 2007

HI,

IN :
is default Param and always Pass By Value, in case of IN Parma Default
value is possible

i.e
Create or replace procedure Cal_Comm
(did in emp.deptno%type Default 20)

is possible.

OUT , IN OUT :

Are by reference , here Default value is not possible.

Tanx

NIKHIL
Answer Question

Login to rate this answer.


deep_paudel
Answered On : Mar 12th, 2007
View all answers by deep_paudel
IN params are by default pass by references.
IN OUT & OUT params are by default pass by value.
One can pass IN OUT/OUT by references using NOCOPY option.
e.g. p_return OUT NOCOPY varchar2 .
Answer Question
4 Users have rated as useful.

Login to rate this answer.


Rup
Answered On : Aug 30th, 2007

Can anyone please explain the same. The above two answers are contradictory.
Answer Question

Login to rate this answer.


malik.aman
Answered On : Dec 4th, 2007
View all answers by malik.aman
IN: Call by reference
OUT: call by value, Exception is with the use of NOCOPY, when nocopy is used oracle knows that it
should not copy the values back and use the reference to the same memory area
Answer Question
1 User has rated as useful.

Login to rate this answer.


ashwinee2
Answered On : Apr 10th, 2008
View all answers by ashwinee2
Take this:

IN parameters are passed by reference, so the value cannot be changed in the procedure and functions.
Out and IN-OUT parameters are passed by value, so the values can be changed inthe procedures and
fucnctions.
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 3rd, 2008
View all answers by krishnaindia2007
IN :- actual parameter is passed by reference (a pointer to the value is passed in)
OUT:- actual parameter is passed by value (a copy of the value is passed out) unless NOCOPY is specified

INOUT :- actual parameter is passed by value (a copy of the value is passed in and out) unless NOCOPY
is specified

Is it possible create table in procedure or function? If Not Why?


Asked by: ddkdhar | Member Since Jun-2006 | Asked on: Mar 1st, 2007
View all questions by ddkdhar View all answers by ddkdhar

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


Nikhil_4_Oracle
Answered On : Mar 5th, 2007

Hi,

Its possible to create a table using procedures.


There are two ways,

#1
Use PRAGMA AUTONOMOUS_TRANSACTION;

Code:
Create or replace procedure Create_tab
As
PRAGMA AUTONOMOUS_TRANSACTION;
Begin
EXECUTE IMMEDIATE
‘Create TABLE ProcT(col1 number(2), col2 varchar2(10))’;
End;

#2

Use Dbms_sql Package

Code:

Create or Replace procedure Dynamic_Tab

(TabName in varchar2)

as

V_cursor INTEGER;
Ddl_Execute INTEGER;

begin

V_cursor:=Dbms_sql.Open_cursor;

Dbms_sql.Parse(V_cursor,'Create Table '||TabName||' (col1 number(2),col2 varchar2

(10))',Dbms_sql.native);

Ddl_Execute:=dbms_sql.Execute(V_cursor);

Dbms_output.put_line(TabName||' Created.');

If Dbms_sql.Is_open(V_cursor) then

Dbms_sql.Close_cursor(V_Cursor);

end if;

Exception

when Others then

Dbms_output.put_line(sqlerrm);

End Dynamic_Tab;

Regards,
Nikhil (iflex).

Explain, Is it possible to have same name for package and the procedure in that
package.
Asked by: Interview Candidate | Asked on: Feb 25th, 2007

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


bhushan_nemade
Answered On : Feb 26th, 2007

Yes, its possible to have same name for package and the procedure in that package.
Answer Question

Login to rate this answer.


samareshp
Answered On : Apr 22nd, 2009
View all answers by samareshp

yes its possible.

what is dense_rank function and it's usage ?


Asked by: ddkdhar | Member Since Jun-2006 | Asked on: Feb 16th, 2007
View all questions by ddkdhar View all answers by ddkdhar

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


Sangeeta Shukla
Answered On : Feb 19th, 2007

A dense_rank fn is similar to Rank fn except for a difference that it does not skip sequential ranking
numbers. If two values are the same and have same rank for ex. 3, then in dense_rank fn the next non
duplicate value will be ranked 4. In normal Rank fn, the next non duplicate value would have
been ranked 5 .
Answer Question
1 User has rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Feb 5th, 2008
Rank Function can cause non-consecutive rankings if the tested values are the same. Whereas,
thedense_rank function will always result in consecutive rankings.
Answer Question

Login to rate this answer.


Teju_hassan
Answered On : Apr 20th, 2011
View all answers by Teju_hassan
See the below example to understand better.

select dense_rank,rank,sal
from emps
order by sal desc

dense_rank|rank|sal
1 1 10000
2 2 5000
2 2 5000
4 3 4000

In the above example you can see that in the dense_rank function if there is a tie then the next position
will be skipped and in the rank function the count start from the next position.
what is diff between strong and weak ref cursors
Asked by: ddkdhar | Member Since Jun-2006 | Asked on: Feb 16th, 2007
View all questions by ddkdhar View all answers by ddkdhar

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


klnreddy
Answered On : Feb 19th, 2007
A strong REF CURSOR type definition specifies a return type, but a weak definition does not.

DECLARE
TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; -- strong
TYPE GenericCurTyp IS REF CURSOR; -- weak
Answer Question

Login to rate this answer.


Parag Sathe
Answered On : Feb 26th, 2007

Strong Ref cursor type is less Error prone, because oracle already knows what type you are going to
return as compare to weak ref type.
Answer Question

Login to rate this answer.


askvenki
Answered On : Jul 20th, 2007
View all answers by askvenki
A strong REF CURSOR type definition specifies a return type, but a weak definition does not.
DECLARE
TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; -- strong
TYPE GenericCurTyp IS REF CURSOR; -- weak
in a strong cursor structure is predetermined --so we cannot query having different structure other than
emp%rowtype
in weak cursor structure is not predetermined -- so we can query with any structure
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Baji Shaik
Answered On : Jun 5th, 2011
View all answers by Baji Shaik

strong ref cursor return value, but seek ref cursor it can't return any value

how to insert a music file into the database


Asked by: rakheeviyyapu | Member Since Mar-2006 | Asked on: Feb 15th, 2007
View all questions by rakheeviyyapu

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


Innila
Answered On : Mar 2nd, 2007
View all answers by Innila

LOB datatypes can be used to store blocks of unstructured data like graphic images, video, audio, etc

What are the Limitations of Packages,views,procedures?


What is the maximum number of subprograms inside a package?
Asked by: Interview Candidate | Asked on: Jan 30th, 2007

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


geetha24
Answered On : Feb 9th, 2007
View all questions by geetha24 View all answers by geetha24

There is no limitation on the number of Subprograms in the package, but there is a limitation on the
compiled file size in the database .

what is the order of execution if there is a statement level and row level trigger on
a same table?
Asked by: Interview Candidate | Asked on: Jan 30th, 2007

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


xxxx
Answered On : Jan 31st, 2007
Always the statement level trigger executes first on a tablexxx
Answer Question

Login to rate this answer.


Faizal
Answered On : Feb 26th, 2007
The Order will be:

Before Statement level


Before Row level
After Row level
After Statement level
Answer Question
2 Users have rated as useful.

Login to rate this answer.


jagadeesh9
Answered On : Feb 24th, 2008
View all questions by jagadeesh9 View all answers by jagadeesh9
Trigger firining sequence:
1) Before statement level triggers, if present

2) For each statement


a) Before row level triggers, if present
b)Statement itself
c)After row level triggers, if present

3) After statement level triggers


Answer Question

Login to rate this answer.


binurajnair
Answered On : Feb 28th, 2008
View all answers by binurajnair
Just a small correction,

Trigger firining sequence:


1) Before statement level triggers, if present

2) For each row

a) Before row level triggers, if present


b)Statement itself
c)After row level triggers, if present

3) After statement level triggers


Answer Question

Login to rate this answer.


delhi_ratnesh
Answered On : Mar 14th, 2008
View all answers by delhi_ratnesh

The correct order is as below.

Trigger firing sequence:

1) Before statement level triggers, if present

2) For each row

a) Before row level triggers, if present

b) After row level triggers, if present

3) Actual Statement

4) After statement level triggers

create table d(col1 number primary key)

create table c(col1 number references d(col1))

create or replace trigger c_b4sttmnt

before insert on c

declare

vnum number;

begin

dbms_output.put_line('c_b4sttmnt');

end;

create or replace trigger c_aftrsttmnt

after insert on c

declare

vnum number;
begin

dbms_output.put_line('c_aftrsttmnt');

end;

create or replace trigger c_aftrrow

after insert on c

for each row

declare

vnum number;

begin

dbms_output.put_line('c_aftrrow');

end;

create or replace trigger c_b4row

before insert on c

for each row

declare

vnum number;

begin

dbms_output.put_line('c_b4row');

end;

Please execute the following command which will fail after first 3 triggers.

insert into c values(1);

c_b4sttmnt

c_b4row

c_aftrrow
ORA-02291: integrity constraint (STAGE.SYS_C0049041) violated - parent key not
found

Regards

- BHAILOGONLINE
Answer Question

Login to rate this answer.


samareshp
Answered On : Apr 22nd, 2009
View all answers by samareshp
Order of triggre firing :::::::

Before Statement level


Before Row level
After Row level
After Statement level

Answer Question

Login to rate this answer.


Baji Shaik
Answered On : Jun 5th, 2011
View all answers by Baji Shaik
the orders of triggers execution is like this

1.before statement level


2.before row level
3. after row level
4 after statement level

Can we have same trigger with different names for a table?

eg: create trigger trig1


after insert on tab1;

and

eg: create trigger trig2


after insert on tab1;

If yes,which trigger executes first.


Asked by: Interview Candidate | Asked on: Jan 30th, 2007

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 13 of 13 Answers


bibin
Answered On : Feb 8th, 2007

Yes you can have . This is because the triggers dont share the same namespace for tables.whereas
funtions,procedures,tables etc share the same namespace.so they cant have the same name
Answer Question

Login to rate this answer.


geetha24
Answered On : Feb 9th, 2007
View all questions by geetha24 View all answers by geetha24

Yes you can have..but you cannot predict the order of the execution.
Answer Question

Login to rate this answer.


Nikhil_4_Oracle
Answered On : Mar 7th, 2007
Hi all,

i think the Question is ask in wrong way,


--> create trigger trig1
--> create trigger trig2
(both
are diff triggers on same table tab1)
its always possible...since oracle allows 12 triggers/table.
but if
you trying to do,
create trigger trigg1
after insert on emp
**************
create trigger trigg1
after update on emp
then There is An Error,-->"trigg1 already exits".
since Triggers are Stored objects in oracle, like u r stored procedures and functions..
Regards,

Nikhil - i-flex

Answer Question

Login to rate this answer.


prabha0508
Answered On : May 4th, 2007
Yes we can create trigger on same event with different names but cannot predict which trigger is
executed.

for example:
create or replace trigger trigg1
before delete on emp
begin
raise_application_error(-20001,'Delete not allowed');
end;

create or replace trigger trigg2


before delete on emp
begin
raise_application_error(-20001,'Deletion is not allowed');
end;

SQL> delete from emp;


delete from emp
*
ERROR at line 1:
ORA-20001: Deletion is not allowed
ORA-06512: at "SCOTT.TRIGG2", line 2
ORA-04088: error during execution of trigger 'SCOTT.TRIGG2'

Prabha Sharma
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Ritesh
Answered On : Jun 6th, 2007
Hi,
The triggers will be fired on the basis of TimeStamp of their creation in Data Dictionary. The trigger with
latest timestamp will be fired at last.

Ritesh
Answer Question
2 Users have rated as useful.

Login to rate this answer.


kperumal75
Answered On : Feb 26th, 2009
View all questions by kperumal75 View all answers by kperumal75

Yes we can. The same effect is produced twice.


Answer Question

Login to rate this answer.


manish.baehal
Answered On : Apr 5th, 2009
View all answers by manish.baehal
We can have same trigger with different names for a table

The triggers will be fired on the basis of TimeStamp of their creation in Data Dictionary. The trigger with
latest timestamp will be fired at last.

Regards,
Manish kumar
Answer Question

Login to rate this answer.


nevinalencherry
Answered On : Apr 6th, 2009
View all answers by nevinalencherry
Yes, we can decide which trigger should fire first, if two triggers are defined with the same timing point.

Eg: create trigger trig2


after insert on tab1
for each row
FOLLOWS trig1;

create trigger trig1


after insert on tab1
for each row;

Here trig2 will fire after trig1.


This is available on Oracle 11g onwards ONLY.
Answer Question
Login to rate this answer.
panky10
Answered On : Apr 13th, 2009
View all answers by panky10
Yes, you can very well have a trigger on a single table performing the same operation but with different
names.

The trigger which has the latest timestamp will be executed first and then followed by the others in the
order of their creation :)
Answer Question
1 User has rated as useful.

Login to rate this answer.


samareshp
Answered On : Apr 22nd, 2009
View all answers by samareshp
yes we can create the Triggers,,

Firing sequence is inreverse order of creation

say ::
m trigger ---created last fires first.
a trigger
z trigger
ttt trigger
tt trigger-- created first fires last
Answer Question

Login to rate this answer.


imranbaig.geek
Answered On : Dec 2nd, 2009
View all answers by imranbaig.geek

The trigger which is newly created will be fired first then the old trigger
Answer Question

Login to rate this answer.


Baji Shaik
Answered On : Jun 5th, 2011
View all answers by Baji Shaik
yes, we cant said upto 10g oracle server executes the triggers randomly,

but 11g we are having a feature follows clause,by using this we have to control the execution of triggers
explicitly by the developer,

syntax: create or replace trigger trig1


after insert on tab1;

create trigger trig2


after insert on tab1
follows trig1
Answer Question

Login to rate this answer.


MURTHY
Answered On : Sep 7th, 2011
the question is very nice.

yes we can have 2 triggers with same body but with different names.

ex: create trigger trg1


....................
...............................
end;

create trigger trg2


....................
...............................
end;
but the latest trigger will be executed first that means trg2 will execute first then trg1.

pls check it. and intimate me if any mistakes

What will happen to an anonymus block,if there is no statement inside the block?

eg:-
declare

begin

end;

Asked by: Interview Candidate | Asked on: Jan 22nd, 2007

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


zhu1
Answered On : Jan 23rd, 2007

Elapsed: 00:00:00.01system@vicdw_vicwarehouse01> declare 2 3 begin 4 5 end; 6 /end;*ERROR at line


5:ORA-06550: line 5, column 1:PLS-00103: Encountered the symbol "END" when expecting one of the
following:begin case declare exit for goto if loop mod null pragmaraise return select update while
with <pipeElapsed: 00:00:00.03system@vicdw_vicwarehouse01>
Answer Question
1 User has rated as useful.

Login to rate this answer.


User
Answered On : Jan 24th, 2007

An error is encountered.
Answer Question

Login to rate this answer.


geetha24
Answered On : Feb 9th, 2007
View all questions by geetha24 View all answers by geetha24

Compilation error will be raised. You can have Begin NULL;End;


Answer Question
3 Users have rated as useful.

Login to rate this answer.


Chiranjit Dutta
Answered On : Feb 27th, 2007
We cant have
declare
begin
end
we must have something between the begin and the end keywords
otherwise a compilation error will be raised.
Answer Question
1 User has rated as useful.

Login to rate this answer.


visitor
Answered On : Jul 3rd, 2007

If you do not want any executable statement within the begin-end block, you can include a null statment.

eg:

begin
null;
end;

Wheather a Cursor is a Pointer or Reference?


Asked by: Interview Candidate | Asked on: Jan 17th, 2007

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


saurabh kumar verma
Answered On : Jan 19th, 2007

cursor is basically a pointer as it's like a address of virtual memory which is being used storage related
tosql query & is made free after the values from this memory is being used.

what happens when commit is given in executable section and an error occurs
?please tell me what happens if exception block is committed at the last?
Asked by: Interview Candidate | Asked on: Jan 8th, 2007

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


vikrant
Answered On : Jan 21st, 2007

all the transactions done by that executable section will be rolled back
Answer Question

Login to rate this answer.


raghav_sy
Answered On : Feb 7th, 2007
View all answers by raghav_sy

well the answer is, what ever done in executable section will be lost. u can see the exapmle:created table
d as below:SQL > create table d ( sl number(4), name varchar2(5));now do the following
operation:SQL> begin insert into d values ('1223123123','geekinterview'); --making insert to fail here
commit; exception --catching the exception here when others then commit; end; /PL/SQL procedure
successfully completed.now if we use :SQL> select * from d; no rows selectedso even the pl/sql
procedure completed successfully no values were saved in d.this is one case where we are giving invalid
values for both the fields(in insert stmt.). now see the below procedure:SQL> begin insert into d values
('1223123123','RSY'); --first value is incorrect, second is correct one commit; exception when others then
commit; end; /PL/SQL procedure successfully completed.SQL> select * from d; no rows selectedeven in
this case, nothinghas been inserted in table d. even though value for name field is a valid data.now there
is one possible case:SQL> begin insert into d values ('123','RSY'); --both values are correct commit; --
commiting first time insert into d values ('1223123123','RSY'); --entering values to fail insert commit;
exception --handling exception when others then commit; end; /PL/SQL procedure successfully
completed.SQL> select * from d; SL NAME--------- ----- 123 RSYso here the first insert has been
committed, but at the time of second insert the condition fails, so second insert is roll backed. but it will
not affect data that has been already committed.ok take carecheersRSY
Answer Question

Login to rate this answer.


raghav_sy
Answered On : Feb 8th, 2007
View all answers by raghav_sy

hi ,again am posting the same answer, i do not know why the answer is not displayed with proper
formatting. ok once more i will try:well the answer is, what ever done in executable section will be lost. u
can see the exapmle:created table d as below:SQL> create table d ( sl number(4), name
varchar2(5));now do the following operation:SQL> begin insert into d values
('1223123123','geekinterview'); --making insert to fail here commit; exception --catching the exception
here when others then commit; end; /PL/SQL procedure successfully completed.now if we use :SQL>
select * from d; no rows selectedso even the pl/sql procedure completed successfully no values were
saved in d.this is one case where we are giving invalid values for both the fields(in insert stmt.). now see
the below procedure:SQL> begin insert into d values ('1223123123','RSY'); --first value is incorrect,
second is correct one commit; exception when others then commit; end; /PL/SQL procedure successfully
completed.SQL> select * from d; no rows selectedeven in this case, nothinghas been inserted in table d.
even though value for name field is a valid data.now there is one possible case:SQL> begin insert into d
values ('123','RSY'); --both values are correct commit; --commiting first time insert into d values
('1223123123','RSY'); --entering values to fail insert commit; exception --handling exception when others
then commit; end; /PL/SQL procedure successfully completed.SQL> select * from d; SL NAME --------- ---
-- 123 RSYso here the first insert has been committed, but at the time of second insert the condition fails,
so second insert is roll backed. but it will not affect data that has been already committed.ok take
carecheersRSY
Answer Question

Login to rate this answer.


geetha24
Answered On : Feb 9th, 2007
View all questions by geetha24 View all answers by geetha24

Whenever the exception is raised ..all the transaction made before will be commited. If the exception is
not raised then all the transaction will be rolled back.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


ae_sathis
Answered On : Feb 24th, 2008
View all answers by ae_sathis

SQL> create table d ( sl number(4), name varchar2(5));


now do the following operation:
SQL> begin insert into d values ('1223123123','geekinterview');
--making insert to fail here commit; exception

--catching the exception here when others then

commit;

end;

/
PL/SQL procedure successfully completed.
now if we use :
SQL> select * from d;
no rows selected so even the pl/sql procedure completed successfully no values were saved in d.

this is one case where we are giving invalid values for both the fields in insert stmt.).

now see the below procedure:


SQL> begin insert into d values ('1223123123','RSY');
--first value is incorrect, second is correct one commit;

exception when others then

commit;

end;

/
PL/SQL procedure successfully completed.
SQL> select * from d;
no rows selected even in this case, nothing has been inserted in table d.

even though value for name field is a valid data. now there is one possible case:
SQL> begin insert into d values ('123','RSY');
--both values are correct commit;

--committing first time insert into d values ('1223123123','RSY');

--entering values to fail insert commit; exception

--handling exception when others then commit;

end;

/
PL/SQL procedure successfully completed.
SQL> select * from d;
SL NAME
--------- -----
123 RSY
so here the first insert has been committed, but at the time of second insert the condition fails, so second
insert is roll backed. but it will not affect data that has been already committed.

ok take care

cheers

RSY

What is mutatinig trigger? How do you avoid mutating trigger?


Asked by: Interview Candidate | Asked on: Jan 5th, 2007

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


Guest
Answered On : Jan 8th, 2007

when theres a deadlock within multiple DML Triggers.


ex: when a a trigger has got mutiple DML statements and if a statement A tries to modify and row which
statement B had already modified hence this mutating erros occures
Answer Question

Login to rate this answer.


kashinathn
Answered On : Jan 9th, 2007
View all answers by kashinathn

The basic reason for this error is the way Oracle manages a read consistent view of data. The error is
encountered when a row-level trigger accesses the same table on which it is based, while executing. The
table is said to be mutating.
Answer Question

Login to rate this answer.


harsh
Answered On : Feb 8th, 2007

It is avoided by using views or plsql tables...


Answer Question

Login to rate this answer.


geetha24
Answered On : Feb 9th, 2007
View all questions by geetha24 View all answers by geetha24

Say for exampleThere is a before insert row level trigger T1 on the table empInside the trigger if you give
Select Count(*) from Emp, then mutating table error will be raised. This is because you are trying to
access the emp that is being updated by the same trigger. In the same example if you change row level
to statement this error will not be raised.
Answer Question

Login to rate this answer.


madhavi guthula
Answered On : Feb 28th, 2007

A table which is being updated is a mutating table, performing any DML operations or querying on a
mutating table leads to a mutating error. This can be possible in triggers or in funtions that are used in
expressions.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Nikhil_4_Oracle
Answered On : Mar 7th, 2007

Hey All,

Don`t go into therotical more...

Mutating Trigger is very simple,

see you have row level trigger on table with before/after timing, now in you

trigger defination if youhavequery(DML) on the same table on which trigger is

Based , then there is Mutating of Trigger Error. Since oracle can`t proccess

same table @ same time for two diff task.


thats all,

Bye.............

Nikhil. - i-flex

Answer Question

Login to rate this answer.


subramanian,sp
Answered On : Mar 15th, 2007

You can avoid mutating trigger by using autonomous transaction.


Answer Question
1 User has rated as useful.

Login to rate this answer.


Baji Shaik
Answered On : Jun 5th, 2011
View all answers by Baji Shaik
the row level trigger based on a table,the trigger body can't read thedata from same table, if you are
trying to this it gives mutating error

to avoid that you must use statement level trigger


Answer Question

Login to rate this answer.


nade_rs
Answered On : Jun 25th, 2011
View all answers by nade_rs

we can also make use of compound trigger (new feature in 11 g to avoid mutating error)
Answer Question

Login to rate this answer.

How can i see the time of execution of a sql statement?


Asked by: Interview Candidate | Asked on: Dec 20th, 2006

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


celso j.alos
Answered On : Dec 21st, 2006

use set timing on in sqlplus


Answer Question

Login to rate this answer.


geetha24
Answered On : Feb 9th, 2007
View all questions by geetha24 View all answers by geetha24

Set Timing onSelect * from Emp;You will get the time displayed.
Answer Question

Login to rate this answer.


sharmasl
Answered On : Mar 18th, 2009
View all answers by sharmasl
First execute "Set Timing on" Cammand on SQL Prompt and after that

SQL> SET TIMING ON

Execute the SQL Cammand on SQL Prompt

Select * from Emp;

You will get the time displayed. Like This-

SQL> SELECT * FROM EMP;


EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 18-JAN-81 1100 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30
7566 JONES MANAGER 7839 02-APR-81 3075 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1850 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2950 30
7782 CLARK MANAGER 7839 09-JUN-81 5000 10
7788 SCOTT ANALYST 7566 19-APR-87 3200 20
7839 KING PRESIDENT 17-NOV-81 0 10
7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1200 20
7900 JAMES CLERK 7698 03-DEC-81 1050 30
7902 FORD ANALYST 7566 03-DEC-81 3100 20
7934 MILLER CLERK 7782 23-JAN-82 0 10
14 rows selected.
Elapsed: 00:00:00.04
Answer Question

Login to rate this answer.


neerajalatha
Answered On : Jul 7th, 2010
View all answers by neerajalatha

use dbms_utility.get_time to get time of execution of a sql statement


Answer Question

Login to rate this answer.


neerajalatha
Answered On : Jul 7th, 2010
View all answers by neerajalatha

we can find the time of execution of a sql statement using dbms_utility.get_time package

eg:declare
v1 integer;
v2 number;
begin
v1:=dbms_utility.get_time;
dbms_output.put_line(v1);
select count(*) into v2 from employee;
v1:=dbms_utility.get_time;
dbms_output.put_line(v1);
end;
/
Answer Question

Login to rate this answer.


machomanic
Answered On : Jul 8th, 2010
View all answers by machomanic
You can use the command

SQL> SET TIMING ON;

This will show how much time your query took for the execution.
What is materialized view?
Asked by: Interview Candidate | Asked on: Dec 20th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 8 of 8 Answers


manisha Ramchandra Gharat
Answered On : Dec 21st, 2006

A materialized view is a database object that contains the results of a query. They are local copies of data
located remotely, or are used to create summary tables based on aggregations of a table's data.
Materialized views, which store data based on remote tables are also, know as snapshots.A materialized
view can query tables, views, and other materialized views. Collectively these are called master tables (a
replication term) or detail tables (a data warehouse term).
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Swapna
Answered On : Jan 10th, 2007

A materialized view or snapshot contains the results of a query of one or more tables, each of which may
be located on the same or on a remote database. Materialized viwes allows to create replications of
tables of remote data with a read-only privillage on the copy. When a materialized view is created, Oracle
creates one table and index, and in the same schema of the materialized view.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Sathish Palanivel
Answered On : Jul 13th, 2007

A materialized view is like a query with a result that is materialized and stored in a table. When a user
query is found compatible with the query associated with a materialized view, the user query can be
rewritten in terms of the materialized view. This technique improves the execution of the user query,
because most of the query result has been precomputed. The query transformer looks for any
materialized views that are compatible with the user query and selects one or more materialized views to
rewrite the user query. The use of materialized views to rewrite a query is cost-based. That is, the query
is not rewritten if the plan generated without the materialized views has a lower cost than the plan
generated with the materialized views.
Answer Question

Login to rate this answer.


sandeep5580
Answered On : Mar 29th, 2008
View all answers by sandeep5580

in addition to te previous posts, unlike a View,which refreshes automatically if the underlying base table
data is changed, the data in a Materialized view needs o be refreshed explicitly with the help of a
dbms_job.Thanks.
Answer Question

Login to rate this answer.


Ramadevioracle
Answered On : Sep 16th, 2008
View all answers by Ramadevioracle

Materialized views are schema objects that can be used to summarize, precompute, replicate, and
distribute data. E.g. to construct a data warehouse.
Answer Question

Login to rate this answer.


ashish
Answered On : Feb 7th, 2012

A materialized view have a physical memory where it can store the result of query which are combination
in joining of one or more table and view it retrieve a faster result. when we want to refresh the data
which are coming from diffrent application so it retrive the fast result. its a benefit of materialized view.
Answer Question

Login to rate this answer.


uday bhaskar rerddy
Answered On : Apr 19th, 2012
Materialized view is the local copy of remote database object.materialized view is the space demanding
object and it is read only. At the time of creating the materialized views,we can specify refresh interval
and refresh modes.

Refresh intervals represents, how the frequently the materialized view has to be refreshed. Refresh
modes are

1. Complete
2. Fast
3. Force
4. Uncommit
5. On demand
6. Differed
Answer Question

Login to rate this answer.


Sathish
Answered On : Jun 12th, 2012

Materialized views are objects that are used in base table that can be Summarized Group, and
aggregated with the base table.This materialized views are used in data-ware housing and decision
support system.

What is Atomic transaction?


Asked by: Interview Candidate | Asked on: Dec 20th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


Ligon Gopinathan
Answered On : Jan 1st, 2007

An atomic transaction is a database transaction or a hardware transaction which either completely


occurs, or completely fails to occur. A prosaic example is pregnancy - you can't be "halfway pregnant";
you either are or you aren't
http://en.wikipedia.org/wiki/Atomic_transaction
Answer Question
2 Users have rated as useful.

Login to rate this answer.


madhaviguthula
Answered On : Feb 28th, 2007
View all answers by madhaviguthula

Autonomous transactions are independent transactions that can be called from within another
transaction. An autonomous transaction lets you leave the context of the calling transaction, perform
some SQL operations, commit or undo those operations, and then return to the calling transaction's
context and continue with that transaction.
Answer Question

What is a NOCOPY parameter? Where it is used?


Asked by: Interview Candidate | Asked on: Dec 12th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


Abhishek Ghosh
Answered On : Dec 12th, 2006
NOCOPY Parameter Option
Prior to Oracle 8i there were three types of parameter-passing options to procedures and functions:
 IN: parameters are passed by reference
 OUT: parameters are implemented as copy-out
 IN OUT: parameters are implemented as copy-in/copy-out
The technique of OUT and IN OUT parameters was designed to protect original values of them in case
exceptions were raised, so that changes could be rolled back. Because a copy of the parameter set was
made, rollback could be done. However, this method imposed significant CPU and memory overhead
when the parameters were large data collectionsfor example, PL/SQL Table or VARRAY types.
With the new NOCOPY option, OUT and IN OUT parameters are passed by reference, which avoids copy
overhead. However, parameter set copy is not created and, in case of an exception rollback, cannot be
performed and the original values of parameters cannot be restored.
Here is an example of using the NOCOPY parameter option:
TYPE Note IS RECORD( Title VARCHAR2(15), Created_By VARCHAR2(20),
Created_When DATE, Memo VARCHAR2(2000));TYPE Notebook IS VARRAY(2000) OF
Note;CREATE OR REPLACE PROCEDURE Update_Notes(Customer_Notes IN OUT NOCOPY
Notebook) ISBEGIN ...END;
Answer Question
1 User has rated as useful.

Login to rate this answer.


Arun
Answered On : Dec 12th, 2006
NOCOPY is a hint given to the compiler, indicating that the parameter is passed as a reference and hence
actual value should not be copied in to the block and vice versa. The processing will be done accessing
data from the original variable. (Which other wise, oracle copies the data from the parameter variable
into the block and then copies it back to the variable after processing. This would put extra burdon on
the server if the parameters are of large collections/sizes)
Answer Question

Login to rate this answer.


Arun
Answered On : Dec 12th, 2006

I am sorry I didn't notice the second part of your question. This is used with the declaration of OUT
parameter.eq. PROCEDURE my_proc (param1 IN varchar2, param2 OUT NOCOPY varchar2, param3 IN
OUT NOCOPY varchar2)
Answer Question

Login to rate this answer.


iasritesh
Answered On : Jan 14th, 2007
View all questions by iasritesh View all answers by iasritesh

For better understanding of NOCOPY parameter, I will suggest u to run the following code and see the
result.
DECLARE
n NUMBER := 10;
PROCEDURE do_something (
n1 IN NUMBER,
n2 IN OUT NUMBER,
n3 IN OUT NOCOPY NUMBER) IS
BEGIN
n2 := 20;
DBMS_OUTPUT.PUT_LINE(n1); -- prints 10
n3 := 30;
DBMS_OUTPUT.PUT_LINE(n1); -- prints 30
END;
BEGIN
do_something(n, n, n);
DBMS_OUTPUT.PUT_LINE(n); -- prints 20
END;
Thanks & Regards,
Ritesh Kumar.
Answer Question

Login to rate this answer.


raghav_sy
Answered On : Jan 15th, 2007
View all answers by raghav_sy
hi one more thing i wan to add abt NOCOPY, it is that its a hint to compiler, so its compiler wish whether
to follow this thing or not, so before using this just go through the conditions when this thing will not be
taken into account. SO ITS NOT MANDATORY FOR COMPILER TO USE NOCOPY).
like during RPC(remote procedure call), NOCOPY will be not be used.
take care.
Answer Question

Login to rate this answer.


PraGop
Answered On : Jul 21st, 2008
View all answers by PraGop

Can u please give more explanation on this NOCOPY parameter


Answer Question

what are the advantages & disadvantages of packages ?


Asked by: Interview Candidate | Asked on: Nov 27th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 8 of 8 Answers


Thulasidas
Answered On : Nov 27th, 2006

Advantages
------------
Modular approach, Encapsulation/hiding of business logic, security, performance improvement, reusability
Disadvantages
-------------
Cant think of any
Answer Question
1 User has rated as useful.
Login to rate this answer.
sunnyjsr
Answered On : Dec 3rd, 2006
View all answers by sunnyjsr

Advantages of Packages----------------------------------Modularity,Easier Application Design,Information


Hiding,Added Functionality,Better Performance,
Answer Question
1 User has rated as useful.

Login to rate this answer.


Manikandan
Answered On : Dec 6th, 2006

using we can declare session level(scoped) variables.


since variable declared in pack spec has session scope.
Answer Question
1 User has rated as useful.

Login to rate this answer.


deepserp
Answered On : Dec 9th, 2006

Disadvantages of Package - More memory may be required on the Oracle database server when using
Oracle PL/SQL packages as the whole package is loaded into memory as soon as any object in the
package is accessed.
Answer Question
1 User has rated as useful.

Login to rate this answer.


madhuk17
Answered On : Feb 6th, 2007
View all questions by madhuk17 View all answers by madhuk17

we cant pass parameters to packages


Answer Question
2 Users have rated as useful.

Login to rate this answer.


MZ
Answered On : Mar 6th, 2007

Disadvantages: Updating one of the functions/procedures will invalid other objects which use different
functions/procedures since whole package is needed to be compiled.
Answer Question
1 User has rated as useful.

Login to rate this answer.


jagadeesh9
Answered On : Feb 24th, 2008
View all questions by jagadeesh9 View all answers by jagadeesh9
Package: It is an collection of related variables, cursors,procedures and functions stored at one location.
They supports OOPS features like function over loading, encapsulation.
ADV:
We can reduce the I/O operations.
Multiple interaction with database.
They improve performance while accessing sub-programs from remote client.

They are stored permanentely in USER_SOURCE system table.


Answer Question
1 User has rated as useful.

Login to rate this answer.


binurajnair
Answered On : Aug 2nd, 2008
View all answers by binurajnair

We can overload functions/procedures inside packages.

what is the difference between database trigger and schema trigger?


Asked by: Interview Candidate | Asked on: Oct 25th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


Pradeep
Answered On : Oct 26th, 2006

Database triggers are executed in response to particular events on tables in a databaseSchema triggers
are fired when schema objects (tables) are modified. It can be like before create, later,drop
Answer Question
Login to rate this answer.
srietl
Answered On : Oct 30th, 2006
View all answers by srietl

May be the question is like this 'Whats the diff. between database triggers on database or schema?
Database triggers can be system triggers on a database or a schema.
With a database,triggers fire for each event for all users...
With a schema,triggers fire for each event for that specific user...
Answer Question
1 User has rated as useful.

Login to rate this answer.


srujan
Answered On : Oct 30th, 2006

May be the question is like this...


What database triggers on a database or on a schema?
With a database,triggers fire for each event for all users.
With a schema,triggers fire for each event for that specific user.
Answer Question

Login to rate this answer.


rampratap409
Answered On : Dec 5th, 2006
View all questions by rampratap409 View all answers by rampratap409

In database trigger: Trigger for a table /view is a database trigger


like ( before , insert * update, delete, insert * row level, statement level)
2 * 3 * 2 = 12 + instead off trigger for views
schema triggers reffers to : before logoff, after logon, before create, drop,alter on schema ( these
trigger are also called DDL trigger)
Application trigger: before shutdown, after startup, on error( any error occur in database, after starting
the orcalce instance, before closing the instance)
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 18th, 2008
Triggers on system events can be defined at the database or schema level.

A trigger defined at the database level fires for all users, and
A trigger defined at the schema or table level fires only when the triggering event involves that
schema or table.

what is the difference between database server and data dictionary


Asked by: padma radhika | Member Since Sep-2006 | Asked on: Oct 24th, 2006
View all questions by padma radhika

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


Bhargav
Answered On : Oct 31st, 2006

Database Server have many schemas, and users, it has only one instance for the organisation, or lets say
its an instance of the data with all schema infowhereas the data dictionary contains raw data, of the
entire data of the database alongwith compiled code of all packages, procedures, funtions and the all
tables.infact the database server stores everything in raw format in the datadictionary they are not diff
but areone and the same
Answer Question

Login to rate this answer.


Raghavendra Jha
Answered On : Nov 11th, 2006

Database server is base on which everything resides,It Contains all the schemas,triggers,views etc..
Data Dictionary contains meta data information about each and every schemas object like tables
procedures..etc.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


rampratap409
Answered On : Dec 5th, 2006
View all questions by rampratap409 View all answers by rampratap409
Database server is collection of all objects of oracle
Data Dictionary contains the information of for all the objects like when created, who created etc.
Answer Question

Login to rate this answer.


Arun
Answered On : Dec 12th, 2006

HiDatabase server is a server on which the instance of oracle as server runs..whereas datadictionary is
the collection of information about all those objects like tables indexes views triggers etc in a database..
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 4th, 2008
Database Server: A computer in a LAN dedicated to database storage and retrieval. The database server
is a key component in a client/server environment. It holds the database management system (DBMS)
and the databases. Upon requests from the client machines, it searches the database for selected records
and passes them back over the network.

Data Dictionary: Is a collection of tables created and maintained by


the Oracle Server and Contain database information
Answer Question
3 Users have rated as useful.

Login to rate this answer.


psiva_oracle
Answered On : Feb 12th, 2008
View all answers by psiva_oracle
Hi,

Database Server:
It's contains the collection of objects (Table,procedure,trigger,sequence,index,etc)
it's also contains the Schema and user details
we can view the details which are in the Database server

DB dictionary:
It's contains the meta data format of all schema ,user information and object information also
Its contains the data is in non readable format.

Regards,
MPS
Bangalore

Answer Question

Hi, How do we display the column values of a table using cursors without
knowing the column names inside the loop?
Asked by: Interview Candidate | Asked on: Oct 19th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


rampratap409
Answered On : Oct 20th, 2006
View all questions by rampratap409 View all answers by rampratap409

I do not think so. You can not retrive the values from a cursor with OUT KNOWING THE COLUMN
NAME. You can not have (same name)/ (No Name) for all in a family.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Gopal
Answered On : Oct 22nd, 2006

Declare a variable using PL/SQL %ROWTPE ( l_Record EMP%ROWTYPE)In the cursor, you can say ..
cursor cursorname is select * from emp..Open cursor; loop .. fetch cursorname into l_Record.. Display
the values from l_Record using dbms_output.put_line.Close the loop and cursor
Answer Question

Login to rate this answer.


rampratap409
Answered On : Oct 23rd, 2006
View all questions by rampratap409 View all answers by rampratap409

Hi Gopal
Can u give a example please .
Answer Question

Login to rate this answer.


Sanjib
Answered On : Nov 2nd, 2006
Please, provide an example.
Answer Question

Login to rate this answer.


rampratap409
Answered On : Nov 2nd, 2006
View all questions by rampratap409 View all answers by rampratap409

You can not retrive the values from a cursor with OUT KNOWING THE COLUMN NAME
Answer Question

Login to rate this answer.


Sachin Vaidya
Answered On : Nov 6th, 2006

I Don't think so, If you are trying to populate the data using Records, then also you should know name
of the columns from the table or select query of the cursor.
Answer Question

Login to rate this answer.


Raghavendra Jha
Answered On : Nov 11th, 2006

No.its not possible to fetch column value from a cursor without knowing the column name,there is
nothing to do with cursor,cursor is nothing but explicitly created memory area to fetch record, using sql
query itself..and its not possible to retrieve any value without knowing column name,if it is not like that,
plz expalin with an example..
Answer Question

Login to rate this answer.


Naresh Dantu
Answered On : Nov 13th, 2006

You Can. Below is the example.


DECLARE
CURSOR cr_data
IS
SELECT ROWID, a.*
FROM fnd_user a where rownum < 10;
l_table_name VARCHAR2(2000) := 'FND_USER';
-- IMP--This table name should be same as your from table in the above cursor
l_value VARCHAR2 (2000);
l_str VARCHAR2 (2000);
CURSOR column_names (p_table_name VARCHAR2)
IS
SELECT *
FROM all_tab_columns
WHERE table_name = p_table_name;
-- You can use order by clause here if you want.
BEGIN
FOR cr_rec IN cr_data
LOOP
-- We should pass the same Table Name
FOR cr_columc_rec IN column_names (l_table_name)
LOOP
l_str :=
'Select '
|| cr_columc_rec.column_name
|| ' from '||l_table_name||' where rowid = '||chr(39)
|| cr_rec.ROWID||chr(39);
DBMS_OUTPUT.put_line ('Query is ' || l_str);
EXECUTE IMMEDIATE l_str
INTO l_value;
DBMS_OUTPUT.put_line ( 'Column is '
|| cr_columc_rec.column_name
|| ' and Value is '
|| l_value
);
END LOOP;
END LOOP;
END;
Answer Question

Login to rate this answer.


sankar
Answered On : Nov 14th, 2007
We have prdefined table 'col'. from this table we can find the column names dynamically.

For ex.

select cname from col where col=1 and tname='emp'

then you will get first clomun name of emp table; ex. for in 1..2 loop select cname into cname1 from col
where col=i and tname='emp';

cursor ec is select cname1 from emp;

end loop;
Answer Question

What is Flashback query in Oracle9i...?


Asked by: Interview Candidate | Asked on: Oct 18th, 2006

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


rampratap409
Answered On : Oct 18th, 2006
View all questions by rampratap409 View all answers by rampratap409

Flahsback is used to take your database at old state like a system restore in windows. No DDL and DML is
allowed when database is in flashback condition.
user should have execute permission on dbms_flashback package
for example:
at 1030 am
from scott user : delete from emp;
commit;
at 1040 am I want all my data from emp table then ?
declare
cursor c1 is select * from emp;
emp_cur emp%rowtype;
begin
dbms_flashback.enable_at_time(sysdate - 15/1440);
open c1;
dbms_flashback.disable;
loop
fetch c1 into emp_cur;
exit when c1%notfound;
insert into emp values(emp_cur.empno, emp_cur.ename, emp_cur.job,
emp_cur.mgr,emp_cur.hiredate, emp_cur.sal, emp_cur.comm,
emp_cur.deptno);
end loop;
commit;
end;
/
select * from emp;
14 rows selected
Answer Question
3 Users have rated as useful.

Login to rate this answer.


dev
Answered On : Oct 20th, 2006

Thank u Rampratap.
Answer Question

Login to rate this answer.


joybanerjee
Answered On : Dec 26th, 2007
View all questions by joybanerjee View all answers by joybanerjee
when ever a table is dropped the database does not release the space assotiated with it the
table is kept in the recycle bin.using flash back statement
one can get the old table back.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 18th, 2008
Oracle9i introduced Flashback Query to provide a simple, powerful and completely non-disruptive
mechanism for recovering from human errors. It allows users to view the state of data at a point in time
in the past without requiring any structural changes to the database.
This feature allows you to run a query against the database and return results as they would have
been produced at an earlier time. Flashback Query uses the same mechanisms as multiversion
read consistency, so it's like getting a feature for free. Get a consistent view of your data at a
previous point in time.

Hi,

Can anyone tell me the difference between instead of trigger, database trigger,
and schema trigger?

Thanks.
Asked by: Interview Candidate | Asked on: Oct 18th, 2006

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question
Showing Answers 1 - 5 of 5 Answers
sunnyjsr
Answered On : Oct 21st, 2006
View all answers by sunnyjsr

INSTEAD OF Trigger control operation on view , not table. They can be used to make non-updateable
views updateable and to override the behvior of view that are updateable.
Database triggers fire whenever the database startup or is shutdown, whenever a user logs on or log off,
and whenever an oracle error occurs. these tigger provide a means of tracking activity in the database
Answer Question

Login to rate this answer.


deepak
Answered On : Oct 22nd, 2006

Instead of trigger : A view cannot be updated , so if the user tries to update a view, then this trigger can
be used , where we can write the code so that the data will be updated in the table, from which the view
was created. Database trigger : this trigger will be fired when a database event ( dml operation ) occurs
in the database table, like insert , update or delete. System triggers : this trigger will fire for database
events like dtartup / shutdown of the server, logon / logoff of the user, and server errors ... and also for
the ddl events, like alter, drop, truncate etc.
Answer Question
1 User has rated as useful.

Login to rate this answer.


rampratap409
Answered On : Dec 5th, 2006
View all questions by rampratap409 View all answers by rampratap409

In database trigger: Trigger for a table /view is a database trigger


like ( before , insert * update, delete, insert * row level, statement level)
2 * 3 * 2 = 12 + instead off trigger for views
schema triggers reffers to : before logoff, after logon, before create, drop,alter on schema ( these
trigger are also called DDL trigger)
Application trigger: before shutdown, after startup, on error( any error occur in database, after starting
the orcalce instance, before closing the instance)
Answer Question

Login to rate this answer.


Nasim
Answered On : Dec 17th, 2006

Hi
if we have created a view that is based on join codition then its not possibe to apply dml operations like
insert, update and delete on that view. So what we can do is we can create instead off trigger and
perform dml operations on the view.
Database Vs Schema trigger:
consider these three triggers
create or replace trigger trig_usrA_conn
after logon on schema
Begin
insert into example.temp_table values (1,' user A connection fired');
End;
create or replace trigger trig_usrB_conn
after logon on schema
Begin
insert into example.temp_table values(2.'user B connection fired');
End;
create or replace trigger trig_All_conn
after logon on database
Begin
insert into example.temp_table values(3,' All connection fired');
End;
we have created two schema trigger for usera A and B and then created a database trigger. The
Database and Schema Keywords determine the level for a given system trigger.
Now you can connect to the database as usera A and then user B and example database. The after logon
trigger on the schema fires first and then after logon trigger to the database
connect userA/userA
connect userB/userB
connect example/example
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 4th, 2008
Triggers on system events can be defined at the database or schema level.
A trigger defined at the database level fires for all users, and a trigger defined at the schema or table
level fires only when the triggering event involves that schema or table.
INSTEAD OF Triggers
This type of trigger is used to provide a transparent way of modifying views that cannot be modified
directly through SQL DML statements because the view is not inherently modifiable. You can write
INSERT, UPDATE, and DELETE statements against the view. The INSTEAD OF trigger works invisibly in
the background performing the action coded in the trigger body directly on the underlying tables.

Suppose I have 2 triggers on table T, tr1- a before insert trigger & tr2- a before
update trigger.
tr1 has update (T) statement inside body of tr1
and
tr2 has insert (T) statement inside body of tr2
Now, I'm tring to insert a row into T.
What will hppn??
Asked by: shamim909 | Member Since Apr-2006 | Asked on: Oct 13th, 2006
View all questions by shamim909 View all answers by shamim909

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Bavani
Answered On : Oct 13th, 2006

You will get a mutating table error.


because you cannot do any DML statements inside the trigger which is used by the same table you are
updating or inserting.
Answer Question
1 User has rated as useful.

Login to rate this answer.


rampratap409
Answered On : Dec 5th, 2006
View all questions by rampratap409 View all answers by rampratap409
1. This process is called creating recursive trigger which causing the table in mutating stage.
2. you cannot do two DML statements in one statement.
Answer Question

Login to rate this answer.


trupti
Answered On : Feb 13th, 2007
Hi, you can use pragma autonomous_transaction for mutating trigger ie after declare, the first statement
is pragma autonomous_transaction.

try it,

it really works!!
Answer Question

Login to rate this answer.


gkbiswal
Answered On : Oct 21st, 2007
View all answers by gkbiswal

It(autonomous transaction) will work but it'll not satisfy your business requirement. Mutating error is not
actually an error but Oracle has provided this feauture to do away with any side effects due to the bad
application design. Therefore mutaing rror means, sometning is wrong with the application design.

what is the diff between %Rowtype and %type?


Asked by: Interview Candidate | Asked on: Oct 11th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question
Showing Answers 1 - 6 of 6 Answers
Rajeshwaran
Answered On : Oct 12th, 2006
%Rowtype means associating a single variable to a entire row.(It is one way of Declaring a composite
plsql datatype "RECORD")
%type means associating a single variable to a particular column in table.
both %Rowtype and %type declarations are known as Anchored Declarations in plsql .
Answer Question
2 Users have rated as useful.

Login to rate this answer.


sunnyjsr
Answered On : Oct 21st, 2006
View all answers by sunnyjsr

%RowType provides the records type the represent a entire row of a table or view or column select in
the cursor
%Type provides the data type of a variable or a database column to that variable.
Sunny Singh
9860229246
Answer Question

Login to rate this answer.


rampratap409
Answered On : Dec 5th, 2006
View all questions by rampratap409 View all answers by rampratap409

%RowType provides the full records values in one variable, and if in a table any column is added then
also your proc/function will not fail, that variable will hold the reference for new column also.
example:
v_rec emp%rowtype ;
%Type provides the data type of a column of a table
v_empno emp.empno%type;
use of %type, %rowtype makes your proc/function more effective and efficient.
Answer Question

Login to rate this answer.


harit79
Answered On : Jan 9th, 2009
View all questions by harit79 View all answers by harit79

%Rowtype : It associated with entire row of the table


%Type : Associated with single row of the table.

E.g

v_emp emp%rorwtype
v_ename ename%type
Answer Question
Login to rate this answer.
Radha
Answered On : Jul 14th, 2011
We use %type and %rowtype in PL/SQL programming part.

%Type: The variable will assign the datatype which contains in the column of that particular table we
mentioned.
Ex: v_eno employee.eno%type;
Here V_eno is a variable which is assigned the data type of eno column of employee table.

%Rowtype: It anchors the variable to all columns of that table.


Ex: Declare
v_emp employee%rowtype;
Begin
select e.* into v_emp from employee;
v_emp.sal := v_emp.sal + 100;
end;
Here we are accessing the name of the column directly with name of the variable(v_emp.sal)
Answer Question

Login to rate this answer.


manoj_lanser
Answered On : Jul 20th, 2011
View all answers by manoj_lanser
%type is used when we have to define the datatype of a variable similar to another existing column data-
type.
eg- v_id employess.employee_id%type.
In this example we have make a variable v_id similar to the datatype of employee_id column.

%rowtype is used when we have to make a single variable which can have similar datatype values of a
record i.e
it can handle different datatype at a time.

eg- v_id employee%rowtype.

what is difference between Cursor and Ref Cursor. Please give example.
Asked by: Interview Candidate | Asked on: Oct 8th, 2006

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Santo
Answered On : Oct 9th, 2006

Cursor is static one and ref cursor is dynamic with return type.
Answer Question

Login to rate this answer.


rampratap409
Answered On : Oct 9th, 2006
View all questions by rampratap409 View all answers by rampratap409

Example for cursor:


declare
cursor c1 is select * from emp;
begin
for r1 in c1 loop
dbms_output.put_line(r1.empno||' '||r1.ename);
end loop;
end;
/
Example for ref cursor
CREATE OR REPLACE package emp_data is
-- Author : RPSINGH
-- Created : 8/17/2006 12:54:03 AM
-- Purpose : displaying the data from different tables
-- Public type declarations
type my_cur is ref cursor;
-- Public constant declarations
-- Public variable declarations
-- Public function and procedure declarations
procedure tabledata(tname in varchar2, v_cur out my_cur);
end emp_data;
/
CREATE OR REPLACE PACKAGE BODY EMP_DATA IS
procedure tabledata(tname in varchar2,v_cur out my_cur) is
begin
OPEN V_CUR FOR
'SELECT * FROM '||TNAME;
end tabledata;
end emp_data;
/
Now to use this code:
declare
v_cur employees%rowtype;
C_CUR EMP_DATA.MY_CUR;
begin
emp_data.tabledata('EMPLOYEES', C_CUR);
LOOP
FETCH C_CUR INTO V_CUR;
EXIT WHEN C_CUR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(V_CUR.FIRST_NAME||' '||V_CUR.LAST_NAME);
END LOOP;
END;
/
Answer Question

Login to rate this answer.


Rajeshwaran
Answered On : Oct 12th, 2006

Cursor is a structure which points to a memory locations


while Ref-cursor is a datastructure which point to a object which inturn points to Memory locations..the
advantage of having Ref-cursor is that we can pass dynamically the Ref-cursor as a parameter to a
procedures..
Answer Question

Login to rate this answer.


harinath
Answered On : Jul 15th, 2011
cursor is a static,
ref cursor is dynamic,
we can't use ref cursor directly, so we declare cursor variable
cursor variables can't be stored in the database

Can we create a table using with Procedure or Function?


wat is the Mutating trigger error?
Asked by: Interview Candidate | Asked on: Oct 7th, 2006

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


santo
Answered On : Oct 9th, 2006

Ya, we can create table with procedure by using 'EXECUTE IMMEDIATE' command.
Mutating error:- occurs when row level trigger accesses same table on which it is based while executing
or the table currently being modified by the DML statements.
Answer Question

Login to rate this answer.


rani
Answered On : Oct 9th, 2006

mutating trigger error number is ORA-04091


Answer Question

Login to rate this answer.


gangadharam.p
Answered On : Dec 26th, 2006
View all questions by gangadharam.p View all answers by gangadharam.p

HI,
table can be created by using either dbms_sql or EXECUTE_IMMEDIATE in procedure or function.
Answer Question

Login to rate this answer.


sankari
Answered On : Jan 9th, 2007
We can do as shown below... in the same way we can drop the table..

DECLARE

BEGIN
EXECUTE IMMEDIATE 'create table employee(empno number(3),ename varchar2(10))';

END;

1.What is bulk collect?


2.What is instead trigger
3.What is the difference between Oracle table & PL/SQL table?
4.What R built in Packages in Oracle?
5.what is the difference between row migration & row changing?
Asked by: mathewsumoth | Member Since Sep-2006 | Asked on: Sep 29th, 2006
View all questions by mathewsumoth

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


rampratap409
Answered On : Oct 9th, 2006
View all questions by rampratap409 View all answers by rampratap409
1.What is bulk collect?
Bulk collect is part of PLSQL collection where data is stored/ poped up into a variable.
example:
declare
type sal_rec is table of number;
v_sal sal_rec;
begin
select sal bulk collect into v_sal from emp;
for r in 1.. v_sal.count loop
dbms_output.put_line(v_sal(r));
end loop;
end;

2.What is instead trigger


instead triggers are used for views.
3.What is the difference between Oracle table & PL/SQL table?
Table is logical entity which holds the data in dat file permanently . where as scope of
plsql table is limited to the particular block / procedure . refer above example sal_rec
table will hold data only till programme is reaching to end;

4.What R built in Packages in Oracle?


There R more then 1000 oracle builtin packges like:
Dbms_output, dbms_utility dbms_pipe .............

5.what is the difference between row migration & row


changing?
Migration: The data is stored in blocks whic use Pctfree 40%
and pctused 60% ( normally). The 40% space is used for update and delete statements
. when a condition may arise that update/delete statement takes more then pctfree
then it takes the space from anther block. this is called migration.
RowChaining: while inserting the data if data of one row takes more then one block
then this row is stored in two blocks and rows are chained.

Answer Question
1 User has rated as useful.

Login to rate this answer.


shashank.G
Answered On : Oct 13th, 2006

insted of triggers: They provide a transparent way of modifying view that can't be modified directly
through SQL ,DML statement.
Answer Question

Login to rate this answer.


rampratap409
Answered On : Oct 13th, 2006
View all questions by rampratap409 View all answers by rampratap409

Hi Shashank,
Can you explain instead off trigger, DML Trigger and views.
.
Answer Question

Login to rate this answer.


askvenki
Answered On : Jul 20th, 2007
View all answers by askvenki
rowchaining works for varchar2 datatype which will allocate memory dynamically
suppose thier is column name varchar2(20);

first value-- venki which is 5


changed to venki12 which is 7

then oracle will create datablock for 2 extra spaces.so while querying it must read data from two blocks.
so performance is less for varchar2
Suppose thr are 10 DMLs(insert,update,delete ) in the main section of the PL/SQL
block .The exception in them is handled as a whole in the exception handling
section .....The error may occur in any of this DMLs ,so how can we understand
that which DML has failed ??
Asked by: Interview Candidate | Asked on: Sep 24th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


ravikumarzee@gmail.com
Answered On : Oct 5th, 2006
View all questions by ravikumarzee@gmail.com View all answers by ravikumarzee@gmail.com

u'll never really know which DML threw the error.


if u want to trace put an exception handler after each DML.
Answer Question

Login to rate this answer.


rampratap409
Answered On : Oct 9th, 2006
View all questions by rampratap409 View all answers by rampratap409
declare
stmt varchar2(30);
begin
stmt := 'update statement1 ';
update statement...............
stmt := 'update statement2 ';
update ....................
stmt := 'insert statement';
insert into.............
....................
exception
when others then
dbms_output.put_line(stmt||' '||sqlerrm);
end;
/
Answer Question
2 Users have rated as useful.

Login to rate this answer.


chethan
Answered On : Nov 16th, 2006

i think u can use show error option and come to know the error........
Answer Question

Login to rate this answer.


rampratap409
Answered On : Nov 16th, 2006
View all questions by rampratap409 View all answers by rampratap409

show error will not give u runtime error/exceptions.


before compiling if any error : that only u can see by show error
Answer Question

Login to rate this answer.


madhaviguthula
Answered On : Mar 6th, 2007
View all answers by madhaviguthula

That you need to manipulate programtically. Like you can declare a variable called some counter. And
after each statement u increase the value of that counter variable. In the exception block u can
conditionally print the error msg on your own as you know the value of the variable and in which sql
statement u got the exception.
Answer Question

Login to rate this answer.


sandip01
Answered On : May 24th, 2010
View all questions by sandip01 View all answers by sandip01

using dbms_utility.format_call_stack you can know the row where the error occured
Answer Question

Login to rate this answer.


Teju_hassan
Answered On : Apr 19th, 2011
View all answers by Teju_hassan
The best way i feel is to have a output statement after each DML so that we can trace it easily

update table1
set column1='value1'
where column2='condition 2'

commit;
DBMS_OUTPUT.PUT_LINE(table 1 update completed);

update table2
set column2='value2'
where column2='condition 3'

commit;
DBMS_OUTPUT.PUT_LINE(table2 update completed);

If any error comes then the output statement after that update will not be
present in the log
Answer Question

Login to rate this answer.


BakulPatel
Answered On : May 7th, 2011
View all answers by BakulPatel
To simplify Remove exception block. Oracle will show line number with error thrown

Other method:

begin

location :=1;
dml1

location :=2;
dml2

exception
when others than
dbms_output('error at location ' || location || sqlerrm);
end;

Answer Question

Login to rate this answer.


sandeshshinde000
Answered On : Jun 4th, 2011
View all answers by sandeshshinde000
begin

DML 1
'
'
'
'
'
DML 10

exception
when others than
dbms_output('error at location '||dbms_utility.format_error_backtrace);
end;

dbms_utility.format_error_backtrace gives line number at which error has occured and its reason also.
Answer Question

how can u create session variable in pakages?


Asked by: Interview Candidate | Asked on: Sep 12th, 2006

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Sunaina
Answered On : Sep 13th, 2006

By declaring a vaiable in package specification


Answer Question

Login to rate this answer.


rashid
Answered On : Sep 20th, 2006

create or replace package pp


is
aa int :=00.00
end pp;
Answer Question

Login to rate this answer.


rampratap409
Answered On : Dec 11th, 2006
View all questions by rampratap409 View all answers by rampratap409

session variable can not be declared in package, variable declared in package are called global variables.
create package mypack is
num number := 7;
num2 number;
end ;
here num, num2 are global variable
when ever you wnt to use them. you have to use mypack.num or mypack.num2
where as session variable are declared like:
variable res number;
now when ever in current session you wnt to use res , use :res
":" indicates the session variable
Answer Question
2 Users have rated as useful.

Login to rate this answer.


asraf_pa
Answered On : Oct 10th, 2010
View all answers by asraf_pa
You can use DBMS_SESSION to set & get session variable. Below is the example for the same

SQL> EXEC DBMS_SESSION.SET_CONTEXT('CLIENTCONTEXT', 'myvar', 'myvalue');

PL/SQL procedure successfully completed

SQL> SELECT SYS_CONTEXT('CLIENTCONTEXT', 'myvar') FROM dual;

SYS_CONTEXT('CLIENTCONTEXT','M')
Answer Question

How to find the nth hightest record holder from a table


Asked by: Interview Candidate | Asked on: Aug 31st, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 20 of 20 Answers


Ravi S. Pasari
Answered On : Sep 2nd, 2006

You can use the following e.g.1. SELECT * FROM ( SELECT deptno, ename , sal , ROW_NUMBER() OVER
( PARTITION BY deptno ORDER BY sal DESC ) Top3 FROM emp )WHERE Top3 <= 3/2. This will give
distinct values.SELECT * FROM ( SELECT deptno, ename , sal , DENSE_RANK) OVER ( PARTITION BY
deptno ORDER BY sal DESC ) Top3 FROM emp )WHERE Top3 <= 3/
Answer Question
1 User has rated as useful.

Login to rate this answer.


dineshchaini
Answered On : Sep 10th, 2006
View all answers by dineshchaini
Hi...
If u want to find the nth record in salary basis then.. I thnik this will work
select * from(select * from emp order by sal desc) where rownum=
Answer Question
1 User has rated as useful.

Login to rate this answer.


chandra
Answered On : Sep 13th, 2006

the query is select * from sample where rownum=(select max(rownum) from sample)
Answer Question

Login to rate this answer.


rashid
Answered On : Sep 20th, 2006

u can use inline view


select sal from(select sal from emp order by sal desc) where rownum <5;
Answer Question
1 User has rated as useful.

Login to rate this answer.


Santo
Answered On : Oct 9th, 2006

Here is the query,


suppose i have table called T1 with 2 columns say ID,SAL then
i want to find out 3rd highest salary
select a.sal from t1 a
where 3 =(select count(distinct(b.sal)) from t1 b where a.sal <= b.sal);
with Regs
Santo
Answer Question
4 Users have rated as useful.

Login to rate this answer.


Suresh
Answered On : Oct 13th, 2006

select * from ( select rownum r, sal,name from (select * from emp order by sal)) where r=
You need to give all column names in first inline view.
Answer Question

Login to rate this answer.


rampratap409
Answered On : Dec 9th, 2006
View all questions by rampratap409 View all answers by rampratap409

select * from emp where rownum <=9


minus
select * from emp where rownum <9
Answer Question

Login to rate this answer.


sankari
Answered On : Jan 9th, 2007

We can use dense_rank() built in. It will rank the result set based on the column which is given in the
over() clause.
For ex) to get the 7th highest salary we can use the following query.
select * from(
select empno,ename,salary,dense_rank() over(order by salary desc) r
from emp )where r=7
I have used this in 10g..i am sure about the below versions.
Answer Question
1 User has rated as useful.

Login to rate this answer.


sudhaker
Answered On : Jan 17th, 2007
View all answers by sudhaker

to find nth highest salary u can go with this query


select min(sal) from (select distinct sal from emp order by sal desc) where rownum<='&ar';
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 3rd, 2008
View all answers by krishnaindia2007

select max(sal) from emp a where &n = (select count(distinct sal) from emp where sal >= a.sal);
Answer Question

Login to rate this answer.


nade_rs
Answered On : Jun 25th, 2011
View all answers by nade_rs
select min(sal) from (select distinct sal from emp order by sal desc) where rownum<n;
Answer Question

Login to rate this answer.


diptisaxena
Answered On : Jul 15th, 2011
View all answers by diptisaxena

If we have a table EMP and having data as, if we want second highest sal i.e 5000 the the query will be:
Code
1. EMPNO ENAME SAL
2. 1 A 5000
3. 2 B 2000
4. 3 C 10000
5.
6. SELECT MIN(SAL) FROM (SELECT * FROM EMP ORDER BY SAL DESC)
7. WHERE ROWNUM <=2
8.
Same as nth highest query we need to put that number instead of 2.
Answer Question

Login to rate this answer.


ravindra
Answered On : Jul 27th, 2011
Code
1. SELECT * FROM(SELECT ROW NUMBER AS rno emp.*FROM emp)WHERE RANK=&n;
Answer Question

Login to rate this answer.


Nihar
Answered On : Aug 26th, 2011
SELECT * FROM Emp A
WHERE &n=(SELECT COUNT(DISTINCT(Sal)) FROM EMP B WHERE A.Sal<=B.Sal);
Answer Question

Login to rate this answer.


anitha
Answered On : Aug 31st, 2011
Code
1. SELECT * FROM emp a WHERE n = (SELECT count(DISTINCT sal) FROM emp
b WHEREa.sal<=b.sal)
2.
3. //IN n place mention 1, 2,3...
4.
Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11

It is better to use analytic functions these days as they are faster and smarter and your managers will
think high of you...
Code
1. Top n-paid IN ALL Depts - changer the orde BY dept AND sal DESC IF ant TO find
out top paid IN each dept:
2. SELECT * FROM ( SELECT deptno, ename, sal
3. , ROW_NUMBER() OVER (ORDER BY sal DESC, ename) AS row_num
4. , RANK () OVER (PARTITION BY deptno ORDER BY sal DESC) rank
5. , DENSE_RANK () OVER (PARTITION BY deptno ORDER BY sal DESC) d_rank
6. FROM emp )
7. --WHERE row_num <= 4
8. /
Answer Question

Login to rate this answer.


rohitosu
Answered On : Mar 13th, 2012
View all answers by rohitosu

This is incorrect. It will not return anything. One of the possible answer is
Code
1. SELECT salary FROM (SELECT rownum n, a.salary
2. FROM
3. (SELECT DISTINCT salary FROM person ORDER BY salary ) a)
4. WHERE n = 5 ;
Answer Question

Login to rate this answer.


rohitosu
Answered On : Mar 13th, 2012
View all answers by rohitosu
This is a nice solution but it will not work correctly if any of the row has null values in it.

This is what I did. I specified n = 1 which means I want the highest salary. then I put the NULL values
for this record in salary column. The record with NULL value always shows me as the highest salaried
employee which is incorrect.
Answer Question

Login to rate this answer.


Neeraj Siddhey
Answered On : Mar 20th, 2012

This will work:-


Code
1. SELECT DISTINCT a.salary FROM emp a, emp b
2. WHERE 9=(SELECT DISTINCT count(b.salary) FROM emp b WHERE a.salary<=b.salary);
Answer Question

Login to rate this answer.


manisha
Answered On : May 27th, 2012

use
Code
1. NVL(a.sal,0)<= NVL(b.sal,0)
Hi Friends!!
Can anybody answer what are the constraints on Mutating tables? How to remove
the mutating errors in triggers? Urgent plzzzzzzzzzzzzzzzz

Thanks in Advance..
Thanks&Regds
Ramki,TCS
Asked by: Interview Candidate | Asked on: Aug 30th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


badhu
Answered On : Sep 4th, 2006

Hi Friend
Trigger Mutating will araise, when u want to do more than one DML operation on a table u will get
Trigger Mutation.
For example
U have table Stud with Sno, Mark1, Mark2, total,Avg fields.
U write a trigger Like below
Create or Replace Trigger Stud_Trig AFTER INSERT ON STUD FOR EACH ROW
begin
Update Stud SET total=:NEW.mark1 + :NEW.mark2, Avg = (:New.mark1 + :new.mark2) / 2 where sno
= :new.sno;
end;
Here u will get trigger Mutating.
The Trigger Mutating also appear in another time. I am not sure abt that time
I will work out and give the sample to u.
Regards
badhu
Answer Question

Login to rate this answer.


anonymous
Answered On : Oct 4th, 2006
A mutating table is a table that is currently being modified by an UPDATE, DELETE,
or INSERTstatement.When a trigger encounters a mutating table, a runtime error occurs, the effects of
the trigger body and triggering statement are rolled back, and control is returned to the user or
application. This Mutating Trigger restriction applies only to the for each row triggers.
If you need to update a mutating table, you could bypass these restrictions by using a temporary table, a
PL/SQL table, or a package variable. For example, in place of a single AFTER row trigger that updates the
original table, resulting in a mutating table error, you might use two triggers--an AFTER row trigger that
updates a temporary table, and an AFTER statement trigger that updates the original table with the
values from the temporary table.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Ashish M
Answered On : Nov 13th, 2006

I got rid of same kind of error while writing a trigger. I wrote a new function using AUTONMOUS
TRANSACTION keyword within it and called that function from the trigger. It worked for me. Hope it
works for you as well.
Answer Question
1 User has rated as useful.

Login to rate this answer.


be17be
Answered On : Dec 1st, 2006
View all questions by be17be View all answers by be17be

Ashish, can you please give an example?


Answer Question

Login to rate this answer.


amahanit
Answered On : Oct 13th, 2007
View all questions by amahanit View all answers by amahanit
1) make the trigger as a statement level trigger.
2) if u want to use :old and :new qualifer then create 2 trigger ,1st before insert trigger and use PL/SQL
table to select the values,2nd after insert trigger and insert the values from PL/SQL tables.
Answer Q

What will the Output for this Coding>


Declare
Cursor c1 is select * from emp FORUPDATE;
Z c1%rowtype;
Begin
Open C1;
Fetch c1 into Z;
Commit;
Fetch c1 in to Z;
end;
Asked by: Interview Candidate | Asked on: Aug 17th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 8 of 8 Answers


vivek tyagi
Answered On : Aug 17th, 2006

by declaring this cursor we can update the table emp through z,means wo not need to write table name
for updation,it may be only by "z".
Answer Question

Login to rate this answer.


oranachs
Answered On : Aug 17th, 2006
View all questions by oranachs View all answers by oranachs

since there is no space between forupdate clause it raises an error.


Answer Question

Login to rate this answer.


fli3
Answered On : Aug 18th, 2006

No error. Everthing is fine. Once commit, the only thing happened is the table got unlocked.
Answer Question

Login to rate this answer.


divya
Answered On : Aug 23rd, 2006

The block will fail with error:


ORA-01002: fetch out of sequence
This is because in for update cursors , since rows are
locked by the query , one has to make sure that the crrsor is closed before
commmiting.

Answer Question
3 Users have rated as useful.

Login to rate this answer.


Pankaj Gauba
Answered On : Sep 13th, 2006

No error. Everthing is fine. Once commit, the only thing happened is the table got unlocked.
Table is locked until the table is updated or deleted
Answer Question

Login to rate this answer.


Raghavendra
Answered On : Nov 19th, 2006

NO ERROR..
Answer Question

Login to rate this answer.


satyam_Ora
Answered On : May 8th, 2008
View all questions by satyam_Ora View all answers by satyam_Ora
Declare
Cursor c1 is select * from emp FORUPDATE;
Z c1%rowtype;
Begin
Open C1;
Fetch c1 into Z;
Commit;
Fetch c1 in to Z;
end;

SQL> start e1
Declare * ERROR at line 1: ORA-01002: fetch out of sequence ORA-06512: at line 8
Reason: This error means that a fetch has been attempted from a cursor which is no longer valid.
Here the main reason of this error is
"the cursor has been opened with the FOR UPDATE clause, fetching after a COMMIT has been issued will
returning the error.

Action: Do not issue a COMMIT inside a fetch loop for a cursor that has been opened FOR UPDATE
Answer Question
1 User has rated as useful.

Login to rate this answer.


satyam_Ora
Answered On : May 8th, 2008
View all questions by satyam_Ora View all answers by satyam_Ora
Please remove the commit from the begin statement and the it will execute properly.

Thanks,

What are the Restrictions on Cursor Variables?


Thanks
Ramki, Hyd, TCS
Asked by: Interview Candidate | Asked on: Aug 17th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


latha
Answered On : Aug 18th, 2006

Hi RamaKrishna,Currently, cursor variables are subject to the following restrictions:You cannot declare
cursor variables in a package spec. For example, the following declaration is not allowed:CREATE
PACKAGE emp_stuff AS TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; emp_cv
EmpCurTyp; -- not allowedEND emp_stuff;You cannot pass cursor variables to a procedure that is called
through a database link.If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the
server side unless you also open it there on the same server call.You cannot use comparison operators to
test cursor variables for equality, inequality, or nullity.You cannot assign nulls to a cursor
variable.Database columns cannot store the values of cursor variables. There is no equivalent type to use
in a CREATE TABLE statement.You cannot store cursor variables in an associative array, nested table, or
varray.Cursors and cursor variables are not interoperable; that is, you cannot use one where the other is
expected. For example, you cannot reference a cursor variable in a cursor FOR
loop.Regardslatha,Bangalore,TCS
Answer Question
3 Users have rated as useful.

Login to rate this answer.


mariashylaja
Answered On : Aug 22nd, 2006

What a answere..... excellent...


Answer Question

Login to rate this answer.


Vidhya
Answered On : Aug 23rd, 2006

Answer is very in-depth


Answer Question

Login to rate this answer.


stan
Answered On : Sep 12th, 2006

No need of much more explanation....excellent answer latha..


Answer Question

Login to rate this answer.


rashid
Answered On : Sep 20th, 2006

hi friend
cursor variable can't use with dynamic sql.
cursor variable can't use with in package because it is not having persistent state.
nulls can't assinged to cursor variable.
remote procedure can't accept cursor variable
Answer Question

Login to rate this answer.


Ashwini
Answered On : Dec 23rd, 2006

Cursor Variable Restrictions


Cursor variables are subject to the following restrictions; Oracle may remove some of these in future
releases.
 Cursor variables cannot be declared in a package since they do not have a persistent state.
 You cannot use RPCs (Remote Procedure Calls) to pass cursor variables from one server to another.
 If you pass a cursor variable as a bind or host variable to PL/SQL, you will not be able to fetch from it
from within the server unless you also open it in that same server call.
 The query you associate with a cursor variable in an OPEN-FOR statement cannot use the FOR UPDATE
clause.
 You cannot test for cursor variable equality, inequality, or nullity using comparison operators.
 You cannot assign NULLs to a cursor variable.
 Database columns cannot store cursor variable values. You will not be able to use REF CURSOR types to
specify column types in statements to CREATE TABLEs or CREATE VIEWs.
 The elements in a nested table, index-by table, or variable array (VARRAY) cannot store the values of
cursor variables. You will not be able to use REF CURSOR types to specify the element type of a
collection.
 Cursor variables cannot be used with dynamic SQL (through use of the DBMS_SQL package).
can we declare a column having number data type and its scale is larger than
pricesion
ex: column_name NUMBER(10,100),
column_name NUMBAER(10,-84)
Asked by: Interview Candidate | Asked on: Aug 15th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


Supriya
Answered On : Aug 16th, 2006

Yes,
we can declare a column with above condition.
table created successfully.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Oracle_learner
Answered On : Sep 20th, 2006

Yes ,such declaration is possible .Explaining with example .1.number(9,11) means there are 11 digits
after decimal .However as the max precision is 9 so the rest are zero padded .Like
0.009999999992.number(9,-11) means that there are 9 digits whereas the rest is zero padded towards
left of the decimal point Like 99999999900000000000.0
Answer Question

Login to rate this answer.


satyam_Ora
Answered On : May 8th, 2008
View all questions by satyam_Ora View all answers by satyam_Ora
SQL > create table a2(a number(10,100));
Table created.

SQL> create table a3(a number(10,-84));


Table created.

How to disable multiple triggers of a table at at a time?


Asked by: Interview Candidate | Asked on: Aug 11th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


gouthami
Answered On : Aug 13th, 2006

Alter table tablename disable all triggers;


Answer Question
2 Users have rated as useful.

Login to rate this answer.


dineshchaini
Answered On : Aug 13th, 2006
View all answers by dineshchaini

ALTER TABLE<TABLE NAME> DISABLE ALL TRIGGER


Answer Question
1 User has rated as useful.

Login to rate this answer.


srinivas
Answered On : Aug 23rd, 2006

ALTER TABLE<TABLE NAME> DISABLE ALL TRIGGER


Answer Question

Login to rate this answer.


Brijesh Mishra
Answered On : Oct 9th, 2006

SQL> Spool c:tempdisable_all_trigger


SQL > Select 'ALTER TRIGGER '|| trigger_name ||' disable;' from user_triggers;

SQL> spool off


after that open file disable_all_trigger.lst and remove header part and save file.
SQL>@c:tempdisable_all_trigger.lst
Answer Question

Login to rate this answer.


Raghavendra
Answered On : Nov 19th, 2006

Alter table
disable all trigger;
Answer Question

How to avoid using cursors? What to use instead of cursor and in what cases to
do so?
Asked by: moviefan456 | Member Since Aug-2006 | Asked on: Aug 9th, 2006
View all questions by moviefan456

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


oranachs
Answered On : Aug 17th, 2006
View all questions by oranachs View all answers by oranachs

hai
just use subquery in for clause
ex:
for emprec in (select * from emp)
loop
dbms_output.put_line(emprec.empno);
end loop;
no exit statement needed
implicit open,fetch,close occurs
try this and send me the reply on ora.nachs@yahoo.com
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Venkat
Answered On : Sep 21st, 2006

I think the answer is:


If your select statement retruns only one value, you can avoid using cursor:
for instance:
select fname into v_fname
from emp where empno = 10;
(here assueme that the empno is PK)
in your procedure or package or function you can declare the variable v_fname and directly use the
abovesql statement instead of declaring a cursor,opening, ...

Thanks.
Venkat
Answer Question
Login to rate this answer.
Venkat9999
Answered On : Sep 21st, 2006

I think the answer is:


If your select statement retruns only one value, you can avoid using cursor:
for instance:
select fname into v_fname
from emp where empno = 10;
(here assueme that the empno is PK)
in your procedure or package or function you can declare the variable v_fname
and directly use the above sql statement instead of declaring a cursor,opening,
...
Venkat
Answer Question

Login to rate this answer.


Jagadish V
Answered On : Nov 24th, 2006

if you need to perform manipulations from the output of the select statement which results multiple rows
,the cursor need to be used.
Answer Question

Login to rate this answer.


Tanveer Islam Siddiqui
Answered On : Nov 24th, 2006

U have 2 options to do it..


1st) Use Pl/SQL Table...
2nd) Create Temporary Table and use it in place of Table...
Answer Question

Login to rate this answer.


Thulasidas
Answered On : Nov 26th, 2006

Well there may be several ways for not to use a cursor. But a good programming practice suggests the
use of cursors as much as possible for performance and efficiency purpose.
Answer Question

Login to rate this answer.


srinivas
Answered On : Nov 29th, 2006

insted of using cursor we will use attribute data types %type and %rowtype to load data in pl/sql
Answer Question
Login to rate this answer.
krishnaindia2007
Answered On : May 8th, 2008
View all answers by krishnaindia2007

You can use bulk binding to avoid cursors. It improves performance by minimizing context switches sql
and pl/sql. When you are hadling large volume of data then better to use bulk binding.
Answer Question
1 User has rated as useful.

Login to rate this answer.


KSPRADEEP
Answered On : Oct 17th, 2012
Yes we can ..
Instead of cursor we using bulk collection or bulk binding or using %type and %rowtype

How we can create a table in PL/SQL block. insert records into it??? is it possible
by some procedure or function?? please give example...
Asked by: Interview Candidate | Asked on: Aug 8th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


Praphullit
Answered On : Aug 9th, 2006

hi , you can run DDL (create) command in PL/SQL through EXECUTE IMMEDIATE command.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Sekhar
Answered On : Aug 12th, 2006
Hi, Can you give me an example using EXECUTE IMMEDIATE Command
Answer Question
Login to rate this answer.
Dinesh
Answered On : Aug 13th, 2006

No, I tried this out but.... it give error...You just try it and give me the synatx and the code that u
executed
Answer Question

Login to rate this answer.


Ram
Answered On : Aug 14th, 2006
CREATE OR REPLACE PROCEDURE ddl_create_proc (p_table_name IN VARCHAR2)
AS
l_stmt VARCHAR2(200);
BEGIN
DBMS_OUTPUT.put_line('STARTING ');
l_stmt := 'create table '|| p_table_name || ' as (select * from emp )';
execute IMMEDIATE l_stmt;
DBMS_OUTPUT.put_line('end ');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line('exception '||SQLERRM || 'message'||sqlcode);
END;
Answer Question

Login to rate this answer.


chanti4u123
Answered On : Aug 14th, 2006
View all answers by chanti4u123

yes we can create a table in the PLSQL block very easly with the help of procedure
hint : here abcd is the procedure name of the stored procedure
create or replace procedure abcd is
begin
create table stud1(sno number(3),sname varchar2(10))
/
end abcd;
/
after that write a program to call the stored procedure
begin
abcd;
end;
/
Answer Question

Login to rate this answer.


dineshchaini
Answered On : Aug 15th, 2006
View all answers by dineshchaini

Dear friends...
Whatever the programme u r writing thea .. is that working... NOOOOOOOO.. so plz try it then
answer.... cause in Rams programme the procedure is created but not creating any table... and chanti....
this is impossible... go through the machine...
Regards
Dinesh
Answer Question

Login to rate this answer.


Maria Antony
Answered On : Aug 22nd, 2006

Hi,
Whatever Ram has given is the correct approach only. However, if you execute the procedure, you may
be left with no table created. That may be because you won't have sufficient privileges. Look down how I
tried to careate a procedure as Ram told and how I executed that and what problem I faced and how I
rectified that.
SQL > conn maria/maria;
Connected.
SQL> set serverout on;
SQL> CREATE OR REPLACE PROCEDURE ddl_create_proc (p_table_name IN VARCHAR2)
2
3 AS
4
5 l_stmt VARCHAR2(200);
6
7 BEGIN
8
9 DBMS_OUTPUT.put_line('STARTING ');
10
11 l_stmt := 'create table '|| p_table_name || ' as (select * from emp )';
12
13 execute IMMEDIATE l_stmt;
14
15 DBMS_OUTPUT.put_line('end ');
16
17 EXCEPTION
18
19 WHEN OTHERS THEN
20
21 DBMS_OUTPUT.put_line('exception '||SQLERRM || 'message'||sqlcode);
22
23 END;
24 /
Procedure created.
SQL> set serverout on
SQL> exec ddl_create_proc('tony_emp');
STARTING
exception ORA-01031: insufficient privilegesmessage-1031
PL/SQL procedure successfully completed.
SQL> conn system/manager;
Connected.
SQL> grant create table to maria identified by maria;
Grant succeeded.
SQL> conn maria/maria;
Connected.
SQL> set serverout on
SQL> exec ddl_create_proc('tony_emp');
STARTING
end
PL/SQL procedure successfully completed.
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
EMP TABLE
TONY_1 TABLE
TONY_4 TABLE
TONY_EMP TABLE
SQL> select * from emp where rownum < 3;
ID
----------
1
2
SQL> select * from tony_emp where rownum < 3;
ID
----------
1
2
SQL> spool off
Answer Question
2 Users have rated as useful.

Login to rate this answer.


tdas2004
Answered On : Sep 7th, 2006
View all answers by tdas2004
You are right Maria Antony, but the question is, why is it not possible to create the table thru the
procedure while you can create the same
table using create table SQL command.
The answer is, to create the table thru the procedure the create table privilege must have been granted
directly to the user rather than a role. Remember the user scott having the emp table has already a
create table privilege via the default role 'RESOURCE' allotted when the user was created, thats why u
can create using SQL command.
Answer Question

Login to rate this answer.


dineshchaini
Answered On : Sep 9th, 2006
View all answers by dineshchaini

Dear Maria...
I traied with the DBA previlage but... again the same prob.. proc created but table is not thea... ok I
tried u r proc and mail back to you...
Answer Question

In a Distributed Database System Can we execute two queries simultaneously ?


Justify ?
Asked by: Interview Candidate | Asked on: Jul 29th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


Manoj Kumar Verma
Answered On : Aug 1st, 2006
As Distributed database system based on 2 phase commit,one query is independent of 2 nd query so of
course we can run.
manoj
Answer Question
2 Users have rated as useful.

Login to rate this answer.


D. Madhusudhana Rao ( 9885626575)
Answered On : Aug 1st, 2006

Its depend upon the query. If the two queries are firing on the table it is not possible. If the queries are
firing on different different tables then it is possible.
Thanks & Regards
Madhu D.

1)what is the starting "oracle error number"?


2)what is meant by forward declaration in functions?
Asked by: Interview Candidate | Asked on: Jul 28th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 8 of 8 Answers


Rama Krishna,Yerra
Answered On : Aug 2nd, 2006

Hi Suri !!
Forward Declaration means.. If you are defining a package body having two procedures , If u
want to use second procedure in the defination of first procedure.. You have to declare the second
package with its arguments(if have) before using in the defination of first procedure.. its labled as
forward declaration..
Thanks&Regds
Ramki,Tata Cosnultacny Services,
Deccan Park,HYD,India
Answer Question
2 Users have rated as useful.

Login to rate this answer.


gouthami kodangal
Answered On : Aug 15th, 2006

STARTING ORACLE ERROR NO IS ORA 00001


Answer Question
1 User has rated as useful.

Login to rate this answer.


gouthami kodangal
Answered On : Aug 15th, 2006

One must declare an identifier before referencing it. Once it is declared it can be referred even before
defining it in the PL/SQL. This rule applies to function and procedures also
Answer Question

Login to rate this answer.


Surya Peri
Answered On : Feb 17th, 2007

The starting is ORA0000 which means "Successful Completion".


Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 4th, 2008
ORA-00000: normal, successful completion
Cause: Normal exit.

PL/SQL does not allow forward references. You must declare an identifier before using it.
Therefore, a subprogram must be declared before calling it. You can use forward declarations to
do the following:
• Define subprograms in logical or alphabetical order
• Define mutually recursive subprograms
• Group subprograms in a package
Mutually recursive programs are programs that call each other directly or indirectly.
Answer Question

Login to rate this answer.


psiva_oracle
Answered On : Feb 12th, 2008
View all answers by psiva_oracle
Hi,
Oracle Error message starting from ORA-00000
ORA-00000 normal, successful completion
Cause: An operation has completed normally, having met no exceptions.
Action: No action required.

Regards,
Siva.P
Birlasoft
Bangalore
Answer Question

Login to rate this answer.


KD09714
Answered On : Jun 26th, 2008
View all questions by KD09714 View all answers by KD09714
Example of forward declaration in package :

CREATE OR REPLACE PACKAGE pkg_CBRef_Seq


AS
PROCEDURE sp_CBRCreateDropSeq_scd
( p_cod_CountryCode IN country.country_code%TYPE,
p_cod_LegVeh IN leg_veh.leg_veh%TYPE);

END pkg_CBRef_Seq;
/

CREATE OR REPLACE PACKAGE BODY pkg_CBRef_Seq


AS
/*Forward declaration for procedure as this is private to package and defined later*/
PROCEDURE sp_CBRCreateDropSeq_cd
( p_cod_CountryCode IN country.country_code%TYPE,
p_cod_LegVeh IN leg_veh.leg_veh%TYPE
);

PROCEDURE sp_CBRCreateDropSeq_scd
( p_cod_CountryCode IN country.country_code%TYPE,
p_cod_LegVeh IN leg_veh.leg_veh%TYPE)
AS
BEGIN
sp_CBRCreateDropSeq_cd(p_cod_CountryCode,cur_LegVeh);
/*procedure is called here only because it is forward declared (not defined till now)*/
END sp_CBRCreateDropSeq_scd;

PROCEDURE sp_CBRCreateDropSeq_cd ( p_cod_CountryCode IN


country.country_code%TYPE,
p_cod_LegVeh IN leg_veh.leg_veh%TYPE)
AS
BEGIN
............................/*Procedure defined here onwards....*/
END sp_CBRCreateDropSeq_cd;
Answer Question
2 Users have rated as useful.

Login to rate this answer.


muraligrandhi
Answered On : Jun 23rd, 2011
View all answers by muraligrandhi
A forward declaration means that modules (procedures and functions) are declared in advance of their
actual body definition.

For example, if program A calls program B and program B calls program A, PL/SQL supports mutual
recursion, where two or more programs directly or indirectly call each other.

See the below example you can understand.

CREATE OR REPLACE PACKAGE my_pkg


IS
FUNCTION my_func
RETURN NUMBER;
END my_pkg;
/

Package created.

CREATE OR REPLACE PACKAGE BODY my_pkg


AS
FUNCTION my_func2
RETURN NUMBER; -- forward declaration

FUNCTION my_func
RETURN NUMBER
IS
BEGIN
RETURN my_func2; -- Legal call
END my_func;

FUNCTION my_func2
RETURN NUMBER
IS
BEGIN
RETURN 0;
END my_func2;
END my_pkg;
/
Package body created.

explian rowid,rownum?what are the psoducolumns we have?


Asked by: Interview Candidate | Asked on: Jul 28th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 12 of 12 Answers


krish
Answered On : Jul 28th, 2006

ROWID - Hexa decimal number each and every row having unique.Used in searching
ROWNUM - It is a integer number also unique for sorting Normally TOP N Analysys.
Other Psudo Column are
NEXTVAL,CURRVAL Of sequence are some exampls
askrish@hotmail.com
Answer Question
3 Users have rated as useful.

Login to rate this answer.


D. Madhusudhana Rao ( 9885626575)
Answered On : Aug 1st, 2006

psoducolumn in the sence which is not created by the user explicitly but user can use those things
explicityly.
examples
rowid,rowno,currval,nextval,sysdate,uid,level.
RowID: While storing in the database oracle generates one id for each row.

you can call based upon the rowid .ex: select * from emp where rowid=....
RowNo : This no is also generated by oracle itself. but you cant call based upon this one in select clause
Answer Question

Login to rate this answer.


Sphurti
Answered On : Aug 14th, 2006

I would like to add one more point here ,


Rowid is permanent for the life time whereas rownum is not. What i mean is till the time the record is
present in the table, the value of ROWID of a particular row in a table will always be same whereas the
value of ROWNUM will vary.
Answer Question

Login to rate this answer.


Gyaneshwar VC
Answered On : Sep 4th, 2006

Even ROWID is also not permanent for life time.Because If one exports and imports the table data then
ROWID changes.
Answer Question
1 User has rated as useful.

Login to rate this answer.


sunflower
Answered On : Feb 22nd, 2007
Rowid is a unique identifier, when a row is inserted into the table it generates a row id and will be
removed when the row is deleted.

For each row returned by the query a Rownum, pseudocolumn is returned in which order oracle selects
the rows from the table. Using rownum one can even limit the number of rows selected from the table.

Ex: select * from emp where rownum<10;


Answer Question
1 User has rated as useful.

Login to rate this answer.


askvenki
Answered On : Jul 19th, 2007
View all answers by askvenki
rowid is hexadecimal format which is parmently stored with row
rownum while retreivng data oracle attach row num for each row
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 4th, 2008
Row id: Hexadecimal string representing the unique address of a row in its table. This datatype
is primarily for values returned by the ROWID pseudocolumn.
Rownum: For each row returned by a query, the ROWNUM pseudocolumn returns a number
indicating the order in which Oracle selects the row from a table or set of joined rows. The first
row selected has a ROWNUM of 1, the second has 2, and so on. You can use ROWNUM to limit
the number of rows returned by a query, as in this example:
SELECT * FROM employees WHERE ROWNUM < 10;

A pseudocolumn behaves like a table column, but is not actually stored in the table. You can
select from pseudocolumns, but you cannot insert, update, or delete their values. This section
describes these pseudocolumns:
- CURRVAL and NEXTVAL
- LEVEL
- ROWID
- ROWNUM
Answer Question
3 Users have rated as useful.

Login to rate this answer.


johnjerry
Answered On : Oct 9th, 2009
View all answers by johnjerry
My 2 cents:
Rowid contains hexa-decimal number

 bits 1 to 32 (bytes 1 to 4): data object id (0-4294967295)


 bits 33 to 44 (byte 5 and half byte 6): file number inside the tablespace (0-4095) - file id
 bits 45 to 64 (half byte 6 and bytes 7 and 8): block number inside the file (0-1048575) - block id
 bits 65 to 80 (bytes 9 and 10): row number inside the block (0-65535)
When printed, each field is displayed in radix 64 (A-Za-z0-9+/): OOOOOOFFFBBBBBBRRR
Answer Question

Login to rate this answer.


Radha
Answered On : Jul 14th, 2011
Row ID: Code defined by the database for unique identification of each row. It is 18 alphabetical
characters in length.

Row NUM: A sequence number used to retrieve rows from the table.

Some other Pseudo columns are - Level, Rowscn, UID, User, Sysdate.
Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11
Pseudocolumn - a column that is not stored in a table, yet behaves like a table column.

ROWID - a global unique address for a row in a database.


ROWNUM
Returns a number indicating the order in which Oracle selects the row from a table or set of joined rows.
The first row selected has a ROWNUM of 1, the second has 2, and so on.

If using ORDER BY with ROWNUM then the rows will be reordered by the ORDER BY clause, means the
sequence of rows will be different. it is better to use ROW_NUMBER() analytic unction.

Example:
SELECT * FROM emp WHERE ROWNUM < 11 ORDER BY ename;

Fix:
SELECT * FROM (SELECT * FROM emp ORDER BY empno) WHERE ROWNUM < 11;

ROW_NUMBER() analytic function example:


SELECT * FROM ( SELECT deptno, ename, sal ,ROWNUM ,ROW_NUMBER() over (order by sal desc,
ename) as rno FROM emp ) --WHERE rno <= 4
/

Answer Question

Login to rate this answer.


Dilip
Answered On : Sep 3rd, 2012

Here I am providing all the psudo columns of Oracle ROWNUM, ROWID,NEXTVAL, CURRVAL, SYSDATE,
USER, LEVEL
Answer Question

Login to rate this answer.


PRADEEP
Answered On : Oct 16th, 2012
rowid is octal decimal values it is stored permanently in a oracle database. It will created while creating a
table.

rownum is also octal decimal number but it is for only specific time span it will arise after completed a
task.
Answer Question

what is difference b/w stored procedures and application procedures,stored


function and application function..
Asked by: rajanen | Member Since Jul-2006 | Asked on: Jul 26th, 2006
View all questions by rajanen View all answers by rajanen

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


gouthami kodangal
Answered On : Aug 13th, 2006

stored procedures are subprogrammes stored in the


database and can be called &executee multiple times
wherein an application procedure is the one being used
for a particular application same is the way for function
Answer Question
3 Users have rated as useful.

Login to rate this answer.


Maria Antony Samy
Answered On : Aug 29th, 2006

Hi Rajan,
I do not know what do you mean by application funciton/procedure. In Oracle terms, a PL/SQL block
which is stored ( meaning, you define once; and you can call that procedure or function from other part
of application; if you grant permission to others, they will also be able to acces that procedure or function
) in the database. Here youn can ask the question "What are the other type of procedure or functions
available in Oracle?"...... The answer is, you can have a procedure or function defined within a pl/sfql
block. This enables you to call that pro/function from that pl/sql block only. Moreover, you can define
pro/function in packages aswell.
Are you clear now....? if not, do not hesitae to ask me...
Regards,
maria_antony2000@yahoo.com
Answer Question

Login to rate this answer.


srinivas
Answered On : Nov 29th, 2006

hi friend,
i think that there is no difference between stored procedure and applicaton procedure.both r stoed in the
data base only they can call any where required what do say plz give me replaye by seeing this
Answer Question

Login to rate this answer.


Nishant Patel
Answered On : Jun 13th, 2007
The difference between the two can be categorised via: Stored subprograms ans Application
subprograms
1) Stored subprograms: These are coded and compiled fromwithin the Oracle database via SQL Plus etc.
2) Application subprograms: These are coded and compiled from within the Oracle development tools
such as Oracle Developer.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 4th, 2008
Application procedures or functions: Named PL/SQL blocks stored in an Oracle Forms Developer
application or shared library; can accept parameters and can be invoked repeatedly by name and are
available in Oracle Developer tools components, for example, Oracle Forms Developer, Oracle Reports.

Stored procedures or functions: Named PL/SQL blocks stored in the Oracle server; can accept parameters
and can be invoked repeatedly by name and are available in Oracle server.

State the advatage and disadvantage of Cursor's


Asked by: Interview Candidate | Asked on: Jul 25th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


D. Madhusudhana Rao ( 9885626575)
Answered On : Jul 26th, 2006

advantage :
In pl/sql if you want perform some actions more than one records you should user these cursors only.
bye using these cursors you process the query records. you can easily move the records and you can exit
from procedure when you required by using cursor attributes.
disadvantage:
using implicit/explicit cursors are depended by sutiation. if the result set is les than 50 or 100 records it is
better to go for implicit cursors. if the result set is large then you should use exlicit cursors. other wise it
will put burdon on cpu.
Answer Question

Login to rate this answer.


gouthami kodangal
Answered On : Aug 13th, 2006
There is no diff .Any one can be used while creaing a procedure.
Answer Question

Login to rate this answer.


Venkat9999
Answered On : Sep 21st, 2006

I think your implict and explict cursor concent needs a correction:


EXPLICIT CURSORS are used, when you are getting more than a single row of data
that needs to be processed further. Explicit cursor requires the cursor to be declared,
opened, fetched and then closed.

IMPLICIT CURSORS are used primarily when returning a single row of data.
With Implicit cursors, the declaration, open, fetch and close functions are done
automatically.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
Whenever we execute DML statements oracle assigns a work area called private sql area to store
information. Cursors meachanism allows us to name that private sql area there by access information
stored it.

The main disadvantage of cursors is that it process records sequentially. It increases number of context
switches between sql and pl/sql. It hampers the performance. We may overcome this problem by using
collections.

How to display the contents of a current record fetched in a ref cursor


Asked by: Interview Candidate | Asked on: Jul 17th, 2006

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


Mano
Answered On : Jul 19th, 2006

Hi,
U define a variable in the SQL Prompt as ref cursor ,Before that u have to write a procedure with a sys
ref cursor as a inout parameter.Then execute the procedure by passing the variable defined in the SQL
prompt and print the variable, It will display the records.
Mano
Answer Question

Login to rate this answer.


Shiv Mangal Rahi
Answered On : Jul 25th, 2006

Hi,
You could do the same as given under below for emp table.....
CREATE OR REPLACE procedure proc
as
begin
declare
v_empno emp.empno%type;
v_ename emp.ename%type;
cursor c_emp is
select empno,ename from emp;
begin
open c_emp;
loop
fetch c_emp into v_empno , v_ename;
dbms_output.put_line(v_empno||' '|| v_ename);
exit when c_emp%notfound;
end loop;
close c_emp;
end;
end proc;
/
Answer Question

Login to rate this answer.


gouthami kodangal
Answered On : Aug 13th, 2006
by making use of sql%rowfound.

What is HIGH WATERMARK?


I got to know that it is reset when the TRUNCATE command is executed on a
table.
Asked by: Interview Candidate | Asked on: Jun 21st, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


Supraja
Answered On : Jun 22nd, 2006

All Oracle segments have an upper boundary containing the data within the segment. This upper
boundary is called the "High Water Mark" or HWM", which means table cannot contain data beyond the
HWM
Answer Question

Login to rate this answer.


AyanM
Answered On : Jul 11th, 2006
View all answers by AyanM

Just to add more when Truncate command is issued it reduces the High Water Mark - the same can be
simulated in case of delete also using
alter table move;
Some time select query takes a lot of time but can't find any data - this is also because of HWM without
any data created by a delete statement
Answer Question

Login to rate this answer.


mariashylaja
Answered On : Aug 12th, 2006

Just to add more on this...


HWM is the upper boundary of the storage area of a table. when TRUNCATE is used on the table, all the
rows of that table is deleted and the HWM is decreased to the minimum size. But when DELETE is issued
on the table, the rows are deleted and nothing is done on the HWM. Thats is, the HWM is never
decreased even after the no of rows for the table is less or none. Thats is this keeps some space always
with its own.
Whats the other reated issue on this?.... when your query perform full table scan on the table on which
the DELETE is done, the query will scan the disk space till the HWM ( even if there is no row ) which will
result in bad response time.... But if TRUNCATE is used, the HWM willl be reset and the query will take
less time...
- Maria Antony
Answer Question
1 User has rated as useful.

Login to rate this answer.


Sphurti
Answered On : Aug 14th, 2006

Just to correct my friend's answer to some extend, HWM is basically the max space a particular table as
occupied till that pt. that doesn't mean that one cannot insert records more than a HWM. Once HWM is
crossed a new HWM is set for a table.
Answer Question

Login to rate this answer.


maria antony
Answered On : Aug 14th, 2006

Exactly dear friend. Thanks.


Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 1st, 2008

Within a segment, the high water mark indicates the amount of used space, or space that had been
formatted to receive data.You cannot release space below the high water mark (even if there is no data
in the space you want to deallocate). However, if the segment is completely empty, you can release
space using the TRUNCATE ... DROP STORAGE statement.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Sudhir Sorout
Answered On : Feb 4th, 2008
View all answers by Sudhir Sorout
yes when we truncate instead of delete, for deleting records , truncate set the HWM to 'zero' but if we
use only delete then HWM remain same ......

Sudhir Sorout

what is pragma?
can any one give me the example of autonomous Transaction ?
can we change the order of procedure parameter while calling procedure?
Asked by: Interview Candidate | Asked on: Jun 11th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


sagar singh
Answered On : Jun 11th, 2006

Pragmas are pre-compiler directives.


Answer Question

Login to rate this answer.


KHARTHY
Answered On : Jun 12th, 2006

ABOUT PRAGMApragma'S are private transactions , which does not affect anyother transaction. consider
procedure1 is calling procedure2, after finishing a transaction in the second procedure if a error occurs in
the procedure1 then all the transactions will be rolled back ( even tat happend in the procedure2) , if
pragma_autonomous transaction is used in the second procedure ...tat transaction can be
savedhttp://www.psoug.org/reference/autonomous_tx.htmlI HOPE TAT LINK WILL GIVE U A MUCH
BETTER PICTUREREGARDSd.r. KHARTHY
Answer Question

Login to rate this answer.


Shivraj G. Gutte
Answered On : Jun 18th, 2006
Pragama is compile directive .
Example of Autonomous transactions
Suppose you are updating value from table and you don't have update trigger on that table
but still you want to maintain a log entry for this update in seprate table.
You can write a procedure and call that procedure to do this . But you can not use COMMIT in this
called procedure because it will save the entire transaction.
To avoid this you can delclare this procedure as autonomous transaction procedure so that theexecution
of this procedure will be treated as totally diff. transaction and you can issue commit in called procedure
without affecting the main transaction.

Answer Question

Login to rate this answer.


pankaj_gauba
Answered On : Jun 22nd, 2006
View all questions by pankaj_gauba View all answers by pankaj_gauba

prgma is a compiler directive, it takes the oracle description error name from database for oracle error
code.
Example of autonous transaction:
Autonomous Transaction is a feature of oracle 8i which maintains the state of its
transactions and save it , to affect with the commit or rollback of the surrounding
transactions.

Here is the simple example to understand this :-

ora816 SamSQL :> declare


2 Procedure InsertInTest_Table_B
3 is
4 BEGIN
5 INSERT into Test_Table_B(x) values (1);
6 Commit;
7 END ;
8 BEGIN
9 INSERT INTO Test_Table_A(x) values (123);
10 InsertInTest_Table_B;
11 Rollback;
12 END;
13 /

PL/SQL procedure successfully completed.

ora816 SamSQL :> Select * from Test_Table_A;


X
----------
123
ora816 SamSQL :> Select * from Test_Table_B;
X
----------
1

Notice in above pl/sql COMMIT at line no 6 , commits the transaction at line-no 5


and line-no 9. The Rollback at line-no 11 actually did nothing. Commit/ROLLBACK
at nested transactions will commit/rollback all other DML transaction before that.
PRAGMA AUTONOMOUS_TRANSACTION override this behavior.

Let us the see the following example with PRAGMA


AUTONOMOUS_TRANSACTION.

ora816 SamSQL :> declare


2 Procedure InsertInTest_Table_B
3 is
4 PRAGMA AUTONOMOUS_TRANSACTION;
5 BEGIN
6 INSERT into Test_Table_B(x) values (1);
7 Commit;
8 END ;
9 BEGIN
10 INSERT INTO Test_Table_A(x) values (123);
11 InsertInTest_Table_B;
12 Rollback;
13 END;
14 /

PL/SQL procedure successfully completed.

ora816 SamSQL :> Select * from Test_Table_A;

no rows selected

ora816 SamSQL :> Select * from Test_Table_B;

X
----------
1
With PRAGMA AUTONOMOUS_TRANSACTION , the transaction state maintained
independently . Commit/Rollback of nested transaction will no effect the other
transaction. It is advisable to increase the value of TRANSACTIONS parameter in
the INIT parameter file to allow for the extra concurrent transaction .

can we change the order of procedure parameter while calling procedure?


Yes we can change the order , it is called Named Notation

Answer Question
2 Users have rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Feb 1st, 2008
Using Named & Combination Parameter passing Methods you can change the order of
parameter in a procedure
Named: List actual parameters in arbitrary order by associating each with its corresponding
formal parameter.
• Combination: List some of the actual parameters as positional and some as named.
Answer Question
1 User has rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Feb 18th, 2008

A pragma is compiler directive. Pragmas are processed at compile time, not at run time. They pass
information to the compiler.
Answer Question

Login to rate this answer.

can we use commit in trigger and cursors?


Asked by: Interview Candidate | Asked on: Jun 11th, 2006

 First

 Previous

 Next
 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


Soumi
Answered On : Jun 12th, 2006

Yes, you can fire 'commit' using autonomous transaction.


Answer Question

Login to rate this answer.


anjireddy
Answered On : Jun 16th, 2006

no u cant give commit in triggers


Answer Question

Login to rate this answer.


pankaj_gauba
Answered On : Jun 22nd, 2006
View all questions by pankaj_gauba View all answers by pankaj_gauba

Yes we write commit on trriger but only in autonomous transaction only. But is hardy recomended
Answer Question

Login to rate this answer.


srinivas
Answered On : Dec 1st, 2006

No we can't use commit in triggers, But we can use commit in Cursors


Regards
srinivas
Answer Question

Login to rate this answer.


PARI
Answered On : Mar 14th, 2007
NO we cannot use commit in triggers but ya we can call a procedure in which commit is used but its not
reccommended
pl/sql will not issue any error during compilation its only during the execution of trigger ,it will give err
message.
Answer Question

Login to rate this answer.


mohan kumar
Answered On : Apr 9th, 2007
Yes We can use commit statement in triggers with 10G.
Here is example :

CREATE OR REPLACE TRIGGER t_trigger


AFTER INSERT ON t1 FOR EACH ROW

DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
i PLS_INTEGER;
BEGIN
SELECT COUNT(*)
INTO i
FROM t1;

INSERT INTO t2
VALUES
(i);
COMMIT;
END;
/
Answer Question
1 User has rated as useful.

Login to rate this answer.


mohan
Answered On : Apr 9th, 2007
CREATE OR REPLACE TRIGGER t_trigger
AFTER INSERT ON t1 FOR EACH ROW

DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
i PLS_INTEGER;
BEGIN
SELECT COUNT(*)
INTO i
FROM t1;

INSERT INTO t2
VALUES
(i);
COMMIT;
END;
/

difference between truncate and delete


Asked by: Interview Candidate | Asked on: Jun 9th, 2006
 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 11 of 11 Answers


Nagabhushan S N
Answered On : Jun 9th, 2006

TRUNCATE
It's a DDL command and delete the complate table data and no rollback possible.It also resets the HIGH
WATERMARK which will imporve subsequent query performance.
DELETE
This is DML statement and require commit to make changes permanant.Can be used to delete selective
rows from table.Does not reset the High Watermark of the table.
Answer Question
1 User has rated as useful.

Login to rate this answer.


pankaj_gauba
Answered On : Jun 22nd, 2006
View all questions by pankaj_gauba View all answers by pankaj_gauba

Nagabhushan S N is right.
Answer Question

Login to rate this answer.


Vithal Patil
Answered On : Jun 23rd, 2006

TRUNCATE
It is possible to Delete data permanantly from the table without commit.
After deletion don't have rollback option.
DELETE
Require commit to make changes permanantly after delete command.
and also u can select particular row to delete with where conditions.
here after deletion have rollback option
Answer Question

Login to rate this answer.


D.Madhu
Answered On : Jun 29th, 2006
Delete

With Rollback Facility

DML Operation.

No Auto Commit.

Truncate

Without Rollback Facility

DDL Operation

Auto Commit
Answer Question

Login to rate this answer.


harshali patil
Answered On : Jun 1st, 2007
Truncate:
truncate require no commit
Delete:
delete require commit
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
1. Delete creates a rollback segment and cane be rollback. It is DML statement. Truncate is a DDL
statement and can not be rollback.

2. Delete command deletes records one by one where as truncte removes all the records at a time.

3. Truncate does not allow conditional remove of records where as delete allows conditional remove of
records

4.Trigger fires on delete statement where as trigger do not fires on truncate statement.
Answer Question
1 User has rated as useful.

Login to rate this answer.


cajie
Answered On : Oct 26th, 2009
View all answers by cajie

More difference are as below:

1) TRUNCATE fires 2 COMMIT before firing and after deleting the rows. The COMMIT fired before,
commits all the open uncommitted transactions.

2) TRUNCATE does not write into redo/undo logs which makes it faster than DELETE.

Correct me if I am wrong.

Cajie
Answer Question

Login to rate this answer.


geek.hari
Answered On : Dec 28th, 2009
View all answers by geek.hari
Delete will need an explicit commit or rollback to end the transaction. It will perform a redo log entry.
Truncate has inherent commit in it. It will not perform any redolog entry.
Answer Question

Login to rate this answer.


Gourvendra Singh
Answered On : Oct 9th, 2012
Major Differences are:
Delete: Delete command will delete either full table records or make a conditional deletion on the table.
Truncate: It will delete all the records of the table.
Delete: Delete will write the records in redo log buffer before deleting the records and erase the entry
from the redo log buffer once the transaction is committed or rollback.
Truncate: Truncate will delete the records directly from the table and records cannot be rollbacked. This
is why truncate runs faster then delete.
Truncate: It will reset the watermark of the table.
Answer Question

Login to rate this answer.


jose george
Answered On : Oct 15th, 2012
in addition to others

truncate is DDL hence would implicitly commit before executing


Delete is DML
truncate resets the High water mark
delete does not reset the high water mark
Answer Question

Login to rate this answer.


VASU
Answered On : Oct 20th, 2012
By using delete we have to delete particular records only..
If we use truncate we cannot retrieve the data permanently...

What is Mutation of a trigger? why and when does it oocur?


Asked by: rajanipriya | Member Since May-2006 | Asked on: Jun 6th, 2006
View all questions by rajanipriya View all answers by rajanipriya

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


sagar singh
Answered On : Jun 11th, 2006

When a trigger tries to access its own table, from which its fired, then the trigger is said to be mutating
and table is mutating table.
Answer Question

Login to rate this answer.


Arun Arumugam
Answered On : Jul 1st, 2006

A table is said to be a Mutating table under the following three circumstances1) When u try to do delete,
update, insert into a table through a trigger and at the same time u r trying to select the same table.2)
The same applies for a view3) Apart from that, if u r deleting (delete cascade),update,insert on the
parent table and doing a select in the child tableAll these happen only in a row level trigger
Answer Question
2 Users have rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Feb 18th, 2008

A mutating table is a table that is currently being modified by an UPDATE, DELETE, or INSERT statement.
A table is not considered mutating for STATEMENT triggers. The triggered table itself is a mutating table,
as well as any table referencing it with the FOREIGN KEY constraint. This restriction prevents a row
trigger from seeing an inconsistent set of data.
Answer Question

What is the data type of Null?


Asked by: Interview Candidate | Asked on: Jun 1st, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question
Showing Answers 1 - 15 of 15 Answers
Srinivas
Answered On : Jun 2nd, 2006
What is the Data Type of NULL?

In Tech Speack, NULL is a age old concept of nothing. This is not true in case of oracle. Oracle treats
NULL as character value of length of 0.

So, the default data type of NULL is a character data type and to prove it, we create a view on a null
column with an alias a, and then describe it to see the datatype and length of the string. Here is the
code.....

create view myview


as
select null a from dual;

describe myview;

The describe command shows that the column a has a data type of a varchar2(0).
So the Answer is : Character Type
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Nagesh
Answered On : Jun 5th, 2006

Adding to Prev comments Also Null is and undefined Value its not = 0 ' ' (Space) , also if Value of null
may not be equal to Null (null!= null)(its an unknow value or not defined value.
Answer Question

Login to rate this answer.


Mohan Cherin
Answered On : Jun 29th, 2006

Data type of NULL is any scalar variable i.e varchar2, char, number, date etc..
Answer Question

Login to rate this answer.


Girish Bhatia
Answered On : Jul 18th, 2006

Adding to Srinivas comments,


NULL has same datatype as the column, so if we make view with the following query
create view myview
as
select to_date(null) a from dual;
describe myview;
then datatype of it will be DATE, same way we can use to_number() function instead os to_date and see
the results.
Answer Question

Login to rate this answer.


Ritesh Ratna
Answered On : Nov 3rd, 2006

NULL value is accepted by Fields that are Number Datatype also. So how can it be varchar. As varchar
values can not be inserted in Field with Datatype as Number.
Answer Question

Login to rate this answer.


RoulRaj
Answered On : May 9th, 2007

Null may be any data type


Answer Question
Login to rate this answer.
g_sidhu
Answered On : Feb 1st, 2008

A null value means the value is unav ailable, unassigned, unknown, or inapplicable. Therefore, you
cannot test with = because a null cannot be equal or unequal to any value.
Answer Question

Login to rate this answer.


sanjoy.dubey
Answered On : Mar 3rd, 2008
View all questions by sanjoy.dubey View all answers by sanjoy.dubey

Null means indeterminate or unknown


Answer Question

Login to rate this answer.


chaitunitk
Answered On : Jun 2nd, 2010
View all answers by chaitunitk

Even some times NULL is treated as string of length 0;


Answer Question

Login to rate this answer.


diptisaxena
Answered On : Jul 15th, 2011
View all answers by diptisaxena

Datatype of NULL is CHAR(0)


Answer Question

Login to rate this answer.


manoj_lanser
Answered On : Jul 20th, 2011
View all answers by manoj_lanser

null is incomparable to any value.


Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11

Character (Char)
Answer Question

Login to rate this answer.


bhaskarreddy
Answered On : Oct 1st, 2011
Null is the undefined value...
Null is never equal to zero..
Answer Question

Login to rate this answer.


priya dharan raj
Answered On : Nov 14th, 2011
View all answers by priya dharan raj
it can be of any type ..since null can set as value for any variable in pl/sql with any data type
Answer Question

Login to rate this answer.

How can I speed up the execution of query when number of rows in the tables
increased
Asked by: Interview Candidate | Asked on: May 30th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Ramprasad K
Answered On : May 30th, 2006

Hi,
By tuning the query we can increase the execution speed with following TUNING TOOLS

MONITOR
SQL_TRACE and TKPROF

EXPLAIN PLAN
ORADBX

ANALYZE

UTLBSTAT (begin) and UTLESTAT (end)

-Thanks Alot.
Answer Question

Login to rate this answer.


sushilsb
Answered On : May 30th, 2006
View all answers by sushilsb

Standard practice is -
1. Indexed the columns (Primary key)
2. Use the indexed / Primary key columns in the where clause
3. check the explain paln for the query and avoid for the nested loops / full table scan (depending on the
size of data retrieved and / or master table with few rows)
Answer Question
1 User has rated as useful.

Login to rate this answer.


Syed Jawahar
Answered On : May 31st, 2006

HI
YOU CAN SPEED UP THE QUERY BY USING THE ROWID IN THE SELECT STATEMENT.
Answer Question

Login to rate this answer.


Srinivasa Bhargava
Answered On : Jul 27th, 2007
You have to index the columns properly and make sure that driving columns of the composite indexes are
used in the query .
You may as well wish to rebuild indexes as the number of records is increased.
Answer Question

Login to rate this answer.

What is autonomous Transaction? Where are they used?


Asked by: sbagai2001 | Member Since May-2006 | Asked on: May 26th, 2006
View all questions by sbagai2001 View all answers by sbagai2001

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


neema
Answered On : May 29th, 2006

Autonomous transaction is the transaction which acts independantly from the calling part and could
commit the process done.
example using prgma autonomous incase of mutation problem happens in a trigger.
Answer Question

Login to rate this answer.


pankaj_gauba
Answered On : Jun 22nd, 2006
View all questions by pankaj_gauba View all answers by pankaj_gauba
Autonomous Transaction is a feature of oracle 8i which maintains the state of
its transactions and save it , to affect with the commit or rollback of the
surrounding transactions.

Here is the simple example to understand this :-

ora816 SamSQL :> declare

2 Procedure InsertInTest_Table_B

3 is

4 BEGIN

5 INSERT into Test_Table_B(x) values (1);

6 Commit;
7 END ;

8 BEGIN

9 INSERT INTO Test_Table_A(x) values (123);

10 InsertInTest_Table_B;

11 Rollback;

12 END;

13 /

PL/SQL procedure successfully completed.

ora816 SamSQL :> Select * from Test_Table_A;

----------

123

ora816 SamSQL :> Select * from Test_Table_B;

----------

Notice in above pl/sql COMMIT at line no 6 , commits the transaction at


line-no 5 and line-no 9. The Rollback at line-no 11 actually did nothing.
Commit/ROLLBACK at nested transactions will commit/rollback all other DML
transaction before that. PRAGMA AUTONOMOUS_TRANSACTION override this behavior.

Let us the see the following example with PRAGMA AUTONOMOUS_TRANSACTION.

ora816 SamSQL :> declare

2 Procedure InsertInTest_Table_B

3 is
4 PRAGMA AUTONOMOUS_TRANSACTION;

5 BEGIN

6 INSERT into Test_Table_B(x) values (1);

7 Commit;

8 END ;

9 BEGIN

10 INSERT INTO Test_Table_A(x) values (123);

11 InsertInTest_Table_B;

12 Rollback;

13 END;

14 /

PL/SQL procedure successfully completed.

ora816 SamSQL :> Select * from Test_Table_A;

no rows selected

ora816 SamSQL :> Select * from Test_Table_B;

----------

With PRAGMA AUTONOMOUS_TRANSACTION , the transaction state maintained


independently . Commit/Rollback of nested transaction will no effect the other
transaction. It is advisable to increase the value of TRANSACTIONS parameter in
the INIT parameter file to allow for the extra concurrent transaction .
Answer Question
1 User has rated as useful.

Login to rate this answer.


rampratap409
Answered On : Sep 23rd, 2006
View all questions by rampratap409 View all answers by rampratap409
Autonomous_transcation is used to create a new session. It is more useful when you want to have log
like:

You want when ever update statement is fired on emp table. You want a entry should be made in
logfile that emptable is attempted to update no matter updation was successful or not

CREATE TABLE EMPLOG(TERMINAL_NAME VARCHAR2(50), UPDATE_DATE DATE);

CREATE OR REPLACE TRIGGER UPDATE_EMP_TRIG

BEFORE UPDATE ON EMP

DECLARE

RMSG VARCHAR2(50) ;

PRAGAMA AUTONOMOUS_TRANSACTION;

BEGIN

SELECT ' EMP TABLE IS UPDATED FROM TERMINAL : '||USERENV('TERMINAL') INTO RMSG

FROM DUAL;

INSERT INTO EMPLOG VALUES(RMSG, SYSDATE);

COMMIT;

END;

/
now if user issues

UPDATE EMP SET SAL = SAL + 400 ;

ROLLBACK;

This query will not effect emp table but "emplog" will have a entry
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 1st, 2008
Autonomous Transaction are use for writing to an error log table. Upon detecting an error in the
transaction, you can insert a row into the error log table and commit it, and then roll back the main
transaction without losing the insert.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 18th, 2008

A autonomous transaction starts with the first sql statement of the pl/sql block and ends with a commit.
It starts within the context of an another transaction called parent transaction and independent of it
(parent transaction).To make a transaction autonomous u have to declare PRAGMA
AUTONOMOUS_TRANSACTION at the beginning.
The main adv. of using PRAGMA AUTONOMOUS_TRANSATION is that weather the transaction made by
the parent may be rolled back due to some error, the autonomous transaction has no effect on it.
Suppose if there is any error in autonomous transaction … then >>>> what happen? ? ? don’t
worry***** It will save all the transactions just before the error occurred. Only the last transaction that
has error will be rolled back only if there is no error handler.
Answer Question

Login to rate this answer.


shinehere
Answered On : Feb 24th, 2008
View all answers by shinehere
An autonomous transaction is a transaction that is started within the context of another transaction,
called the parent transaction, but is independent of it.

An autonomous transaction can be committed or rolled back regardless of the state of the parent
transaction.

We can specify a transaction as autonomous using a PRAGMA.

PRAGMA AUTONOMOUS TRANSACTION

What is the difference between In, Out, InOut Parameters. Can we pass value or
reference or both to the In Out Parameter.
Asked by: sbagai2001 | Member Since May-2006 | Asked on: May 26th, 2006
View all questions by sbagai2001 View all answers by sbagai2001

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


narasimhulu
Answered On : May 31st, 2006
View all answers by narasimhulu
By default, OUT and IN OUT parameters are passed by value. The values of any IN
OUT parameters are copied before the subprogram is executed. During subprogram
execution, temporary variables hold the output parameter values. If the subprogram
exits normally, these values are copied to the actual parameters. If the subprogram
exits with an unhandled exception, the original parameters are unchanged.
Answer Question

Login to rate this answer.


sbagai2001
Answered On : May 31st, 2006
View all questions by sbagai2001 View all answers by sbagai2001

How do pass value to out or InOut Parameter by Reference.


Answer Question

Login to rate this answer.


bankimcn
Answered On : May 31st, 2006
View all answers by bankimcn

Eg for in out parameterBellow the parameter having x (eg x_return_status)as suffix is OUT,p (eg
p_calling_fn)as suffix is IN and px (px_trans_rec)as suffix is INOUT.Initializing In parameter is mandatory
to get desired output,OUT will be the result of procedure execution and INOUT will store result processed
by the procedure.Initialize fl_chr_validation, l_num_messg_count,l_chr_messg,l_chr_trans,l_chr_disttrans
proc1( p_validation_level => l_chr_validation , x_return_status => l_chr_return_status , x_msg_count
=> l_num_messg_count , x_msg_data => l_chr_messg , p_calling_fn => NULL , px_trans_rec =>
l_chr_trans , px_dist_trans_rec => l_chr_disttrans);NOTE:- for better analysis/execution Always initkialize
all the parameter IN and OUT.
Answer Question

Login to rate this answer.


pankaj_gauba
Answered On : Jun 22nd, 2006
View all questions by pankaj_gauba View all answers by pankaj_gauba
In
1 Default mode
2 Value is passed into
subprogram
3 Formal parameter acts as
a constant
4 Actual parameter can be a
literal, expression,
constant, or initialized
variable
5 Can be assigned a default
value
OUT
1 Must be specified
2 Returned to
calling
environment
3 Uninitialized variable
4 Must be a variable
5 Cannot be
assigned
a default value
INOUT
1 Must be specified
2 Passed into
subprogram;
returned to calling
environment
3 Initialized variable
4 Must be a variable
5 Cannot be
assigned
a default value

Can we pass value or reference or both to the In Out Parameter.


Yes, we can by using NOCOPY keyword
Answer Question

Login to rate this answer.


Shefali
Answered On : Aug 15th, 2006
You can use NOCOPY hint for passing it by reference
Answer Question

Login to rate this answer.


raghav_sy
Answered On : Jan 15th, 2007
View all answers by raghav_sy

hi friends,
To make it simple, keep in mind,
IN : It is a CONSTANT in the sub-program and u can not modify its value in sub- program. if its value
is modified in the sub-program then it will give a error.
OUT: the out parameter will always have a NULL value during the begining of the sub-program, we can
modify its value in the sub-program and then this modified value can be sent to the calling program.
Suppose from calling evironment u are sending a variable which has some value to the sub-program, but
if that corresponding variable is mrked as OUT in the sub-program, then in the sub-program that value
will be replaced with NULL, and then the operation in the sub-program will be done.
NOTE: this behaviour can be changed using the NOCOPY option, but remmeber the restriction imposed
on NOPCOY.
IN-OUT: well this is the variable, where u can read the variable and write the variable.
And one more thing to note is that, for OUT and IN-OUT the variables will be passed by value. if
NOCOPY option is not used,
but the restriction with the NOCOPY is that its a hint to the compiler, and not necessary that the
compiler will be using it, so be careful while usin the NOCOPY option.
Answer Question

Login to rate this answer.


saishradha
Answered On : Nov 26th, 2008
View all answers by saishradha
Here is the answer in 1 line

IN-- value is used in a program.


It cannot be a variable .COuld be literal,expression,value .

OUT-- value is returned back from the program to the caller.Must be a variable.

IN OUT-- Its combination of IN and OUT as name suggests. It acts like a varible ie value can be used in
the program and than can be returned back to the caller from the program

Hope you get some idea.


Jai Sairam
1) Why it is recommonded to use INOUT instead of OUT parameter type in a
procedure?

2) What happen if we will not assign anything in OUT parameter type in a


procedure?
Asked by: Interview Candidate | Asked on: May 19th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Narender Reddy
Answered On : May 19th, 2006

Hi,OUT parameter will be useful for returning the value from subprogram, value can be assigned only
once and this variable cannot be assigned to another variable.IN OUT parameter will be used to pass the
value to subprogram and as well as it can be used to return the value to caller of subprogram. It acts as
explicitly declared variable. Therefore it can be assigned value and its value can be assigned to another
variable.So IN OUT will be useful than OUT parameter.
Answer Question

Login to rate this answer.


Arun Arumugam
Answered On : Jul 1st, 2006

1) IN OUT and OUT selection criteria depends upon the program need.if u want to retain the value that is
being passed then use seperate (IN and OUT)otherwise u can go for IN OUT.2)If nothing is assigned to a
out parameter in a procedure then NULL will be returned for that parameter.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
1.There is no hard and fast rule about this. Whether to use INOUT or OUT depends upon the situation.

2. If not assigned anything to OUT parameter it retuns NULL value.


Answer Question
2 Users have rated as useful.

Login to rate this answer.


KSPRDEEP
Answered On : Oct 17th, 2012
In parameter means it will insert the values
OUT parameters means it will print out put (pass values to output). If we not assigning any value to out
parameter it will take (print) NULL value.

INOUT means it take values as input and out put


Answer Question

Login to rate this answer.

1) Why it is recommonded to use INOUT instead of OUT parameter type in a


procedure?

2) What happen if we will not assign anything in OUT parameter type in a


procedure?
Asked by: Interview Candidate | Asked on: May 19th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Narender Reddy
Answered On : May 19th, 2006

Hi,OUT parameter will be useful for returning the value from subprogram, value can be assigned only
once and this variable cannot be assigned to another variable.IN OUT parameter will be used to pass the
value to subprogram and as well as it can be used to return the value to caller of subprogram. It acts as
explicitly declared variable. Therefore it can be assigned value and its value can be assigned to another
variable.So IN OUT will be useful than OUT parameter.
Answer Question

Login to rate this answer.


Arun Arumugam
Answered On : Jul 1st, 2006

1) IN OUT and OUT selection criteria depends upon the program need.if u want to retain the value that is
being passed then use seperate (IN and OUT)otherwise u can go for IN OUT.2)If nothing is assigned to a
out parameter in a procedure then NULL will be returned for that parameter.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
1.There is no hard and fast rule about this. Whether to use INOUT or OUT depends upon the situation.

2. If not assigned anything to OUT parameter it retuns NULL value.


Answer Question
2 Users have rated as useful.

Login to rate this answer.


KSPRDEEP
Answered On : Oct 17th, 2012
In parameter means it will insert the values
OUT parameters means it will print out put (pass values to output). If we not assigning any value to out
parameter it will take (print) NULL value.

INOUT means it take values as input and out put


Answer Question

Login to rate this answer.

What is the difference between User-level, Statement-level and System-level


Rollback? Can you please give me example of each?
Asked by: kameshakundy | Member Since Apr-2006 | Asked on: Apr 25th, 2006
View all questions by kameshakundy View all answers by kameshakundy

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


ramiya
Answered On : Apr 30th, 2006
What is the difference between User-level, Statement-level and System-level
Rollback? Can you please give me example of each?

Answer Question

Login to rate this answer.


KAILASH CHANDRA
Answered On : May 1st, 2006

no comments
Answer Question

Login to rate this answer.


rajanipriya
Answered On : Jun 6th, 2006
View all questions by rajanipriya View all answers by rajanipriya

please someone who knows it well , reply naaa!!!!!!!!!!


Answer Question

Login to rate this answer.


kamini
Answered On : Nov 7th, 2006

1. System - level or transaction level


Rollback the current transaction entirely on errors. This was the unique
behavior of old drivers becauase PG has no savepoint functionality until
8.0.

2. Statement
Rollback the current (ODBC) statement on errors (in case of 8.0 or later
version servers). The driver calls a SAVEPOINT command just before starting
each (ODBC) statement and automatically ROLLBACK to the savepoint on errors
or RELEASE it on success. If you expect Oracle-like automatic per statement
rollback, please use this level.
3. User Level
You can(have to) call some SAVEPOINT commands and rollback to a savepoint
on errors by yourself. Please note you have to rollback the current
transcation or ROLLBACK to a savepoint on errors (by yourself) to continue
the application
Answer Question
3 Users have rated as useful.

Login to rate this answer.


kameshakundy
Answered On : Nov 12th, 2006

Dear Kamini,
May I know what do you mean by PG
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 1st, 2008

Statement-level: Part of a transaction can be discarded by an implicit rollback if a statement execution


error is detected. If a single DML statement fails during execution of a transaction, it s effect is undone
by a statement-level rollback, but the changes made by the previous DML statements in the transaction
are not discarded. They can be committed or rolled back explicitly by the user

What is PL/Sql tables?

Is cursor variable store in PL/SQL table?


Asked by: Interview Candidate | Asked on: Apr 19th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


Sekhar
Answered On : Apr 20th, 2006
What is PL/Sql tables?
Ans: PL/SQL tables are like arrays in C, the indexing starts from 1.
Is cursor variable store in PL/SQL table?
pls be clear with ur question.
Answer Question

Login to rate this answer.


pravin
Answered On : Apr 26th, 2006

pl/sql table is temparary table which is used to store records temrparaily in PL/SQL Block, whenever block
completes execution, table is also finished.
Answer Question

Login to rate this answer.


pandish
Answered On : Apr 30th, 2006
View all questions by pandish View all answers by pandish

Cursor is a pointer to a memory location, where all the rows have been retrieved
Answer Question

Login to rate this answer.


manu
Answered On : May 17th, 2006

Pl/Sql Table is like C Array .


Cursor variable doesn't store with pl/sql Table .
IT is a pointer to cursor & it is not item, It is dynamic.
Answer Question

Login to rate this answer.


sbagai2001
Answered On : May 30th, 2006
View all questions by sbagai2001 View all answers by sbagai2001
DECLARE
TYPE EmpCurTyp IS REF CURSOR; // Reference Cursor - weak
TYPE NumList IS TABLE OF NUMBER; // Table of Number
TYPE NameList IS TABLE OF VARCHAR2(25); // Table of varchar2
emp_cv EmpCurTyp;
empids NumList;
enames NameList;
sals NumList;
BEGIN
OPEN emp_cv FOR 'SELECT employee_id, last_name FROM employees';
FETCH emp_cv BULK COLLECT INTO empids, enames; // fetching cursor into tables
CLOSE emp_cv;
EXECUTE IMMEDIATE 'SELECT salary FROM employees'
BULK COLLECT INTO sals;
END;
/

what is difference between varray and nested table.


can u explain in brief and clear my these concepts.
also give a small and sweet example of both these.
Asked by: Interview Candidate | Asked on: Apr 1st, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


Deepika S Verma
Answered On : Apr 4th, 2006

According to O Reilly Book , the main difference between Index-By Table(pl-Sql Table) , Varray and
nested tables are -

Index-By Table Nested Table VARRAY

Dimensionality Single Single Single

Usable in SQL ? No Yes Yes

Usable as column No Yes; data stored "out Yes; data stored "in
datatype in a table? of line" (in separate line" (in same table)
table)

Uninitialized state Empty (cannot be Atomically null; illegal Atomically null;


Index-By Table Nested Table VARRAY

null); elements to reference elements illegal to reference


undefined elements

Initialization Automatic, when Via constructor, fetch, Via constructor,


declared assignment fetch, assignment

In PL/SQL, elements BINARY_INTEGER Positive integer Positive integer


referenced via between 1 and between 1 and
(-2,147,483,647 ..
2,147,483,647 2,147,483,647
2,147,483,647)

Sparse? Yes Initially, no; after No


deletions, yes

Bounded? No Can be extended Yes

Can assign value to Yes No; may need to No; may need to
any element at any EXTEND first EXTEND first, and
time? cannot EXTEND
past upper bound

Means of extending Assign value to Use built-in EXTEND EXTEND (or TRIM),
element with a new procedure (or TRIM to but only up to
subscript condense), with no declared maximum
predefined maximum size

Can be compared for No No No


equality?

Retains ordering and N/A No Yes


subscripts when
stored in and
retrieved from
database?
Answer Question
Login to rate this answer.
Sravan Anumala
Answered On : Apr 13th, 2006

Varry and Nestead table both are belongs to CollectionsThe Main difference is Varray has Upper bound,
where as Nestead table doesn't. It's size is unconstrained like any other database tableNestead table can
be stored in DatabaseSyntax of Nestead TableTYPE nes_tabtype IS TABLE OF emp.empno%type;nes_tab
nes_tabtype;Syntax of VarryTYPE List_ints_t IS VARRAY(8) OF NUMBER(2);aList
List_ints_t:=List_ints_t(2,3,5,1,5,4);
Answer Question

Login to rate this answer.


Ganesh Ashok Korde
Answered On : Feb 9th, 2007

Nested table can be indexed where as VArray can't.


Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 18th, 2008
Nested tables are unbounded.
Initially dense but can become sparse through deletions.
Order is not preserved
Can be indexed

VARRAYs are always bounded(varying arrays have a limited number of entries)


Never sparse.
When you store and retrieve a VARRAY, its element order is preserved.
Cannot be indexed
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
The following are the main differences between nested tables and varray

1. Nested tables are unbounded where as varray has maximun limit.


2. Nested tables are dense intially but can be sparse latter. So you can delete individual elements from
nested tables. Varrays are always dense .It is not possible to delete individual elements in varrays.
3. Varrays stores data in-line. Nested tables are stored seperately , main table maintains a pointer to
nested table.
4. When stored in database varrays retain their order where as nested tables do not.
What steps should a programmer should follow for better tunning of the PL/SQL
blocks?
Difference between procedure and function?
What is the use of ref cursor return type?
Asked by: aseemnaithani | Member Since Feb-2006 | Asked on: Mar 15th, 2006
View all questions by aseemnaithani View all answers by aseemnaithani

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


gomathi
Answered On : Mar 18th, 2006

The main difference between procedure and function,function should return a value.procedure need not
Answer Question
1 User has rated as useful.

Login to rate this answer.


Antony Gubert
Answered On : Mar 20th, 2006

Ref cursor return type can be used when it's required that a procedure / function need to return set of
records.
Answer Question

Login to rate this answer.


Savithri
Answered On : Apr 2nd, 2006

Tuning can be taken care by using the Correct Index on the table.We should not use Not equal to,
Distinct on the Indexed columns.
Answer Question

Login to rate this answer.


Keshav
Answered On : May 22nd, 2006
SQL Queries Best Practices

1. Always use the where clause in your select statement to narrow the number of rows
returned.
If we dont use a where clause, the Oracle performs a full table scan on our table and
returns all of the rows.

2. Use EXISTS clause instead of IN clause as it is more efficient than IN and performs
faster.

Ex:

Replace
SELECT * FROM DEPT WHERE DEPTNO IN
(SELECT DEPTNO FROM EMP E)
With
SELECT * FROM DEPT D WHERE EXISTS
(SELECT 1 FROM EMP E WHERE D.DEPTNO = E.DEPTNO)

Note: IN checks all rows. Only use IN if the table in the sub-query is extremely
small.

3. When you have a choice of using the IN or the BETWEEN clauses in your SQL, use
the BETWEEN clause as it is much more efficient than IN.
Depending on the range of numbers in a BETWEEN, the optimizer will choose to do a
full table scan or use the index.

4. Avoid WHERE clauses that are non-sargable. Non-sargable search arguments in the
WHERE clause, such as "IS NULL", "OR", "<>", "!=", "!>", "!<", "NOT", "NOT
EXISTS", "NOT IN", "NOT LIKE", and "LIKE %500" can prevent the query optimizer
from using an index to perform a search. In addition, expressions that include a
function on a column, or expressions that have the same column on both sides of the
operator, are not sargable.

Convert multiple OR clauses to UNION ALL.

5. Use equijoins. It is better if you use with indexed column joins. For maximum
performance when joining two or more tables, the indexes on the columns to be
joined should have the same data type.

6. Avoid a full-table scan if it is more efficient to get the required rows through an
index. It decides full table scan if it has to read more than 5% of the table data (for
large tables).

7. Avoid using an index that fetches 10,000 rows from the driving table if you could
instead use another index that fetches 100 rows and choose selective indexes.
8. Indexes can't be used when Oracle is forced to perform implicit datatype
conversion.

9. Choose the join order so you will join fewer rows to tables later in the join order.
 use smaller table as driving table
 have first join discard most rows

10. Set up the driving table to be the one containing the filter condition that eliminates
the highest percentage of the table.

11. In a where clause (or having clause), constants or bind variables should always be
on the right hand side of the operator.

12. Do not use SQL functions in predicate clauses or WHERE clauses or on indexed
columns, (e.g. concatenation, substr, decode, rtrim, ltrim etc.) as this prevents the
use of the index. Use function based indexes where possible

SELECT * FROM EMP WHERE SUBSTR (ENAME, 1, 3) = KES

Use the LIKE function instead of SUBSTR ()

13. If you want the index used, dont perform an operation on the field.

Replace
SELECT * FROM EMPLOYEE WHERE SALARY +1000 = :NEWSALARY

With
SELECT * FROM EMPLOYEE WHERE SALARY = :NEWSALARY 1000

14. All SQL statements will be in mixed lower and lower case. All reserve words will be
capitalized and all user-supplied objects will be lower case. (Standard)

15. Minimize the use of DISTINCT because it forces a sort operation.

16. Try joins rather than sub-queries which result in implicit joins

Replace
SELECT * FROM A WHERE A.CITY IN (SELECT B.CITY FROM B)

With
SELECT A.* FROM A, B WHERE A.CITY = B.CITY

17. Replace Outer Join with Union if both join columns have a unique index:

Replace
SELECT A.CITY, B.CITY FROM A, B WHERE A.STATE=B.STATE (+)

With
SELECT A.CITY, B.CITY FROM A, B WHERE A.STATE=B.STATE
UNION
SELECT NULL, B.CITY FROM B WHERE NOT EXISTS
(SELECT 'X' FROM A.STATE=B.STATE)

18. Use bind variables in queries passed from the application (PL/SQL) so that the same
query can be reused. This avoids parsing.
19. Use Parallel Query and Parallel DML if your system has more than 1 CPU.

20. Match SQL where possible. Applications should use the same SQL statements
wherever possible to take advantage of Oracle's Shared SQL Area. The SQL must
match exactly to take advantage of this.

21. No matter how many indexes are created, how much optimization is done to queries
or how many caches and buffers are tweaked and tuned if the design of a database
is faulty, the performance of the overall system suffers. A good application starts
with a good design.

22. The following operations always require a sort:

SELECT DISTINCT
SELECT UNIQUE
SELECT ....ORDER BY...
SELECT....GROUP BY...
CREATE INDEX
CREATE TABLE.... AS SELECT with primary key specification
Use of INTERSECT, MINUS, and UNION set operators
Unindexed table joins
Some correlated sub-queries
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Poojitha Somareddy
Answered On : May 26th, 2006
Also the order in which the conditions are given in the 'WHERE' cluase are very important while performing a
'Select' query. The Performance Difference is unnoticed ifother wise the query is run on a Massive Database.
For example for a select statement,
SELECT Emp_id FROM Emp_table WHERE Last_Name = 'Smith' AND Middle_Initial = 'K' AND Gender
= 'Female';
The look up for matches in the table is performed by taking the conditions in the WHERE cluase in the reverse order
i.e., first all the rows that match the criteria Gender = 'Female' are returned and in these returned rows, the conditon
Last_Name = 'Smith' is looked up.
There fore, the order of the conditions in the WHERE clause must be in such a way that the last condition gives
minimum collection of potential match rows and the next condition must pass on even little and so on. So, if we fine
tune the above query, it should look like,
SELECT Emp_id FROM Emp_table WHERE Gender = 'Female' AND Middle_Initial = 'K' AND
Last_Name = 'Smith' ; as Last_Name Smith would return far more less number of rows than Gender = 'Female' as
in the former case.
Answer Question

Login to rate this answer.


ptmich
Answered On : May 28th, 2012
View all answers by ptmich

Ref cursor is used to declare a pointer variable. When you return a ref cursor, you are returning a pointer
variable.
Answer Question

Login to rate this answer.


Aniruddha Das
Answered On : Jun 11th, 2012

If you want to take care of performance tuning you need to take care of sub-queries as they takes a lot
of time to executing in side the pl-sql blocks.
Answer Question

Login to rate this answer.

what is p-code and sourcecode ?


Asked by: Interview Candidate | Asked on: Mar 3rd, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Ashok kr. Choubey
Answered On : Mar 4th, 2006
P-code is Pre-complied code stored in Public cache memory of System Global Area after the Oracle
instance is started, whereas sourcecode is a simple code of sp, package, trigger, functions etc which are
stored in Oracle system defined data dictionary. Every session of oracle access the p-code which have the
Execute permission on that objects.
Source code stored in user_objects data dictinary for user defined Store proc, Trigger, Package,
Function. DBA_object stores all the db objects in sp. DB. ALL_objects stores all the db objects in sp.
schema.
Answer Question

Login to rate this answer.


Arun Arumugam
Answered On : Jul 1st, 2006

Source code: The code say a PLSQL block that the user types for the exectionP-Code: The source code
after -Syntax check, Parse tree generation, Symantic check, and further execution of the parse
tree..giving the final P-code ready for data fetch or manipulation ...
Answer Question
2 Users have rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
Source code is the Text of the procedure.It is accessed from USER_SOURCE data dictionary view.

P-code is Compiled object code which is not accessible.


Answer Question

Login to rate this answer.


grajeshkumar82
Answered On : Jun 9th, 2009
View all answers by grajeshkumar82
PCode is the parsed Code of the Procedure which is ready for
execution... This is the code that is loaded into the shared pool and
executed for you.
Answer Question

Login to rate this answer.

What is the difference between all_ and user_ tables ?


Asked by: Shweta_faqs | Member Since Oct-2005 | Asked on: Feb 15th, 2006
View all questions by Shweta_faqs View all answers by Shweta_faqs

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


tm1966_muthu
Answered On : Feb 17th, 2006
View all answers by tm1966_muthu
 An ALL_ view displays all the information accessible to the current user, including information from the
current user's schema as well as information from objects in other schemas, if the current user has
access to those objects by way of grants of privileges or roles.
While
 A USER_ view displays all the information from the schema of the current user. No special privileges
are required to query these views.
Answer Question

Login to rate this answer.


Ashok kr. Choubey
Answered On : Mar 4th, 2006

User_tables data dictionary contains all the tables created by the users under that schema.
whereas All_tables stores all the tables created in different schema. If any user id have the Grants for
access table of diff. schema then he can see that table through this dictionary.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
The information available in data dictionary tables is very difficult to understand. So it provides views in a
form that is easily understood by users. All these views are owned by sys.

Oracle provides three different type of views.

USER_XXXX -> Objects owned by the user.


ALL_XXXX -> List of objects that user has access to
DBA_XXXX -> List of all objects available in database.
Answer Question
3 Users have rated as useful.
Login to rate this answer.
pawan_kr2007
Answered On : Oct 11th, 2009
View all answers by pawan_kr2007
ALL_OBJECTS: Objects accessible to the user.
USER_OBJECTS: Describes all objects owned by the current user.
DBA_OBJECTS: Describes all objects in the database.

Based on what conditions can we decide whether to use a table or a view or a


materialized view ?
Asked by: Shweta_faqs | Member Since Oct-2005 | Asked on: Feb 10th, 2006
View all questions by Shweta_faqs View all answers by Shweta_faqs

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


rajat dey
Answered On : Feb 21st, 2006

hi,1. Security reasons we can use view2. If there is a more transaction in a base table we better chose
materialised view for performance 3. Depend upon the situation where we need to refresh the data in
specific time interval.
Answer Question

Login to rate this answer.


Ashok kr. Choubey
Answered On : Mar 4th, 2006

Hi All,
Tables we used for entity information physically in our DB.
View is a virtual representation of table data, for security and hiding the table column infor. we
used normally view. we uses for Report & MIS purposes for showing the data from more than two table.
Materalized view is used for remote data access and suitable for transaction related data storage in
distributed environment. It stores the data phyisically comparision to normal view. It can refreshes the
remote data auto. and forcefully/manually.
--if the refresh mode is Force
dbms_mview.refresh('Ashok_mview')
Answer Question

Login to rate this answer.


Deepika S Verma
Answered On : Apr 19th, 2006

Table is the basic entity in any RDBMS , so for storing data you need table .
for view - if you have complex query from which you want to extract data again and again , moreover it
is a standard data which is required by many other user also for REPORTS generation then create view .
Avoid to insert / update / delete through view unless it is essential. keep view as read only (FOR
SHOWING REPORTS)
for materialized view - this view ia mainly used in datawarehousing . if you have two databases and you
want a view in both databases , remember in datawarehousing we deal in GB or TB datasize . So create
a summary table in a database and make the replica(materialized view) in other database.
when to create materialized view-
[1] if data is in bulk and you need same data in more than one database then create summary table at
one database and replica in other databases
[2] if you have summary columns in projection list of query.
main advatages of materialized view over simple view are -
[1] it save data in database whether simple view's definition is saved in database
[2] can create parition or index on materialize view to enhance the performance of view , but cannot on
simple view.
Answer Question
4 Users have rated as useful.

Login to rate this answer.


pawan_kr2007
Answered On : Oct 11th, 2009
View all answers by pawan_kr2007

View: If a query is being used again and again then its better to create a view with that query. The query
gets stored in database as an object.
Materialized view: When you want you replicate the main data to multiple sites to reduce the load on
main server materialized views are used. Materialized view is a way of reducing load on main server and
ease of access to local replicated subset of actual data.
Answer Question

Login to rate this answer.


Radha
Answered On : Jul 14th, 2011

We use view to be confidential about the data and to avoid the complexity of a query. But Mviews are
used for performance problem, we use mviews for faster execution of a query. But we need to do regular
refresh for mviews.
Answer Question

What are ref cursors ?


Asked by: Shweta_faqs | Member Since Oct-2005 | Asked on: Feb 9th, 2006
View all questions by Shweta_faqs View all answers by Shweta_faqs

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


guru
Answered On : Feb 13th, 2006

They are similar to a normal curson but they can have different select stmts at run time.
Answer Question

Login to rate this answer.


rnr
Answered On : Feb 16th, 2006

cursors r private sql area used to access its stored information


Answer Question

Login to rate this answer.


manu
Answered On : Apr 6th, 2006

cursor is a memeory area where Oracle process SQL statment , whele ref cursor is a pointer to point
cursor area( memory location), So ref cursor holds location of cursor.
Answer Question

Login to rate this answer.


pankaj_gauba
Answered On : Jun 22nd, 2006
View all questions by pankaj_gauba View all answers by pankaj_gauba

Ref cursor is not bound to particular query.


Answer Question

Login to rate this answer.


nisha
Answered On : Aug 24th, 2006

ref cursor is a simple cursor but it is a datatype that allow developers to declare cursor variable
ref cursor has 2 types:-
strong ref cursor where we mention the return type with rowtype.
weak cursor where we don't mention return type.the advantage of this is that we can use weak cursor
with any query.it is not rowtype bounded.
for ex:-strong ref cursor
type curvar_type is ref cursor return emp%rowtype;
weak cursor:-
type curvar_type is ref cursor is
Answer Question
2 Users have rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
Cursor variables are like C or Pascal pointers, which hold the memory location (address) of some item
instead of the item itself. Thus, declaring a cursor variable creates a pointer, not an item. In PL/SQL, a
pointer has the datatype REF X, where REF is short for REFERENCE and X stands for a class of
objects. A cursor variable has datatype REF CURSOR.

Like a cursor, a cursor variable points to the current row in the result set of a multirow query. However,
cursors differ from cursor variables the way constants differ from variables. A cursor is static, but a cursor
variable is dynamic because it is not tied to a specific query. You can open a cursor variable for any type-
compatible query. This gives you more flexibility.

What is the difference between a reference cursor and normal cursor ?


Asked by: Shweta_faqs | Member Since Oct-2005 | Asked on: Feb 9th, 2006
View all questions by Shweta_faqs View all answers by Shweta_faqs

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


scoodels
Answered On : Feb 23rd, 2006

REF cursors are different than your typical, standard cursors. With standard cursors, you know the
cursor's query ahead of time. With REF cursors, you do not have to know the query ahead of time. With
REF Cursors, you can build the cursor on the fly
Answer Question
1 User has rated as useful.

Login to rate this answer.


Nagesh
Answered On : Feb 28th, 2006

Normal Cursor is a Static Cursor.


Refernce Cursor is used to create dynamic cursor.
There are two types of Ref Cursors:
1. Weak cursor and 2.Strong cursor
Type ref_name is Ref cursor [return type]
[return type] means %Rowtype
if Return type is mentioned then it is Strong cursor else weak cursor
The Reference cursor does not support For update clause.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Nantha
Answered On : Apr 18th, 2006

Normal cursor is used to process more than one record in plsql.


Refcusor is a type which is going to hold set of records which can be sent out through the procedure or
function out variables.
Answer Question

Login to rate this answer.


syed_ansar
Answered On : Oct 18th, 2006

we can use Ref cursor as an IN OUT parameter .

Can e truncate some of the rows from the table instead of truncating the full table.
Asked by: Interview Candidate | Asked on: Feb 9th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


Mohit Kumar Verma
Answered On : Feb 21st, 2006

No , it is not possible. Truncate is a DDL Command and we can not where clause in Truncate.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Unmesh
Answered On : May 10th, 2006

You can truncate few rows from a table if the table is partitioned. You can truncate a single partition and
keep remaining.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Girish Bhatia
Answered On : Jul 18th, 2006

Unmesh can you explain how is it possible with example.


Answer Question

Login to rate this answer.


Sourajit
Answered On : Dec 28th, 2006

Here is the example:


CREATE TABLE parttab (
state VARCHAR2(2),
sales NUMBER(10,2))
PARTITION BY LIST (state) (
PARTITION northwest VALUES ('OR', 'WA')
TABLESPACE uwdata,
PARTITION southwest VALUES ('AZ', 'CA')
TABLESPACE uwdata);

INSERT INTO parttab VALUES ('OR', 100000);


INSERT INTO parttab VALUES ('WA', 200000);
INSERT INTO parttab VALUES ('AZ', 300000);
INSERT INTO parttab VALUES ('CA', 400000);
COMMIT;

SELECT * FROM parttab;

ALTER TABLE parttab


TRUNCATE PARTITION southwest;

SELECT * FROM parttab;


Answer Question
2 Users have rated as useful.

Login to rate this answer.


leelakrishna302
Answered On : Jun 15th, 2012
View all answers by leelakrishna302

We cannot
Answer Question

Login to rate this answer.


Vishal R Bhadange
Answered On : Aug 12th, 2012
Yes.
Yes we can truncate some of the rows from the table, But table should be partitioned & all the rows to be
deleted should be present in one single partition...
Answer Question

can i write plsql block inside expection


Asked by: Interview Candidate | Asked on: Feb 9th, 2006

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


Rupjit Roy
Answered On : Feb 23rd, 2006
Yes you can write PL/SQL block inside exception section. Suppose you want to insert the
exception detail into your error log table, that time you can write insert into statement in
exception part. To handle the exception which may be raised in your exception part, you can
write the PL/SQL code in exception part.
Answer Question
1 User has rated as useful.

Login to rate this answer.


samareshp
Answered On : Apr 15th, 2009
View all answers by samareshp

Sure, you can write plsql block inside exception.

Can any one explain Perforance Tuning in PL/SQL


Asked by: Interview Candidate | Asked on: Feb 7th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


tm1966_muthu
Answered On : Feb 17th, 2006
View all answers by tm1966_muthu

The different aspects of tuning PL/SQL are


Analyzing program performance.
Tuning access to compiled code.
Tuning access to your data.
Tuning your algorithms.
Major tools are
MONITOR
SQL_TRACE and TKPROF
EXPLAIN PLAN
ORADBX
ANALYZE
UTLBSTAT (begin) and UTLESTAT (end)
Enterprise Manager/Performance Pack
Answer Question

Login to rate this answer.


prafull.vn
Answered On : Mar 18th, 2006
View all questions by prafull.vn View all answers by prafull.vn

Tune your queries .. like use <= and >= instead of between in case of range specification.
Answer Question

Login to rate this answer.


Poojitha Somareddy
Answered On : May 26th, 2006

Also the order in which the conditions are given in the 'WHERE' cluase are very important while
performing a 'Select' query. The Performance Difference is unnoticed ifother wise the query
is run on a Massive Database.
For example for a select statement,
SELECT Emp_id FROM Emp_table WHERE Last_Name = 'Smith' AND Middle_Initial =
'K' AND Gender = 'Female';
The look up for matches in the table is performed by taking the conditions in the WHERE cluase
in the reverse order i.e., first all the rows that match the criteria Gender = 'Female' are returned
and in these returned rows, the conditon Last_Name = 'Smith' is looked up.
There fore, the order of the conditions in the WHERE clause must be in such a way that the last
condition gives minimum collection of potential match rows and the next condition must pass on
even little and so on. So, if we fine tune the above query, it should look like,
SELECT Emp_id FROM Emp_table WHERE Gender = 'Female' AND Middle_Initial =
'K' AND Last_Name = 'Smith' ; as Last_Name = 'Smith' would return far more less number of
rows than Gender = 'Female' as in the former Select case.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Maria Antony Samy
Answered On : Aug 29th, 2006

Hi Meenakshi,
It seems that I can get some more detail about TUNING. If I need to tune my query, what are the steps
that I need to take....I know nothing about tuning....If you find time, pls give me some idea...
Regards,
maria_antony2000@yahoo.com
Answer Question

Login to rate this answer.


ORA_CRAZY
Answered On : Nov 19th, 2009
View all answers by ORA_CRAZY
Using Bulk binding concepts, we can tune the PL/SQL job that takes long time due to millions of records.
Answer Question

Login to rate this answer.


neerajalatha
Answered On : Jul 5th, 2010
View all answers by neerajalatha

Performance tuning can be improved by using FOR ALL and BULK COLLECT clauses in place of FOR LOOP
and CURSORS which makes the application faster and better.
What happens when a package is initialized ?
Asked by: Shweta_faqs | Member Since Oct-2005 | Asked on: Jan 31st, 2006
View all questions by Shweta_faqs View all answers by Shweta_faqs

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 1 of 1 Answers


SANCHITA SARKAR
Answered On : Feb 2nd, 2006

when a package is initialised that is called for the first time the entire package is loaded into SGA and any
variable declared in the package is initialises.

What are the restrictions on Functions ?


Asked by: Shweta_faqs | Member Since Oct-2005 | Asked on: Jan 31st, 2006
View all questions by Shweta_faqs View all answers by Shweta_faqs

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question
Showing Answers 1 - 10 of 10 Answers
gayu_rec
Answered On : Feb 8th, 2006
View all answers by gayu_rec

(1).Only in parameters are allowed.No inout & out parameters are allowed.
(2).A DML statement containing a function cannot perform another DML operation on the same table.
Answer Question

Login to rate this answer.


Venu
Answered On : Feb 11th, 2006

We can use IN and IN OUT parameters with function, in Oracle 9i ver. 9.2. See below,

create or replace function f1 (num in out number) return number


as
begin
dbms_output.put_line ('Inside f1 num='||num);
num:=100;
return 10;
end;
/
declare
n1 number := 1;
begin
dbms_output.put_line('return val='||f1(n1));
dbms_output.put_line('out param='||n1);
end;
/
Answer Question

Login to rate this answer.


Anoop Sagar Pradhan
Answered On : Feb 17th, 2006

Restrictions of Functions:
1: It has to return a value.
2:Cannot return multiple values.
Answer Question

Login to rate this answer.


gomathi
Answered On : Mar 3rd, 2006

note:we can return more then one value using INOUT parameters.
Answer Question

Login to rate this answer.


pankaj_gauba
Answered On : Jun 22nd, 2006
View all questions by pankaj_gauba View all answers by pankaj_gauba

Restrictions on Calling Functions from


SQL Expressions
Functions called from SQL expressions cannot
contain DML statements.
Functions called from UPDATE/DELETE statements
on a table T cannot contain DML on the same table
T.
Functions called from an UPDATE or a DELETE
statement on a table T cannot query the same table.
Functions called from SQL statements cannot
contain statements that end the transactions.
Calls to subprograms that break the previous
restriction are not allowed in the function.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


venkatesh
Answered On : Jul 19th, 2007
Function cannot have DML statemets and we can use select statement in function
If you create function with DML statements we get message function will be created
But if we use in select statement we get error
Answer Question

Login to rate this answer.


Chandra K. Ravi
Answered On : Sep 18th, 2007

Functions cannot return LONG datatype value.


Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
We can use all three types of parameters in Functions
Here is a simple example

CREATE OR REPLACE FUNCTION TEST_FUNC(A IN NUMBER, B IN OUT NUMBER,C OUTNUMBE


R) RETURN NUMBER IS D NUMBER(3); BEGIN B := B + A; C :=B; D
:= A + B + C; RETURN D; END; DECLARE A1 NUMBER(3) := 10; B1 NUMBER
(3) := 20; C1 NUMBER(3) := 30; D1 NUMBER(3) := 40; BEGIN D1 := TEST_
FUNC(A1,B1,C1); DBMS_OUTPUT.PUT_LINE(A1 || ' ' || B1 || ' ' || C1 || '
' || D1); END;
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
In functions we can use all three types of parameters
here is a simple example

CREATE OR REPLACE FUNCTION TEST_FUNC(A IN NUMBER, B IN OUT NUMBER,C OUT NUMBER)


RETURN NUMBER IS
D NUMBER(3);
BEGIN
B := B + A;
C := B;
D := A + B + C;
RETURN D;
END;

DECLARE
A1 NUMBER(3) := 10;
B1 NUMBER(3) := 20;
C1 NUMBER(3) := 30;
D1 NUMBER(3) := 40;
BEGIN
D1 := TEST_FUNC(A1,B1,C1);
DBMS_OUTPUT.PUT_LINE(A1 || ' ' || B1 || ' ' || C1 || ' ' || D1);
END;
Answer Question

Login to rate this answer.

What type of binding is PL/SQL?


Asked by: Interview Candidate | Asked on: Jan 25th, 2006

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


dilipiyer
Answered On : Jan 28th, 2006
View all answers by dilipiyer

The assigning of values to PL/SQL variables in SQL statements is called binding. PL/SQL binding
operations fall into three categories:
 in-bind
 out-bind
 define
A DML statement can transfer all the elements of a collection in a single operation, a process known as
bulk binding. If the collection has 20 elements, bulk binding lets you perform the equivalent of 20
SELECT, INSERT, UPDATE, or DELETE statements using a single operation. This technique improves
performance by minimizing the number of context switches between the PL/SQL and SQL engines. With
bulk binds, entire collections, not just individual elements, are passed back and forth.
Answer Question
1 User has rated as useful.

Login to rate this answer.


chaitu
Answered On : May 27th, 2006

pl/sql uses early binding.


Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 16th, 2008
Before a PL/SQL program can be executed, it must be compiled. The PL/SQL compiler resolves
references to Oracle objects by looking up their definitions in the data dictionary. Then, the
compiler assigns storage addresses to program variables that will hold Oracle data so that Oracle
can look up the addresses at run time. This process is called binding.

How a database language implements binding affects runtime efficiency and flexibility. Binding at compile
time, called static or early binding, increases efficiency because the definitions of database objects are
looked up then, not at run time. On the other hand, binding at run time, called dynamic or late binding,
increases flexibility because the definitions of database objects can remain unknown until then.

Why Functions are used in oracle ?


Can Functions Return more than 1 values?
Why Procedures are used in oracle ?
What are the Disadvantages of packages?
What are the Global Variables in Packages?
Asked by: Interview Candidate | Asked on: Dec 16th, 2005

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 18 of 18 Answers


manju
Answered On : Dec 20th, 2005

functions are return a value.


No,Functions must return a single value.
procedure are used to perform an action.
variables in the package specification are called global variables
Answer Question

Login to rate this answer.


mvnagendra
Answered On : Dec 23rd, 2005
View all answers by mvnagendra

1) A function will return a value, adding to that , it is possible to use a function in SQL statements,
whereas procedures cannot be used.2)No, functions cannot retrun more than one value, instead one can
get this done in other way round by using OUT parameters for a function.3)To perform validations and
transactions on database tables.4)Memory usage is more.5)The variable defined inside Package
Specification are treated as Global variables, which can be referred externally.
Answer Question
3 Users have rated as useful.

Login to rate this answer.


PRATIK GHOSHAL
Answered On : Jan 8th, 2006

Hi,
function can return more than one value - one by return staement and others by OUT parameters.
Answer Question

Login to rate this answer.


senthil vinayagam
Answered On : Jan 28th, 2006

Function dost not have out parameters.


function should return single value only
Answer Question

Login to rate this answer.


Diptendu Hui
Answered On : Jan 28th, 2006
It is recommended that Not use OUT and INOUT parameter with Function to avoid the side effect.
Although we can declare a OUT parameter but it should return by the return statement and both should
have same data taypes.
So, We can't return more than one value from a function at a single point of time.
Answer Question

Login to rate this answer.


Rajeev C R
Answered On : Feb 1st, 2006

Both functions and procedures are using to do a special task or action, In functions it is must to return a
single value, where as in procedures its not compulsory, In functions with the help of OUT parameter we
can pass multiple outputs.
The functions can be used in DML statements , but it should satiesfy the function purity level. but
procedures cant use in DML statements.
Answer Question

Login to rate this answer.


Sekhar
Answered On : Apr 20th, 2006

You can call functions which returned one value from SQL where as procedures you can't
Answer Question

Login to rate this answer.


aseem naithani
Answered On : May 1st, 2006

Hi,
The functions are used where we can't used the procedure.i.e we can use a function the in select
statments,in the where clause of delete/update statments.But the procedure can't used like that.
It is true that function can return only one value, but a function can be used to return more than one
value,by using out parameters and also by using ref cursors.
There is no harm in using the out parameter,when functins are used in the DML statements we can't
used the out parameter(as per rules).
Answer Question

Login to rate this answer.


raj
Answered On : Oct 17th, 2006

Hii
A function can return more than one value. It can be done by using out parameters with the variables,
datatype and size, and calling them in the return clause.
Hope this will help you.
Bye.
Answer Question

Login to rate this answer.


hindol_saha
Answered On : Mar 27th, 2007
View all questions by hindol_saha View all answers by hindol_saha
Function can able to return more than one value using ref cursur...it will return on base of select
statement......
Answer Question

Login to rate this answer.


bhaskar
Answered On : Jun 9th, 2007

functions can return more than a value by returning a ref cursor variable instead of returning a single
value(varchar2 or number). pls notify if this breaks any rule or functionality of oracle ??
Answer Question

Login to rate this answer.


srianju
Answered On : Aug 11th, 2007
Function can have more than one value in a return value by using record structure

Define record type in a package and use this type in your function.
Answer Question

Login to rate this answer.


Tulashidas
Answered On : Sep 27th, 2007

1. Most use of the function is you can call function from your select or any exicuteble statment. You can't
call procedure like function.
2. You can pass any number of values to function and function will retern any number of values but it will
must returnone value.
3. Procedure is used for pass any number of parameter and return any number of values. You can call
procedure from any whare by using call function or execute function.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
Functions are use to compute a value, which must be returned to the calling environment.

A function must return a value to the calling environment. Although multiple RETURN
statements are allowed in a function (usually within an IF statement), only one RETURN
statement is executed, because after the value is returned, processing of the block ceases. To
have a function return multiple values is poor programming practice. Also, functions should be
free from side effects, which change the values of variables that are not local to the subprogram.
Procedure is use to perform an action.

Disadvantages of Packages: more memory is required when using packages as the whole
package is loaded into memory as soon as any object in the package is accessed native
compilation can take twice as long as normal compilation.

Global Variables: The variable defined inside Package Specification are treated as Global
variables, that can be referenced outside the package and is visible to external users. Global
package items must be declared in the package specification.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
Functions are used to compute a value

Using Return statement we can return only one value. Even in functions also we may return more than
one value using out parameter. But It is not a good practice to return more than one value using
functions.

Procedure are used to execute business logic.

Whenever you call a packaged pl/sql construct for the first time, entire package is loaded into memory.
High memory use is the disadvantage.

Variables declared in the package specification part of a package are called global variables.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
1.Functions are used to compute a value
2. Function can return more than one value using out paramater. But it is not good practice to return
more than one value in a function
3. Procedures are used to execute business logic
4. When a packaged object is called entire package is loaded into memory. High memory usage is
disadvantage.
5. The variable declared in pakage specification is called global variable.

Here is simple example for using outparameter in functions

CREATE OR REPLACE FUNCTION TEST_FUNC(A IN NUMBER, B IN OUT NUMBER,C OUTNUMBE


R) RETURN NUMBER IS D NUMBER(3); BEGIN B := B + A; C :=B; D
:= A + B + C; RETURN D; END; DECLARE A1 NUMBER(3) := 10; B1 NUMBER
(3) := 20; C1 NUMBER(3) := 30; D1 NUMBER(3) := 40; BEGIN D1 := TEST_
FUNC(A1,B1,C1); DBMS_OUTPUT.PUT_LINE(A1 || ' ' || B1 || ' ' || C1 || '
' || D1); END;
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
1.Functions are used to computer a value.
2.Function can return more than one value using out parameter. But it is not a good practice to return
more than one value in functions.
3.Procedures are used to execute business logic.
4. when a package object is called entire package is loaded into memory. High memory usage may be
disadvantage.
5. A variable declared in package specification part is called a global variable.

Example for using out parameter in functions


CREATE OR REPLACE FUNCTION TEST_FUNC(A IN NUMBER, B IN OUT NUMBER,C OUT NUMBER)
RETURN NUMBER IS
D NUMBER(3);
BEGIN
B := B + A;
C := B;
D := A + B + C;
RETURN D;
END;

DECLARE
A1 NUMBER(3) := 10;
B1 NUMBER(3) := 20;
C1 NUMBER(3) := 30;
D1 NUMBER(3) := 40;
BEGIN
D1 := TEST_FUNC(A1,B1,C1);
DBMS_OUTPUT.PUT_LINE(A1 || ' ' || B1 || ' ' || C1 || ' ' || D1);
END;
Answer Question

Login to rate this answer.


ravivenkat1234
Answered On : Apr 28th, 2009
View all answers by ravivenkat1234
Functions can have multiple out Parameters one with Return Parameter and others can be IN OUT
Parameter to the function. this way a function can return multiple out parameters.

Eg : Function ( a in number,
b in out number,
c in out number)
Return number;

What is bulk binding please explain me in brief ?


Asked by: Interview Candidate | Asked on: Dec 7th, 2005

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


Vinayak Tripathi
Answered On : Dec 14th, 2005

Bulk Binds (BULK COLLECT , FORALL ) are a PL/SQL technique where, instead of multiple individual
SELECT, INSERT, UPDATE or DELETE statements are executed to retrieve from, or store data in, at table,
all of the operations are carried out at once, in bulk.
This avoids the context-switching you get when the PL/SQL engine has to pass over to the SQL engine,
then back to the PL/SQL engine, and so on, when you individually access rows one at a time. To do bulk
binds with Insert, Update and Delete statements, you enclose the SQL statement within a
PL/SQL FORALL statement.
To do bulk binds with Select statements, you include the Bulk Collect INTO a collection clause in the
SELECT Statement instead of using Simply into .
Collections, BULK COLLECT and FORALL are the new features in Oracle 8i, 9i and 10g PL/SQL that can
really make a different to you PL/SQL performance
Answer Question
1 User has rated as useful.

Login to rate this answer.


Ashok kr. Choubey
Answered On : Mar 4th, 2006

Hi ,
Bulk Binding is used for avoiding the context switching between the sql engine and pl/sql engine. If we
use simple For loop in pl/sql block it will do context switching between sql and pl/sql engine for
each row processing that degrades the performance of pl/sql bloack.
So that for avoiding the context switching betn two engine we user FORALL keyword by using the
collection pl/sql tables for DML. forall is pl/sql keyword.
It will provides good result and performance increase.
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 7th, 2008
View all answers by krishnaindia2007
Generally to process large number of records in pl/sql we use cursors . But cursors process records
sequentially. It increases number of context switches between SQL and PL/SQL there by hampers
performance. We may over come this problem using bulk binding.

FOR ALL and BULK COLLECT together are called bulk binding.

In Bulk binding instead of handling records sequentially the operations are carried out at once in bulk.
There by Bulk binding improves performance by minimizing no of context switches between SQL and
PL/SQL.

Can we use commit or rollback command in the exception part of PL/SQL block?
Asked by: Interview Candidate | Asked on: Oct 19th, 2005

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 21 of 21 Answers


Sarat
Answered On : Oct 19th, 2005
No
Answer Question

Login to rate this answer.


santosh mhamunkar
Answered On : Oct 19th, 2005

yes
Answer Question
1 User has rated as useful.

Login to rate this answer.


suresh
Answered On : Nov 4th, 2005

how can u say we can use commands commit,rollback?


Answer Question

Login to rate this answer.


rishu
Answered On : Nov 8th, 2005

Yes
Answer Question

Login to rate this answer.


vardhan_81
Answered On : Nov 9th, 2005
View all questions by vardhan_81 View all answers by vardhan_81

no we can not use tcl(commit,rollback,savepoint) and ddl commands in exception block


Answer Question

Login to rate this answer.


answertoyourquery
Answered On : Nov 9th, 2005

Yes, we can use the TCL commands(commit/rollback) in the exception block of a stored
procedure/function. The code in this part of the program gets executed like those in the body without
any restriction. You can include any business functionality whenever a condition in main block(body of a
proc/func) fails and requires a follow-thru process to terminate the execution gracefully!
Answer Question
4 Users have rated as useful.

Login to rate this answer.


vinayak tripathi
Answered On : Dec 14th, 2005

Yes, u can use commit or rollback in exception block.


Answer Question
1 User has rated as useful.

Login to rate this answer.


PRATIK GHOSHAL
Answered On : Jan 8th, 2006

yes we can
Answer Question

Login to rate this answer.


Rupjit Roy
Answered On : Feb 23rd, 2006
Yes we can use commit/rollback in exception part. Example:
DECALRE
..
BEGIN
.
EXCEPTION
WHEN NO_DATA_FOUND THEN

INSERT INTO err_log(


err_code, code_desc)
VALUES(1403, No data found)

COMMIT;
RAISE;
END
Answer Question

Login to rate this answer.


Deepika S Verma
Answered On : Apr 19th, 2006

yes you can .. try this code


create table test1(x varchar2(20))
declare
x number;
begin
select sal into x from emp where ename like 'TTT%';
exception when no_data_found then
insert into test1 values('no data');
commit;
end;
/
select * from test1;
Answer Question
Login to rate this answer.
neema
Answered On : May 29th, 2006

Yes
Answer Question

Login to rate this answer.


Arup Chakraborty
Answered On : Nov 3rd, 2006

Yes, we can use Commit / Rollback in the Exception part. Declare ---Variable declaration Begin ----
Executable part Exception When others then dbms_output.put_line(sqlerrm); Rollback; END ;
Answer Question
1 User has rated as useful.

Login to rate this answer.


vandsavvy
Answered On : Jun 15th, 2008
View all answers by vandsavvy

Yes We can
Answer Question

Login to rate this answer.


aksingh283
Answered On : May 27th, 2011
View all answers by aksingh283
Yes , we can use commit or rollback in exception part of PL SQL Block .
Below is an anonymous PL SQL block , try this :

Declare
myexception EXCEPTION;
Begin
RAISE myexception;
EXCEPTION
When myexception then
insert into table_name values (......);
COMMIT;

insert into table_name values (.......);


ROLLBACK;
END;
Answer Question

Login to rate this answer.


subhash
Answered On : Jul 31st, 2011

yes we can......
Answer Question

Login to rate this answer.


geetha
Answered On : Aug 4th, 2011

no, we can't use exceptions in ddl statements.normal form sql or sql*plus,without explicitly issuing
commit or rollback statements.
Answer Question

Login to rate this answer.


Prashant
Answered On : Aug 30th, 2011

Yes, you can use commit/rollback in exception block.


Answer Question

Login to rate this answer.


Kunal Priyadarshi
Answered On : Sep 22nd, 2011
View all answers by Kunal Priyadarshi

yes.. surely.. you can use any TCL command within the exception block.
Answer Question

Login to rate this answer.


priya dharan raj
Answered On : Nov 14th, 2011
View all answers by priya dharan raj
we can use commi ,rollback inside exception block

EXCEPTION -- exception handlers begin


WHEN ZERO_DIVIDE THEN -- handles 'division by zero' error
INSERT INTO stats (symbol, ratio) VALUES ('XYZ', NULL);
COMMIT;
Answer Question

Login to rate this answer.


TIRUMALARAOKONDA
Answered On : Dec 11th, 2011
View all answers by TIRUMALARAOKONDA
Yes, we can use the commit/rollback statements in an exception blocks.
Answer Question

Login to rate this answer.


Susil Kumar Nagarajan
Answered On : Jan 20th, 2012
Yes. You can very well use COMMIT or ROLLBACK in exception block. But it is not a good idea to use, as
it will commit the previous transactions in the same PLSQL block. Make use of creating SAVEPOINTS and
commiting them when required.

What is the output of the following pl/sql block ?


declare
v_empno emp.empno%type;
begin
select empno into v_empno from emp where empno = 10;
exception
when others then
dbms_output.put_line ( 'no data found');
when no_data_found then
dbms_output.put_line ( 'ther is no data found ');
end;

when others then


*
ERROR at line 6:
ORA-06550: line 6, column 2:
PLS-00370: OTHERS handler must be last among the exception handlers of a block
ORA-06550: line 0, column 0:
PL/SQL: Compilation unit analysis terminated
Asked by: Interview Candidate | Asked on: Sep 20th, 2005

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


Suryam
Answered On : Oct 18th, 2005
always when others exception should be the last exception handling in sequence.
Answer Question
Login to rate this answer.
Neerajms
Answered On : Nov 21st, 2005
View all answers by Neerajms

When Others is always handeled at the very end of all handeled exceptions. In this others should be in
the last means after No_data_Found.
Answer Question

Login to rate this answer.


Lavanya Chowdary
Answered On : May 6th, 2007

If you are using the exception part in the prg "others" exception should be the last exception that is the
only mistake in the program.
Answer Question

Login to rate this answer.


ramyaselvi16
Answered On : Jun 26th, 2008
View all questions by ramyaselvi16 View all answers by ramyaselvi16
I think It will work,

declare
v_empno emp.empno%type;
begin
select empno into v_empno from emp where empno = 10;
exception
when no_data_found then
dbms_output.put_line ( 'ther is no data found ');
when others then
dbms_output.put_line ( 'no data found');
end;

Rgds

Ramya
Answer Question
1 User has rated as useful.

Login to rate this answer.


nandk.sharma
Answered On : Jun 27th, 2008
View all answers by nandk.sharma
The above PL/SQL code will throw an oracle exception ORA - 06550.

This is due the fact that the 'OTHERS' exception block must be at the last of all the exception in a BEGIN
END block.

In the above code if we put the no_data_found exception in the first place and the others exception after
that then the code will work properly.
Answer Question
1 User has rated as useful.

Login to rate this answer.


neerajalatha
Answered On : Jul 5th, 2010
View all answers by neerajalatha
when others then
*
ERROR at line 6:
ORA-06550: line 6, column 2:
PLS-00370: OTHERS handler must be last among the exception handlers of a block
ORA-06550: line 0, column 0:
PL/SQL: Compilation unit analysis terminated
This is right answer
Answer Question

Login to rate this answer.


kiran_marla
Answered On : Jul 6th, 2010
View all answers by kiran_marla

Error occurs, why because "when others" must and should be placed at last in exception block

What is Data Concarency and Consistency?


Data Concarency => Means that many users can access data at the same time.

Data Consistency => Means that each user sees a consistent view of the data, including visible changes
made by the user's own transactions and transactions of other users.
Asked by: Interview Candidate | Asked on: Sep 5th, 2005

 First

 Previous

 Next
 Last

Return back to PL/SQL

Answer Question

Showing Answers 1 - 2 of 2 Answers

tm1966_muthu

Answered On : Feb 17th, 2006

View all answers by tm1966_muthu

Concurrency
How well can multiple sessions access the same data simultaneously

Consistency
How consistent is the view of the data between and within multiple sessions, transactions or
statements

Answer Question

Login to rate this answer.

arvind kumar

Answered On : Apr 12th, 2006

types of triggers

Name the tables where characteristics of Package, procedure and functions


are stored ?
User_objects, User_Source and User_error.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


vinod kumar
Answered On : Nov 16th, 2005

user_source , user_object , user_errors


Answer Question

Login to rate this answer.


idonknowyou
Answered On : May 22nd, 2007
View all answers by idonknowyou
The Data dictionary tables/ Views where the characteristics of subprograms and Packages are stored are
mentioned below

a) USER_OBJECTS, ALL_OBJECTS, DBA_OBJECTS

b) USER_SOURCE, ALL_SOURCE, DBA_SOURCE

c) USER_DEPENCENCIES

d) USER_ERRORS, ALL_ERRORS, DBA_ERRORS


Answer Question
1 User has rated as useful.

Login to rate this answer

What is difference between a Cursor declared in a procedure and Cursor declared


in a package specification ?
A cursor declared in a package specification is global and can be accessed by other procedures or
procedures in a package.A cursor declared in a procedure is local to the procedure that can not be
accessed by other procedures.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


rampratap409
Answered On : Nov 1st, 2006
View all questions by rampratap409 View all answers by rampratap409

The scope of A cursor declared in a procedure is limited to that procedure only.


The Scope of cursor declared in a package specification is global .
Example:
create or replace package curpack is
cursor c1 is select * from emp;
end curpack;
This will create a package Now You can use this cursor any where. Like:
set serveroutput on
begin
for r1 in curpack.c1 loop
dbms_output.put_line(r1.empno||' '||r1.ename);
end loop;
end;
this will dispaly all empno and enames.
It will be better to use ref cursor in packages
Answer Question

Login to rate this answer.


ddkdhar
Answered On : Feb 13th, 2007
View all questions by ddkdhar View all answers by ddkdhar

if we declare in package body then what is difference b/w cusrsor..........?how many types of
refcursors..............?whata re the advantages of ref cursors....................?
Answer Question

Login to rate this answer.


divyesh
Answered On : Oct 13th, 2007

Ref cursors are used when you want cursor to hold any no. of columns in the row.
If you are not sure about row type at complile time you use ref cursors.

Sys_ref_cursors used when you want cursors to be passed from one procedures to another procedures or
functions.

What is Overloading of procedures ?


TheSame procedure name is repeated with parameters of different datatypes and parameters in different
positions, varying number of parameters is called overloading of procedures. e.g. DBMS_OUTPUT
put_line What is a package ? What are the advantages of packages ?
Asked by: Interview Candidate | Asked on: Jul 8th, 2005

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


Sagar
Answered On : Dec 6th, 2005

Overloading procs are 2 or more procs with the same name but different arguments.
Arguments needs to be different by class it self. ie char and Varchar2 are from same class.
Packages -
The main advantages of packages are -
1- Since packages has specification and body separate so, whenever any ddl is run and if any
proc/func(inside pack) is dependent on that, only body gets invalidated and not the spec. So any other
proc/func dependent on package does not gets invalidated.
2- Whenever any func/proc from package is called, whole package is loaded into memory and hence all
objects of pack is availaible in memory which means faster execution if any is called. And since we put all
related proc/func in one package this feature is useful as we may need to run most of the objects.
30 we can declare global variables in the package
Answer Question

Login to rate this answer.


baskar
Answered On : Apr 11th, 2007
Package is a schema object that groups logically related PL/SQL types, items and subprograms. Basically
contains two parts namely specification and body.

Advantages

Modularity
Easier application design
Hiding information
Added functionality
Better performance
Overloading
Answer Question

Login to rate this answer.


idonknowyou
Answered On : May 22nd, 2007
View all answers by idonknowyou
2 or more procedures or functions are called overloaded when

a) They have the same names


b) Different no of formal parameters defined
c) Formal parameters differ in their datatypes/Subtypes and not in the same family
d) They belong to same subprogram/package/PL SQL Block

They are not overloaded when

a) Any of the above points are not satisfied


b) RETURN datatype alone differs and not the formal parameters

The main purpose of overloading procedures is that, when a PL SQL block is found to do a same
operation with different inputs, we names them same and feed different parameters
Answer Question
1 User has rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
Overloading: Multiple subprograms of the same name
• Enables you to use the same name for different subprograms inside a PL/SQL block, a
subprogram, or a package
• Requires the formal parameters of the subprograms to differ in number, order, or data type
family
• Enables you to build more flexibility because a user or application is not restricted by the
specific data type or number of formal parameters
Note: Only local or packaged subprograms can be overloaded. You cannot overload stand-alone
subprograms.
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007

Definining two or more procedures with same name is called overloading of procedures. But they must
differ in no or order or datatype family of formal arguments.

Explain how procedures and functions are called in a PL/SQL block ?


Function is called as part of an expression. sal := calculate_sal ('a822'); procedure is called as a
PL/SQL statement calculate_bonus ('A822');
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


M.KUMARAN
Answered On : Nov 12th, 2005
Function is called as part of an expression.
sal := calculate_sal ('a822');
procedure is called as a PL/SQL statement
calculate_bonus ('A822');
KKK
Answer Question
2 Users have rated as useful.

Login to rate this answer.


idonknowyou
Answered On : May 22nd, 2007
View all answers by idonknowyou
Procedure can be called in the following ways

a) CALL direc

b) EXCECUTE from calling environment

c) from other procedures or functions or packages

Functions can be called in the following ways

a) EXCECUTE from calling environment. Always use a variable to get the return value.

What are advantages fo Stored Procedures / Extensibility,Modularity,


Reusability, Maintainability and one time compilation.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


P.Ravi
Answered On : Nov 17th, 2005

Extensibility,Modularity, Reusability, Maintainability and one time compilation.


Answer Question

Login to rate this answer.


ramya
Answered On : Jun 29th, 2007

Procedure is used to perform an action.


Answer Question

Login to rate this answer.


deviji2000
Answered On : Oct 16th, 2007
View all answers by deviji2000
procedures and function hv many benefits in addition to modularizing application development.

1) easy maintenance : sub programs are located in one location and hence it is easy to
- modify routines online without interfering with other users
- modify one routine to affect multiple applications
- modify one routine to eliminate duplicate testing

2) improved data security & integrity


controls indirect access to database objects fr non-privileged users with security privileges. as
a subprogram is executed with its definer's right by default, it is easy to restrict the access privilege by
granting a privilege only to execute the subprogram to a user.

3) improved performance
avoids pl/sql parsing at run time by parsing at compile time
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008

In addition to modularizing application development, stored procedures and functions have the
following benefits:
1) Improved performance
 Avoid reparsing for multiple users by exploiting the shared SQL area
 Avoid PL/SQL parsing at run time by parsing at compile time
 Reduce the number of calls to the database and decrease network traffic by bundling commands
• Easy maintenance
– Modify routines online without interfering with other users
– Modify one routine to affect multiple applications
– Modify one routine to eliminate duplicate testing
• Improved data security and integrity
– Control indirect access to database objects from nonprivileged users with security
privileges
– Ensure that related actions are performed together, or not at all, by funneling activity for
related tables through a single path
• Improved code clarity: By using appropriate identifier names to describe the actions of the routine,
you reduce the need for comments and enhance clarity.

What is a stored procedure ?


A stored procedure is a sequence of statements that perform specific function.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 5 of 5 Answers


xyz
Answered On : Oct 20th, 2005

Stored Procedure is the PlSQL subprgram stored in the databasse .


Answer Question

Login to rate this answer.


Kavitha Sengottaiyan
Answered On : Jan 27th, 2006
Stored Procedure
A program running in the database that can take complex actions based on the inputs you send
it. Using a stored procedure is faster than doing the same work on a client, because
the program runs right inside the database server. Stored procedures are nomally written
in PL/SQL or Java.
Answer Question

Login to rate this answer.


Like to become an Oracle geek
Answered On : May 22nd, 2007
A stored procedure is a subprogram that is stored in the database as a PCODE and thus called as a
standalone schema object.

a) It can be invoked directly from any calling environments, or other subprograms.

b) It is similar to any subprogram that accepts parameters and performs an action. It may or may not
return a value. This attribute differentiates it from another subprogram type called FUNCTION.

c) It can be nested

d) Is created by using the syntax CREATE OR REPLACE

e) This stored procedure can be seen as an object in the User_Objects and is different from the
procedures that are created in packages.

Answer Question
1 User has rated as useful.

Login to rate this answer.


ramesh_resides
Answered On : Jun 23rd, 2007
View all answers by ramesh_resides

Stored procedure is a sub program and stored in memory for repated execution

Where the Pre_defined_exceptions are stored ?


In the standard package. Procedures, Functions & Packages ;
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


pankaj_gauba
Answered On : Jun 22nd, 2006
View all questions by pankaj_gauba View all answers by pankaj_gauba
PL/SQL declares predefined exceptions in the STANDARD package.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
PL/SQL declares predefined exceptions in the STANDARD package.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007

Predefined exceptions are globally declared in standard package


Answer Question
2 Users have rated as useful.

What are the return values of functions SQLCODE and SQLERRM ?


SQLCODE returns the latest code of the error that has occurred.SQLERRM returns the relevant error
message of the SQLCODE.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


acpsrinivas
Answered On : Feb 25th, 2006
View all answers by acpsrinivas
Pl / Sql Provides Error Information via two Built-in functions, SQLCODE & SQLERRM.
SQLCODE Returns the Current Error Code.
Returns 1.
SQLERRM Returns the Current Error Message Text.
Returns " User Defined Exception "
Cheers,
Bonthu.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
• SQLCODE: Returns the numeric value for the error code• SQLERRM: Returns the message associated
with the error numberSQLCODE Value Description
0 No exception encountered
1 User-defined exception
+100 NO_DATA_FOUND exception
negative number Another Oracle server error number

What is Raise_application_error ?
Raise_application_error is a procedure of package DBMS_STANDARD which allows to issue an
user_defined error messages from stored sub-program or database trigger.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Raghavendra
Answered On : Nov 15th, 2006
Raise_application_error is used to create your own error messages which can be more descriptive than
named exceptions.
Syntax is:-
Raise_application_error (error_number,error_messages);
where error_number is between -20000 to -20999..
Answer Question
3 Users have rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
You can use this procedure to issue user-defined error messages from stored subprograms.
You can report errors to your application and avoid returning unhandled exceptions.
Syntax: raise_application_error (error_number,message[, {TRUE | FALSE}]);
Answer Question

Login to rate this answer.


SARANYA
Answered On : Jul 25th, 2011

i know that the error no in raise_application_error are non standard but tell me on what basis we are
giving those numbers? is that simply a number or it some implicit meaning ?
Answer Question

Login to rate this answer.


Ashutosh
Answered On : Oct 8th, 2012
Their classes of errors and diff. errors are divided among these classes simply because of ease in
classification,
For defining errors and error message with raise_application_error procedure by users the class of error
number ranges from 20000 to 20999.
That is only numbers from this interval can be used to defining your own error code
Answer Question

What is Pragma EXECPTION_INIT ? Explain the usage ?


The PRAGMA EXECPTION_INIT tells the complier to associate an exception with an oracle error. To get
anerror message of a specific oracle error. e.g. PRAGMA EXCEPTION_INIT (exception name, oracle
error number)
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


kehri_anurag
Answered On : Jan 13th, 2006
View all questions by kehri_anurag View all answers by kehri_anurag
Pragma exception_init Allow you to handle the Oracle predefined message by you'r own message.
means you can instruct compiler toassociatethe specific message to oracle predefined message at
compile time.This way you Improve the Readbility of your program,and handle it accoding to your own
way.
It should be declare at the DECLARE section.
example
declare
salary number;
FOUND_NOTHING exception;
Pragma exception_init(FOUND_NOTHING ,100);
begin
select sal in to salaryfrom emp where ename ='ANURAG';
dbms_output.put_line(salary);
exception
WHEN FOUND_NOTHING THEN
dbms_output.put_line(SQLERRM);
end;
Answer Question
2 Users have rated as useful.

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
PRAGMA EXCEPTION_INIT statement associate the declared exception with the standard
Oracle server error number. PRAGMA EXCEPTION_INIT tells the compiler to associate an
exception name with an Oracle error number. That allows you to refer to any internal exception
by name and to write a specific handler for it.
PRAGMA (also called pseudoinstructions) is the keyword that signifies that the
statement is a compiler directive, which is not processed when the PL/SQL block is
executed. Rather, it directs the PL/SQL compiler to interpret all occurrences of the
exception name within the block as the associated Oracle server error number.
Syntax
PRAGMA EXCEPTION_INIT(exception, error_number);
Answer Question

Login to rate this answer.


Devendra Tawar
Answered On : Apr 27th, 2011
View all answers by Devendra Tawar

Use for handle user defined exception.


Answer Question

Login to rate this answer.

What is an Exception ? What are types of Exception ?


Exception is the error handling part of PL/SQL block. The types are Predefined and user defined.
Some of Predefined exceptions are. CURSOR_ALREADY_OPEN DUP_VAL_ON_INDEX
NO_DATA_FOUND TOO_MANY_ROWS INVALID_CURSOR INVALID_NUMBER
LOGON_DENIED NOT_LOGGED_ON PROGRAM-ERROR STORAGE_ERROR
TIMEOUT_ON_RESOURCE VALUE_ERROR ZERO_DIVIDE OTHERS.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 4 of 4 Answers


Surender Rana
Answered On : Jan 24th, 2006

Exception is nothing but Error. In PL/SQL block we handle these errors in Exception block.There are two
types of exceptions: 1> System define exception and 2> User define exception. System define exception
predefine exceptions like 'ZERO_DEVIDE',NO_DATA_FOUND etc.User define exceptions is defined by the
user and raise in the excution block and then call into the exception block.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Rana
Answered On : Apr 9th, 2006
EXCEPTIONS

Predefined
Do not declare and allow the Oracle server to raise implicitly

NO_DATA_FOUND
TOO_MANY_ROWS
INVALID_CURSOR
ZERO_DIVIDE
INVALID_CURSOR

WHEN EXCEPTION THEN

Non predefined
Declare within the declarative section and allow allow Oracle server
to raise implicitly
o SQLCODE Returns the numeric value for the seeor code
o SQLERRM Returns the message associated with error number

DECLARE -- PRAGMA EXCEPTION_INIT (exception, error_number)


RAISE WHEN EXCEPTION_NAME THEN

User defined
Declare within the declarative section and raise explicitly.

IF confidition the
RAISE EXCEPTION or RAISE_APPLICATION_ERROR
Answer Question
1 User has rated as useful.

Login to rate this answer.


Lavanya Chowdary
Answered On : May 6th, 2007
Exception is nothing but error in the PL/SQL program. If any error occured in the PL/SQL program that
terminates from the program. To handle that exceptions we are using exception handling part in the
PL/SQL
There are three types of exceptions
1. predefined
2. non-predefined
3. user defined
Predefined exceptions are defined by the system we have some predefined exception names to handle
some exceptions
non-predefined exceptions are also raised by the system only but we dont have any predefined names
we have to trap the exceptions with error code defined by the system
User defined exceptions are defined by the user. He has to declare the exception, he has to raise the
exception.
Answer Question

Write the order of precedence for validation of a column in a table ?


I. done using Database triggers. ii. done using Integarity Constraints. I & ii. Exception :
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


prashant
Answered On : Jul 6th, 2006

ii. done using Integarity Constraints


Answer Question

Login to rate this answer.


Srinatha Reddy
Answered On : May 21st, 2008
View all answers by Srinatha Reddy
create table a ( b number, c number check (c >100) );

create or replace trigger t1


before insert on a
begin
dbms_output.put_line('this is before insert trigger');
end;
create or replace trigger t2
after insert on a
begin
dbms_output.put_line('this is after insert trigger');
end;

insert into a values (1,99);


/

this is before insert trigger

insert into a values (1,99)


*
ERROR at line 1:
ORA-02290: check constraint (XXINV.SYS_C00106711) violated

insert into a values (1,199);


/
this is before insert trigger
this is after insert trigger
1 row created.

So, if it is before insert trigger then the trigger will run first before the constriants in the table. if it is after
insert trigger , contraints are checked first and then trigger will run.

What happens if a procedure that updates a column of table X is called in a


database trigger of the same table ?
Mutation of table occurs.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


Sunil Yadav
Answered On : Oct 26th, 2005
To avoid the mutation table error ,the procedure should be declared as an AUTONOMOUS
TRANSACTION.
By this the procedure will be treated as an separate identity.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


rudra pratap
Answered On : Jul 5th, 2007

In order to avoid mutation table error we need to have a row level as well as a statment level trigger.
Answer Question

Login to rate this answer.

What are two virtual tables available during database trigger execution ?
The table columns are referred as OLD.column_name and NEW.column_name.For triggers related to
INSERT only NEW.column_name values only available.For triggers related to UPDATE only
OLD.column_name NEW.column_name values only available.For triggers related to DELETE only
OLD.column_name values only available.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 2 of 2 Answers


bambino_chakma
Answered On : Jul 15th, 2007
View all answers by bambino_chakma
The two virtual table available are old and new.
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
OLD and NEW are two virtual tables available during database trigger execution.

UPDATE statement has access to both old and new values.

INSERT statement has access only to new values. Old values are NULL for insert statement.

DELETE satement has access only to old values. New values are NULL for delete statement.

Is it possible to use Transaction control Statements such a ROLLBACK or


COMMIT in Database Trigger ? Why ?
It is not possible. As triggers are defined for each table, if you use COMMIT of ROLLBACK in a
trigger, it affects logical transaction processing.
Asked by: Interview Candidate | Asked on: Sep 2nd, 2005

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 10 of 10 Answers


ketan
Answered On : Jul 28th, 2005

Yes, it is possibale if your triggers is Autonomous Triggers than


Answer Question

Login to rate this answer.


Naidu
Answered On : Aug 22nd, 2005
Generally In triggers you can't use TCL commands.
But you can use TCL commands in Autonomous Triggers.
You can declare a trigger as Autonomous by providing PRAGMA AUTONOMOUS_TRANSACTION in the
beginning of the trigger.
At a same time you have to end your trigger with commit/rollback.
You can use these type of triggers to maintain log details of a table.
Answer Question
3 Users have rated as useful.

Login to rate this answer.


Taral Desai
Answered On : Sep 2nd, 2005

it's possible through pragma autonomous_transaction


Answer Question
1 User has rated as useful.

Login to rate this answer.


mahendra
Answered On : Sep 29th, 2005

If the trigger is declare as autonomous transaction, then it can have commit or rollback.
Answer Question

Login to rate this answer.


m
Answered On : Nov 12th, 2005

is it possible to use Transaction control command at block...


Answer Question

Login to rate this answer.


sureshchowdary
Answered On : May 3rd, 2007

Give me one example


Answer Question

Login to rate this answer.


Karthik
Answered On : May 4th, 2007
Autonomous Transaction is a feature of oracle 8i which maintains the state of
its transactions and save it , to affect with the commit or rollback of the
surrounding transactions.

Here is the simple example to understand this :-


ora816 SamSQL :> declare

2 Procedure InsertInTest_Table_B

3 is

4 BEGIN

5 INSERT into Test_Table_B(x) values (1);

6 Commit;

7 END ;

8 BEGIN

9 INSERT INTO Test_Table_A(x) values (123);

10 InsertInTest_Table_B;

11 Rollback;

12 END;

13 / PL/SQL procedure successfully completed.

ora816 SamSQL :> Select * from Test_Table_A; X---------- 123

ora816 SamSQL :> Select * from Test_Table_B; X---------- 1

Notice in above pl/sql COMMIT at line no 6 , commits the transaction at


line-no 5 and line-no 9. The Rollback at line-no 11 actually did nothing.
Commit/ROLLBACK at nested transactions will commit/rollback all other DML
transaction before that. PRAGMA AUTONOMOUS_TRANSACTION override this behavior.
Let us the see the following example with PRAGMA AUTONOMOUS_TRANSACTION.

ora816 SamSQL :> declare

2 Procedure InsertInTest_Table_B

3 is

4 PRAGMA AUTONOMOUS_TRANSACTION;

5 BEGIN

6 INSERT into Test_Table_B(x) values (1);


7 Commit;

8 END ;

9 BEGIN

10 INSERT INTO Test_Table_A(x) values (123);

11 InsertInTest_Table_B;

12 Rollback;

13 END;

14 /PL/SQL procedure successfully completed.

ora816 SamSQL :> Select * from Test_Table_A;no rows selected

ora816 SamSQL :> Select * from Test_Table_B; X---------- 1

With PRAGMA AUTONOMOUS_TRANSACTION, the transaction state maintained


independently. Commit/Rollback of nested transaction will no effect the other
transaction. It is advisable to increase the value of TRANSACTIONS parameter in
the INIT parameter file to allow for the extra concurrent transaction.
Answer Question
1 User has rated as useful.

Login to rate this answer.


bambino_chakma
Answered On : Jul 15th, 2007
View all answers by bambino_chakma
Yes ...it is possible ,provide the trigger is autonomus or else table mutation occur
Autonomus trigger can be defined using the trigger beggining with
Pragma autonomus _trancation and the trigger must have a commit/rollback statment at the end of
the trigger
Answer Question
1 User has rated as useful.

Login to rate this answer.


jockey
Answered On : Aug 2nd, 2007

Using autonomous_transaction it is possible


Answer Question

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008

COMMIT, ROLLBACK, and SAVEPOINT statements are not allowed within the trigger body. It is possible
to commit or rollback indirectly by calling a procedure, but it is not recommended because of side effects
to transactions.

What is a database trigger ? Name some usages of database trigger ?


Database trigger is stored PL/SQL program unit associated with a specific database table. Usages
are Audit data modifications, Log events transparently, Enforce complex business rules Derive
column values automatically, Implement complex security authorizations. Maintain replicate tables.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


tm1966_muthu
Answered On : Feb 17th, 2006
View all answers by tm1966_muthu
A database trigger is a stored procedure that is invoked automatically when a predefined event occurs.
Database triggers enable DBA's (Data Base Administrators) to create additional relationships between
separate databases.
For example, the modification of a record in one database could trigger the modification of a record in a
second database.
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
A database trigger is a named pl/sql block associated with a table and fires automatically when an event
occurs or something happens.

Data auditing , Implementing complex business rules, security are main uses of database triggers.
Answer Question
3 Users have rated as useful.

Login to rate this answer.


KSPRADEEP
Answered On : Oct 17th, 2012
Trigger is data base object .Trigger is block of code it is executed automatically when dml operations are
fired .

by using trigger we can do the auditing and perform a operation(modifications) on a tables (using dml
operation)
Answer Question

Explain the usage of WHERE CURRENT OF clause in cursors ?


WHERE CURRENT OF clause in an UPDATE,DELETE statement refers to the latest row fetched from a
cursor. Database Triggers
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


kishorebabu
Answered On : Sep 20th, 2005
PL/SQL provides the WHERE CURRENT OF clause for both UPDATE and DELETE statements inside a
cursor in order to allow you to easily make changes to the most recently fetched row of data.
The general format for the WHERE CURRENT OF clause is as follows:
UPDATE table_name SET set_clause WHERE CURRENT OF cursor_name;DELETE FROM
table_name WHERE CURRENT OF cursor_name;
Notice that the WHERE CURRENT OF clause references the cursor and not the record into which the next
fetched row is deposited.
The most important advantage to using WHERE CURRENT OF where you need to change the row fetched
last is that you do not have to code in two (or more) places the criteria used to uniquely identify a row in
a table. Without WHERE CURRENT OF, you would need to repeat the WHERE clause of your cursor in the
WHERE clause of the associated UPDATEs and DELETEs. As a result, if the table structure changes in a
way that affects the construction of the primary key, you have to make sure that each SQL statement is
upgraded to support this change. If you use WHERE CURRENT OF, on the other hand, you only have to
modify the WHERE clause of the SELECT statement.
This might seem like a relatively minor issue, but it is one of many areas in your code where you can
leverage subtle features in PL/SQL to minimize code redundancies. Utilization of WHERE CURRENT OF,
%TYPE, and %ROWTYPE declaration attributes, cursor FOR loops, local modularization, and other
PL/SQL language constructs can have a big impact on reducing the pain you may experience when you
maintain your Oracle-based applications.
Let's see how this clause would improve the previous example. In the jobs cursor FOR loop above, I want
to UPDATE the record that was currently FETCHed by the cursor. I do this in the UPDATE statement by
repeating the same WHERE used in the cursor because (task, year) makes up the primary key of this
table:
WHERE task = job_rec.task AND year = TO_CHAR (SYSDATE, 'YYYY');
This is a less than ideal situation, as explained above: I have coded the same logic in two places, and this
code must be kept synchronized. It would be so much more convenient and natural to be able to code
the equivalent of the following statements:

Delete the record I just fetched.


or:

Update these columns in that row I just fetched.


A perfect fit for WHERE CURRENT OF! The next version of my winterization program below uses this
clause. I have also switched to a simple loop from FOR loop because I want to exit conditionally from the
loop:
DECLARE CURSOR fall_jobs_cur IS SELECT ... same as before ... ; job_rec
fall_jobs_cur%ROWTYPE;BEGIN OPEN fall_jobs_cur; LOOP FETCH fall_jobs_cur INTO
job_rec; IF fall_jobs_cur%NOTFOUND THEN EXIT; ELSIF
job_rec.do_it_yourself_flag = 'YOUCANDOIT' THEN UPDATE winterize SET responsible =
'STEVEN' WHERE CURRENT OF fall_jobs_cur; COMMIT; EXIT; END IF; END
LOOP; CLOSE fall_jobs_cur;END;
Answer Question
2 Users have rated as useful.

Login to rate this answer.


Shefali
Answered On : Aug 16th, 2006

"WHERE CURRENT OF" clause is used for updating or deleting rows selected by the cursor with FOR
UPDATE cluase.It explicitily locks the row for updating or deleting.
Answer Question
1 User has rated as useful.
Login to rate this answer.
g_sidhu
Answered On : Jan 31st, 2008
When referencing the current row from an explicit cursor, use the WHERE CURRENT OF
clause. This
allows you to apply updates and deletes to the row currently being addressed, without the need to
explicitly reference the ROWID. You must include the FOR UPDATE clause in the cursor query to
lock the rows first.

What will happen after commit statement ?


Cursor C1 is Select empno, ename from emp; Begin open C1;
loop Fetch C1 into eno.ename; Exit When C1 %notfound;--
--- commit; end loop; end; The cursor having query as SELECT ....
FOR UPDATE gets closed after COMMIT/ROLLBACK. The cursor having query as SELECT.... does not
get closed even after COMMIT/ROLLBACK.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 18 of 18 Answers


kishorebabukm
Answered On : Sep 20th, 2005

The cursor having query will get closed, because once the for update clause is fired it locks all the rows
which is been modified and once it encounters a commit/rollback it automatically comes out of that
session, and will be processing a fresh loop altogether.
Answer Question

Login to rate this answer.


Bhanu
Answered On : Oct 19th, 2005

DDL statements cannot be included in the pl/sql block. Hence giving commit is not allowed.
Answer Question
Login to rate this answer.
hanthur
Answered On : Feb 23rd, 2006
View all answers by hanthur

The changes will be permanently written to hard disk. No undo(rollback) is possible.


Answer Question

Login to rate this answer.


sunil
Answered On : Jun 12th, 2007

All the Database Locks are Released after commit....


Answer Question

Login to rate this answer.


Prajyot Shelar
Answered On : Jun 28th, 2007
When u will executed this statement into the server that's time commit mechanism will start to save a
record as permanently into the database.
COMMIT statement it's part of TCL Language.
Answer Question

Login to rate this answer.


askvenki
Answered On : Jul 18th, 2007
We cannot give commit inside a loop statement. Then we have to commit out side loop
Answer Question

Login to rate this answer.


vickyjp
Answered On : Jul 20th, 2007

If the data set is too big commiting with-in the cursor loop might lead to the `Snapshot too old Error`.
Answer Question

Login to rate this answer.


bambino chakma
Answered On : Aug 12th, 2007

after the commit statement, the cursor get closed ...as the result no further rows can be fetched even
though there are rows to be fetched.
Answer Question

Login to rate this answer.


ANY
Answered On : Nov 12th, 2007
CURSOR WONT CLOSE AFTER COMMIT TRY THIS CODE
DECLARE
CURSOR C IS
SELECT * FROM EMP
WHERE ROWNUM <4;
R C%ROWTYPE;
BEGIN
OPEN C;
LOOP
FETCH C INTO R;
DBMS_OUTPUT.PUT_LINE (R.EMPNO);
EXIT WHEN C%NOTFOUND;
UPDATE EMP
SET SAL = SAL-1;
COMMIT;
END LOOP;
CLOSE C;
END;
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
Commit will not close a cursor.
Commit makes database changes permanent and releases all the locks on that table.
Answer Question

Login to rate this answer.


anjanjali15
Answered On : Jul 22nd, 2008
View all answers by anjanjali15
COMMIT will not close a Cursor.
Also there is no DML operations to COMMIT.
It will give error eno.ename must be declared.
Answer Question

Login to rate this answer.


sharmasl
Answered On : Mar 16th, 2009
View all answers by sharmasl

In this PL/SQL Block the curosrfetch the records in both the variable till the time it get record. After
fetching all the records when the condition %not found is true it execute the commit and save all the
record which is fetched at the time of execution.
Answer Question

Login to rate this answer.


rachit_srivastava
Answered On : Aug 17th, 2009
View all answers by rachit_srivastava
Use of COMMIT statement end your current transaction and make permanent all changes performed in
the transaction.
A transaction is a sequence of SQL statements, usually COMMIT is used for DML statements.

Cheers!!
Answer Question

Login to rate this answer.


kinkyfellow
Answered On : Nov 18th, 2009
View all answers by kinkyfellow

Commit in this context will not do anything except the commiting the changes into database, done using
DML statements. However, if the cursor is created with FOR UPDATE clause, it will raise runtime
exception as commit, in that case, would also release all locks and thus close the cursor implicitly and
user will get ORA-1002 "fetch out of sequence " error as after the loop is executed one time, with the
commit statement, the cursor will be closed and fetch into statement will fail.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Dilip Lakshetty
Answered On : Mar 27th, 2011
View all answers by Dilip Lakshetty

Whenever User executes COMMIT statement?

The log writer makes redo log entries in redo log files after that message comes commit complete.

later DBWR writes changes into db files permanently from db buffer.


Answer Question

Login to rate this answer.


technofreek
Answered On : May 26th, 2011
View all questions by technofreek View all answers by technofreek
I want to modify the code mentioned in the thread as:
DECLARE
CURSOR C IS
SELECT * FROM EMP
WHERE ROWNUM <4;
R C%ROWTYPE;
BEGIN
OPEN C;
LOOP
FETCH C INTO R;
EXIT WHEN C%NOTFOUND;
DBMS_OUTPUT.PUT_LINE (R.EMPNO||'-'|| R.SAL);
UPDATE EMP
SET SAL = SAL-1
where empno = r.empno;
DBMS_OUTPUT.PUT_LINE (R.EMPNO||'-'|| R.SAL);
END LOOP;
COMMIT;
CLOSE C;
END;

Also by using commit the changes made by update statement will be seen in database permanently.
Answer Question

Login to rate this answer.


Art11
Answered On : Sep 27th, 2011
View all answers by Art11

The data will be written from redo log buffer into redo log files.
Answer Question

Login to rate this answer.


Vivek
Answered On : Jun 29th, 2012

After committing first oracle will commit the transaction into redo log file and then Data file. The data
block will remain into the memory until the logical reads are going on. Oracle use LRU algorithm to
maintain the data block into the memory. Also oracle maintain rollback segment before committing the
data to store original version of data.
What is a cursor for loop ?
Cursor for loop implicitly declares %ROWTYPE as loop index,opens a cursor, fetches rows of values
from active set into fields in the record and closeswhen all the records have been processed. eg. FOR
emp_rec IN C1 LOOP salary_total := salary_total +emp_rec sal; END LOOP;
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 7 of 7 Answers


kishorebabukm
Answered On : Sep 20th, 2005
The for loop in cursors are used to make less statements to write cursor.
if u are opening a cursor normally using the open cursor ,then
open cursor_name;
fetch cursor_name into variable loop
exit when cursor_name%notfound ;
end loop;
close cursor
in the above statement u have to explicitly open and close the cursor, and also write exit statement to
end the cursor loop
if we write the same using for loop then compare the statements.
for varible in cursor_name loop
statements
end loop;
the above for loop does not need a open and close explicitly since those are involved in the for loop itself.
and also never require the loop to explicitly end using any condition, since it ends the loop if there are no
more rows in the memory.
Answer Question
1 User has rated as useful.

Login to rate this answer.


rashid
Answered On : Sep 20th, 2006

cursor for loop is use for automatically open ,fetch,close


Answer Question

Login to rate this answer.


g_sidhu
Answered On : Jan 31st, 2008
A cursor FOR loop processes rows in an explicit cursor. It is a shortcut because the cursor is
opened, rows are fetched once for each iteration in the loop, the loop exits when the last row is
processed, and the cursor is closed automatically. The loop itself is terminated automatically at
the end of the iteration where the last row is fetched.
The record is implicitly declared.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007

Cursor for loop implicitly declares a loop index as %rowtype. It uses result of query to determine
dynamically no of times the loop is to be repeated. It performs open, fectch , close operations implicitly.
Answer Question
1 User has rated as useful.

Login to rate this answer.


sk.mca6
Answered On : Feb 17th, 2011
View all questions by sk.mca6 View all answers by sk.mca6
>By using cursor for loops we can improve performance of the application .
>it avoids explict cursor life cycle(open,fetch,close).
>in cursor for loop the index variable behaves like a record type variable..which is auto initialized.
>we can also use select stmt in place of cursorname
ex:
for i in (select * from emp) --inline _cursor style
loop -- i record type variable..emp%rowtype
......
end loop;
but here we cant controle the loop explicitely.
Answer Question

Login to rate this answer.


PRADEEP
Answered On : Oct 17th, 2012
If we use explicit cursor we need to open the cursor and fetching the data and close the cursor.

If we use cursor for loop cursor will open the cursor and fetching data and close the cursor automatically.
Answer Question

Login to rate this answer.


vasu
Answered On : Oct 20th, 2012

Cursor for loop is the one by using this we need not to perform open, close, fetch operations of a cursor..
Answer Question

Login to rate this answer.

What are the cursor attributes used in PL/SQL ?


%ISOPEN - to check whether cursor is open or not % ROWCOUNT - number of rows
fetched/updated/deleted. % FOUND - to check whether cursor has fetched any row. True if rows are
fetched. % NOT FOUND - to check whether cursor has fetched any row. True if no rows are
featched.These attributes are proceeded with SQL for Implicit Cursors and with Cursor name for Explicit
Cursors.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004
 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


pa
Answered On : Sep 15th, 2005
Answer Question

Login to rate this answer.


Paramjeet singh
Answered On : Sep 15th, 2005

Atrributes of Coursors are %Rowcount,%IsOpen,%NotFound,%Found


Answer Question

Login to rate this answer.


Jayakumar M
Answered On : Dec 6th, 2005

For Implicit Cursors:-


%Found - Returns TRUE,If the last DML Statement affect atleast 1 row otherwise FALSE.
%NotFound - Returns TRUE If last DML Statement doesn't affect atleast 1 row otherwise FALSE.
%Rowcount - Returns number of rows affected by the last DML statement.
%Isopen - Returns TRUE if the cursor is open otherwise FALSE. Its always returns FALSE incase of
implicit cursor. Because after executing the DML statement Oracle Server automatically close the cursor.
For Explicit Cursors:-
%Found - Returns TRUE if the Last fetch returns a Row otherwise FALSE.
%NotFound - Returns TRUE if the last fetch doesn't return any row otherwise FALSE.
%Rowcount - Returns number of rows returned so far from the active set.
%Isopen - Returns TRUE if the cursor is open otherwise FALSE.
Answer Question
3 Users have rated as useful.
Login to rate this answer.
krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
%FOUND :- Returns True if successful fecth has been executed.
Returns false if no rows returned
Returns NULL if cursor is opened but fetch is not executed.
Raises INVALID_CURSOR exception if cursor is not opened or closed.
%NOTFOUND :- Returns true if no rows were returned
Returns false if fectch has been executed successfully.
Returns NULL if cursor is open but fetch is not executed
Raises INVALID_CURSOR Exception If the cursor is not opened or cursor is closed
%ISOPEN :- Returns true if the cursor is open
Returns false if the cursor is closed

%ROWCOUNT :- Returns no of records fetched.


Raises INVALID_CURSOR exception if the cursor is not opened or closed.

Answer Question
1 User has rated as useful.

Login to rate this answer.


samareshp
Answered On : Jul 30th, 2009
View all answers by samareshp
There are five cursor attributes: %isopen, %found, %notfound, %rowcount and %bulk_rowcount.

%isopen
With %isopen it is possible to test whether a cursor was opened:
%found
%found returns true when the last fetch operation on the cursor fetched a row. If %found is used on a
cursor that is not open (%open returns false), an ORA-01001: invalid cursor is raised. %notfound returns
null is returned:
%notfound
%notfound returns true when the last fetch operation on the cursor did not fetch a row. If %notfound is
used on a cursor that is not open (%open returns false), an ORA-01001: invalid cursor is raised.
%notfound returns null is returned:
%rowcount
%rowcount returns the number of rows that have been fetched so far. So, it increases with each fetch:
%bulk_rowcount
%bulk_rowcount is similar to %rowcount, but is used in bulk collects.
Answer Question

Login to rate this answer.


Lakshmi84
Answered On : Jul 31st, 2009
View all answers by Lakshmi84
%ISOPEN - To check whether cursor is open or not.Returns true if cursoror cursor variable is open or not
otherwisefalse.

%FOUND - To check wheteher cursor is found or not. Returns true if fetch returns a row otherwise false.

%NOTFOUND - To check whether cursor is not found or not.This works logically opposite to %FOUND.
This is usec to exit a loop when fetch fails to return a row.

%ROWCOUNT - To check the number of rows fetched by the cursor.

What are the PL/SQL Statements used in cursor processing ?


DECLARE CURSOR cursor name, OPEN cursor name, FETCH cursor name INTO or Record types,
CLOSE cursor name.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


mahendra
Answered On : Sep 29th, 2005

Also Fetch BULK Collect into


Answer Question

Login to rate this answer.


geetha24
Answered On : Feb 13th, 2007
View all questions by geetha24 View all answers by geetha24

FOR record_index IN [cursor_name | (SELECT statement)]LOOP executable_statement(s)END LOOP;


Answer Question
1 User has rated as useful.
Login to rate this answer.
fancyoracle
Answered On : Aug 14th, 2007
There are two ways of processing a cursor output. These mainly depend on the type of cursor used.
Cursors can be
1) Static : Declared in declarations section with a definate command
2) Dynamic : Usually passed a string, which is formulated in program based on various conditions.

If the cursor is dynamic, it needs to be processed thro open cursor, fetch into, loop and end loop. This is
because such cursors need to be opened into a ref cursor with "open cursor" command.
If the cursor is static, it can be processed thro a cursored for loop or by the method mentioned above.
Cursored for loop takes the pain to open and close the cursor automatically.

Explain the two type of Cursors ?


There are two types of cursors, Implicit Cursor and Explicit Cursor.PL/SQL uses Implicit Cursors for
queries.User defined cursors are called Explicit Cursors. They can be declared and used.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 3 of 3 Answers


DHEERAJ JHA
Answered On : Sep 25th, 2005

implicit cursor: implicit cursor is a type of cursor which is automatically maintained by the Oracle server
itself.implicit cursor returns only one row.
Explicit Cursor: Explicit Cursor is defined by the Proframmer,and it has for phases:declare,open,fetch and
close.explicit Cursor returns more than one row.
Answer Question

Login to rate this answer.


Lavanya Chowdary
Answered On : May 6th, 2007
View all answers by Lavanya Chowdary
There r two types of cursors in the pl/sql
1.Implici 2.explicit
For the select stmt which is retrieving single record or all the dml operations in the pl/sql program
system automatically allocates the temporary memory or private area to fetch the records that is called
as implicit cursor automatically created by the system.
if u r trying to fetch more than one record from the pl/sql programs we need to allocate some private
area,we have to activate the records available in the cursor,we need to fetch one by one record and we
have to refresh the memory for the records after fetching all the records that process will be handled by
explicit cursors defined by the user
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
Cursors are of two types
1. Implicit Cursors: - Whenever we execute sql statements oracle server assigns a work area called
private sql area to store precessed infomation. The most recently used work are can be accessed using
SQL%. In implicit cursors open, fetch , close operations are automatically performed by the server
implicitly.

2.Explicit cursors:- In explicit cursor you can explicitly assign a name to process information stored in
private sql areas. This process involves four steps

I. Declaring a cursor :- Involves assign a name to cursor and associating a query with it..
II. Open the cursor :- Executes the query and identify the result set.
III. Fetch the cursor :- gets the result set and Loops through to process them
IV. Close the cursor :- Releases the cursor

What is a cursor ? Why Cursor is required ?


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.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


chandrakant
Answered On : Oct 16th, 2005

cursor retrive data from a table. it can be done in two level


1 %type it retrive data from a particular row
2 %rowtype it retrive data from a full table
Answer Question

Login to rate this answer.


Santapan
Answered On : Oct 19th, 2005

Cursor is a handler or pointer to Oracle Context Area.Context area is a memory space used for processing
of sql statements.
Answer Question

Login to rate this answer.


pravinkumar
Answered On : Dec 27th, 2005
View all answers by pravinkumar
Cursor is a named private SQL area also called as context area from where information can be accessed.
Cursors are required to process rows individually for queries returning multiple rows. there are three
types of cursors
1. Static Cursor
* Implicit Cursor
* Explicit Cursor
2. Dynamic Cursor
3. Reference Cursor
Answer Question

Login to rate this answer.


brcprasanna
Answered On : Apr 12th, 2006
View all answers by brcprasanna

cursor is a pointer or a handle for the pga(program global area)


using cursors,we can access more than one row which we cant do using select stt,
the second one is,we r using only a small part of memory so,the access time is lesser and hence the
performance is more
Answer Question

Login to rate this answer.


thiyagarajan
Answered On : May 24th, 2007

CURSOR
Whenever a sql statement is issued, at that time oracle server will allocate some memory area to execute
and parse that sql statement. That data area is called as cursor.

Two types : IMPLICIT, EXPLICIT

IMPLICIT
-----------
(1) Called as SQL.
(2) Never user CURSOR keyword explicitly
(3) Memory allocation and program controll will done automatically
(4) Returns or updates or deletes only one record.
(5) Attributes : SQL%FOUND, SQL%NOTFOUND

EXPLICIT
-----------
(1) called as cursors
(2) Uses CURSOR keyword explicitly
(3) Memory allocation and program control thru the cursor written.
(4) Returns or updates or deletesmultiple records.
(5) Attributes : SQL%FOUND, SQL%NOTFOUND, %ISOPEN, %ROWCOUNT
Answer Question
3 Users have rated as useful.

Login to rate this answer.


BAMBINO
Answered On : Jul 15th, 2007
In order to process sql statement oracle allocate an area of memory known as context area. Context area
hold all the necessary information to process the sql statment including the no. of rows processed by the
sql statment.

Cursor is a handler or a pointer to the context area. throught cursor pl/sql programcan control the
context area and what happens to it as thestatment process.

Most common operation using cursor is to fetch data rows in the active set.
Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 16th, 2008
A cursor is a private SQL work area. Whenever you issue a SQL statement, the Oracle server
opens an area of memory in which the command is parsed and executed. This area is called 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.
Answer Question

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007
Oracle uses work areas called private SQL area to Execute Sql statements and store information. A
cursor is a mechanism by which we can assign name to that private sql area , there by access
information stored in it.

In Pl/Sql block if a query returns more than one row it raises an exception TOO_MANY_ROWS. Using
cursors mechanism we can process multiple rows returned by the query in pl/sql blocks.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


rahulg5211
Answered On : Oct 4th, 2009
View all answers by rahulg5211
Cursor is an small memory allocation or workstation where operation or processing is done on the data.

Types of attribute of cursor are-:


1)ROWCOUNT
2)ISOPEN
3)FOUND
4)NOTFOUND

What is PL/SQL table ?


Objects of type TABLE are called "PL/SQL tables", which are modeled as (but not the same as)
database tables, PL/SQL tables use a primary PL/SQL tables can have one column and a primary
key. Cursors

Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last

Return back to PL/SQL


Answer Question

Editorial / Best Answer


Answered by: rkanth18
View all answers by rkanth18

Member Since Sep-2005 | Answered On : Nov 26th, 2005

A PL/SQL table is a one-dimensional, unbounded, sparse collection of homogenous elements, indexed


by integers
One-dimensional

A PL/SQL table can have only one column. It is, in this way, similar to a one-dimensional array.
Unbounded or Unconstrained

There is no predefined limit to the number of rows in a PL/SQL table. The PL/SQL table grows
dynamically as you add more rows to the table. The PL/SQL table is, in this way, very different
from an array.
Related to this definition, no rows for PL/SQL tables are allocated for this structure when it is
defined.
Sparse

In a PL/SQL table, a row exists in the table only when a value is assigned to that row. Rows do
not have to be defined sequentially. Instead you can assign a value to any row in the table. So
row 15 could have a value of `Fox' and row 15446 a value of `Red', with no other rows defined in
between.
Homogeneous elements

Because a PL/SQL table can have only a single column, all rows in a PL/SQL table contain
values of the same datatype. It is, therefore, homogeneous.
With PL/SQL Release 2.3, you can have PL/SQL tables of records. The resulting table is still,
however, homogeneous. Each row simply contains the same set of columns.
Indexed by integers

PL/SQL tables currently support a single indexing mode: by BINARY_INTEGER. This number
acts as the "primary key" of the PL/SQL table. The range of a BINARY_INTEGER is from -231-1
to 231-1, so you have an awful lot of rows with which to work

Showing Answers 1 - 6 of 6 Answers

kishorebabukm

Answered On : Sep 20th, 2005

Pl/SQL tables are the row, column structure as of the table but cannot perform any select query on the
pl/sql tables because the data isfrom fetched only by the indexes like
--- store empno, ename from emp table thru cursor to pl/sql tables.
declare
type ty_plsql is record ( empno number, ename varchar2(50));
ty_plsql1 ty_plsql;
cursor c is select empno,ename from emp;
begin
for i in c loop
ty_plsql(i).empno := i.empno;
ty_plsql(i).ename := i.ename;
end loop;
end;
Answer Question

Login to rate this answer.

rkanth18

Answered On : Nov 26th, 2005

View all answers by rkanth18

A PL/SQL table is a one-dimensional, unbounded, sparse collection of homogenous elements, indexed by


integers
One-dimensional

A PL/SQL table can have only one column. It is, in this way, similar to a one-dimensional array.
Unbounded or Unconstrained

There is no predefined limit to the number of rows in a PL/SQL table. The PL/SQL table grows
dynamically as you add more rows to the table. The PL/SQL table is, in this way, very different
from an array.
Related to this definition, no rows for PL/SQL tables are allocated for this structure when it is
defined.
Sparse

In a PL/SQL table, a row exists in the table only when a value is assigned to that row. Rows do
not have to be defined sequentially. Instead you can assign a value to any row in the table. So
row 15 could have a value of `Fox' and row 15446 a value of `Red', with no other rows defined
in between.
Homogeneous elements
Because a PL/SQL table can have only a single column, all rows in a PL/SQL table contain values
of the same datatype. It is, therefore, homogeneous.
With PL/SQL Release 2.3, you can have PL/SQL tables of records. The resulting table is still,
however, homogeneous. Each row simply contains the same set of columns.
Indexed by integers

PL/SQL tables currently support a single indexing mode: by BINARY_INTEGER. This number acts
as the "primary key" of the PL/SQL table. The range of a BINARY_INTEGER is from -231-1 to 231-
1, so you have an awful lot of rows with which to work

Answer Question

5 Users have rated as useful.

Login to rate this answer.

rkanth18

Answered On : Nov 26th, 2005

View all answers by rkanth18

Keep the following restrictions in mind when you work with PL/SQL tables:
 There is no concept of transaction integrity with PL/SQL tables. You cannot commit information to a
PL/SQL table or roll back changes from the table.
 You cannot SELECT from PL/SQL tables. There is no way to perform set-at-a-time processing to retrieve
data from a PL/SQL table. This is a programmatic construct in a programmatic language. Instead you can
use PL/SQL loops to move through the contents of a PL/SQL table, one row at a time.
 You cannot issue DML statements (INSERTs, UPDATEs, and DELETEs) against PL/SQL tables (though
PL/SQL Release 2.3 does offer a DELETE operator).
Answer Question

Login to rate this answer.

iasritesh

Answered On : Jan 14th, 2007

View all questions by iasritesh View all answers by iasritesh

An associative array (or INDEX-BY table) that can be indexed by NUMBER or VARCHAR2. Elements are
retrieved using number or string subscript values. Unlike with data tables, PL/SQL tables are stored in
memory. PL/SQL Tables are sparse and elements are unordered.
Answer Question

Login to rate this answer.

babu.sridharan

Answered On : Jul 14th, 2008

View all answers by babu.sridharan

Example for PL/SQL table:


==================

In the below block "typlsql" and "ty_plsql2" are PL/SQL tables

declare
type ty_plsql is record ( empno number, ename varchar2(50));
TYPE ty_plsql2 is table of ty_plsql;
ty_plsql1 ty_plsql2;
j number;
cursor c is select empno,ename from emp;

begin
ty_plsql1:=ty_plsql2(NULL,NULL);
for i in c loop
j:=1;
ty_plsql1(j).empno := i.empno;
ty_plsql1(j).ename := i.ename;
dbms_output.put_line('Print the value : '||' No '|| ty_plsql1(j).empno ||' Name '|| ty_plsql1(j).ename);
j:=j+1;
end loop;

end;

What is difference between % ROWTYPE and TYPE RECORD ?


% ROWTYPE is to be used whenever query returns a entire row of a table or view. TYPE rec RECORD
is to be used whenever query returns columns of differenttable or views and variables. E.g. TYPE
r_emp is RECORD (eno emp.empno% type,ename emp ename %type); e_rec emp% ROWTYPE
cursor c1 is select empno,deptno from emp; e_rec c1 %ROWTYPE.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous
 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 6 of 6 Answers


kishorebabukm
Answered On : Sep 20th, 2005

basically the %rowtype is used in case of fetching the values of the cursor irrespective of how many
columns in it and also the data types associated with the tables column.for eg.
declare
cursor c_example is select * from emp;
v_emp emp%rowtype;
begin
for v_emp in c_example loop
statements
......
end loop;
end;
the type record is a object oriented concept related to pl/sql tables, tables with datastructure format etc.
create type ty_name is record ( a number,
b varchar2(10));
this type stores data in a record fashion with 2 columns.
Answer Question
1 User has rated as useful.

Login to rate this answer.


sunilbidgar
Answered On : Apr 18th, 2008
View all answers by sunilbidgar

%rowtype is an attribute to inherit datatypes of attributes of a table into a RECORD variable. Type record
is a keyword to create record type using either explicitly specifying atrributes or by implecitly inheriting
attributes from a table or a existing cursor.
Answer Question
Login to rate this answer.
nagarajkv
Answered On : May 5th, 2008
View all answers by nagarajkv
TYPE RECORD is a composite datatype. It consits of multiple pieces of information, called fields. TYPE
RECORD fields can be defined by the user. Eg:

DECLARE
TYPE extra_book_info_t
IS RECORD (
title books.title%TYPE,
is_bestseller BOOLEAN
);

first_book extra_book_info_t;

here, 'title' is the data type defined in books table. We can declare a RECORD based on this type.

Where as %ROWTYPE is a direct link to the data type of the table.columns, EG:
DECLARE
bestseller books%ROWTYPE;

The advantage of TYPE RECORDS is you can pass these to Functions or Procedures which can reduce the
parameter size or a repitative work.

Hope this give a better explanation.


Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 15th, 2008
View all answers by krishnaindia2007
%ROWTYPE is used when you need to work with complete record.
TYPE RECORD is used to create your own data type with specificed number of values to hold.
Suppose If a table has 20 columns and you need to work with only seven columns . If I use %ROWTYPE,
I get all 20 values unnecessarily. At the same time, my program will be bit clumsy if I use seven %TYPE
declarations. A better way to solve this solution is by defining my own data type, which can hold seven
values.
Answer Question
2 Users have rated as useful.

Login to rate this answer.


iqbal
Answered On : Nov 1st, 2011

there is no need to declare v_emp as we are using for loop....


Answer Question
Login to rate this answer.
priya dharan raj
Answered On : Nov 15th, 2011
View all answers by priya dharan raj

this %rowtype is used declare record type

What are % TYPE and % ROWTYPE ? What are the advantages of using these
over datatypes?
% TYPE provides the data type of a variable or a database column to that variable. % ROWTYPE
provides the record type that represents a entire row of a table or view or columns selected in the
cursor. The advantages are : I. Need not know about variable's data typeii. If the database definition
of a column in a table changes, the data type of a variable changes accordingly.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First

 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 13 of 13 Answers


StoneColdSteveAustin
Answered On : Oct 10th, 2005
View all answers by StoneColdSteveAustin

eg:
ename employees.emp_id%type;
here ename is the variable to be declared.
employees is the table name
emp_id is the column for that table.
%type indicates to assign the datatype of emp_id column in employees table for the ename variable.
Answer Question

Login to rate this answer.


Sebastian Thomas
Answered On : Jan 18th, 2006
Advantage is, if one change the type or size of the column in the table, it will be reflected in our program
unit without making any change.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Lavanya Chowdary
Answered On : May 6th, 2007
View all answers by Lavanya Chowdary

%type is used to refer the column's datatype where as %rowtype is used to refer the whole record in a
table.
Answer Question
1 User has rated as useful.

Login to rate this answer.


satish.m.v
Answered On : May 21st, 2007
View all answers by satish.m.v
%Type is defined as a difination for a perticular columm, It is a scalar type.

EX:
V_EMPNOEMP.EMPNO%Type;
Where as

%ROW TYPE is a defination for a table or it is a composite type.

Ex:
V_EMP EMP.%ROWTYPE.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Yestha Bapna
Answered On : Aug 14th, 2007
%TYPE can be used with the column name preceded with table name to decide the datatype and length
of the variable at runtime. In this case there is no dependency on changes made to the data structure.

%ROWTYPE can be used to declare the variable having the same no. of variables inside it (ROWTYPE) as
no. of columns there in the table. In this case columns selected with SELECT statement must match with
variables inside the rowtype variable. If not then induvidually refer these variables inside the ROWTYPE
variables
Answer Question
1 User has rated as useful.

Login to rate this answer.


sunilbidgar
Answered On : Apr 18th, 2008
View all answers by sunilbidgar
%Type - With %Type attribute we can inherit the datatype of another variable or an attribute of table
into currently declared variable.
eg.

declare
var1 production.invoice.itemno%type;

%Rowtype - With %rowtype attribute we can inherit the datatypes entire variable into a record varible
from another record variable or from all attributes of table into currently declared record variable.
eg.

declare
record1 production.invoice%rowtype;

here u can refer any attrbute as record1.itemno

Advantage is u need not to change the pl/sql code even if table attribute changes.
u need not to remember detail datatypes of table while coding pl/sql
Answer Question
1 User has rated as useful.

Login to rate this answer.


krishnaindia2007
Answered On : May 6th, 2008
View all answers by krishnaindia2007

%TYPE is used to declare a variable with the same type as that of a database table column.%ROWTYPE
is used to declare a record as same type found in database table.These two provides data independence
and allows you to adopt database changes due to new business requirements.You need not know
datatype and size in advance.
Answer Question
1 User has rated as useful.

Login to rate this answer.


ajayraj
Answered On : Dec 15th, 2010
View all answers by ajayraj
% TYPE is used to define a varibale as same data type of the column of associated table.
%ROWTYPE provides a record type that represents a row in database table.

The benefit of %TYPE and %ROWTYPE is when u are fetching the data from a table in procedure and
after that data type of column or size is changed then no need to modify the procedure.
Answer Question

Login to rate this answer.


nirmal1in
Answered On : Dec 25th, 2010
View all questions by nirmal1in View all answers by nirmal1in
The %TYPE is used to define the varible of particular type for column exist on the table.
The %ROWTYPE is used to define variable of row type of table.

- It is good practice to use %TYPE and %ROWTYPE instead of defining varible of simple type. In case of
any change in the data type of columns and no need to make any changes to code.
- %ROWTYPE can be used to fetch complete row instead ofdefining varible for each field to hold the data
while processing.

Answer Question

Login to rate this answer.


Jitendra
Answered On : Feb 28th, 2012
ename variable will create with the data type of emp_id column of the employees table

for eg. if emp_id is of numeric type than ename should be numeric.


Answer Question

Login to rate this answer.


Kishore.Dondla
Answered On : Jun 29th, 2012

We Can USE These Data Types in Stored Procedures ,function and Packages as IN Parameter.
Answer Question

Login to rate this answer.


Yaseen
Answered On : Aug 9th, 2012

if using %type and %rowtype , no need to know the the data type of the table column . and once the
development is finished , the type of column is changed it will not effect the coding.
Answer Question

Login to rate this answer.


PRADEEP
Answered On : Oct 16th, 2012
%rowtype is associated entire table(if we want to declare all columns then we need to declare
%rowtype).

%type is associated with one column .(if we want to declare entire column then we need to declare
%type).

What is PL/SQL ?
PL/SQL is a procedural language that has both interactive SQL and procedural programming
language constructs such as iteration, conditional branching.
Asked by: Interview Candidate | Asked on: Sep 9th, 2004

 First
 Previous

 Next

 Last
Return back to PL/SQL
Answer Question

Showing Answers 1 - 9 of 9 Answers


tm1966_muthu
Answered On : Feb 17th, 2006
View all answers by tm1966_muthu
PL/SQL is Oracle's Procedural Language extension to SQL . PL/SQL's language syntax, structure and
datatypes are similar to that of ADA. The language includes object oriented programming techniques
such as encapsulation, function overloading, information hiding (all but inheritance), and so, brings state-
of-the-art programming to the Oracle database server and a variety of Oracle tools.
Answer Question

Login to rate this answer.


Nagendra
Answered On : Mar 3rd, 2006

Hi Sir,
1.What is PL/SQL ?
Answer :
PL/SQL is Procedural Language extension to SQL. PL/SQL's language syntax, structure and
datatypes are similar to that of ADA. The language includes object oriented programming techniques
such as encapsulation, function overloading, information hiding (all but inheritance), and so, brings state-
of-the-art programming to the Oracle database server and a variety of Oracle tools.
Answer Question

Login to rate this answer.


sumanamara_ora
Answered On : Apr 5th, 2007
View all answers by sumanamara_ora
hii
pl/sql is procedural language extenction to structure query language.
Answer Question

Login to rate this answer.


rajesh
Answered On : Jul 23rd, 2007
PL/SQL is a procedural language that Oracle developed as an extension to standard SQL to provide a way
to execute procedural logic on the database.

New Term - If you have worked with relational databases in the past, you are no doubt familiar with
SQL, which stands for Structured Query Language. SQL itself is a powerful declarative language. It
isdeclarative in the sense that you describe the results that you want but not how they are obtained. This
is good because you can insulate an application from the specifics of how the data is physically stored. A
competent SQL programmer can also push a great deal of processing work back to the server level
through the creative use of SQL.
Answer Question
1 User has rated as useful.

Login to rate this answer.


Yestha Bapna
Answered On : Aug 14th, 2007

PL SQL is a block structured programming language. It combines data manipulation & data processing
power. It supports all SQL data types. Also has its own data types i,e BOOLEAN,BINARY INTEGER
Answer Question

Login to rate this answer.


narender sharma
Answered On : Oct 30th, 2007

Pl/Sql is a procedural extension to sql with design feature of programming language.


Answer Question

Login to rate this answer.


narender1908
Answered On : Oct 30th, 2007
View all answers by narender1908

PL/SQL is procedural extension to SQL with design feature of programming language.


Answer Question

Login to rate this answer.


g_sidhu
Answered On : Feb 16th, 2008
PL/SQL is the procedural extension to SQL with design features of programming languages.
Data manipulation and query statements of SQL are included within procedural units of code.
PL/SQL offers modern software engineering features such as data encapsulation, exception
handling, information hiding, object orientation.
Answer Question

Login to rate this answer.


surya72446
Answered On : Sep 30th, 2009
View all answers by surya72446
PL/SQL stands for procedural languages extensions to SQL and it's theme is to hold a bunch of SQL
statements as a single function and return a single output.
PL/SQL is advantageous compared to other programming languages as it is a Oracle proprietary and does
not require any external interfaces for the database connectivity.

Das könnte Ihnen auch gefallen