1.what Is Cursor ? Answer
1.what Is Cursor ? Answer
Answer :
Cursor is a buffer area which is used to process multiple records and also record by record
tabs.
1.Implicit cursor
2.Explicit cursor
Implicit cursor : Implicit cursor is a buffer area which has been defined and controlled by
oracle internally. Implicit cursor will process single record at a time.
example :
declare
v_Ename varchar2(100);
begin
dbms_output.put_line(V_Ename );
end;
The above cursor is implicit cursor where all the operations are defined by oracle engine
internally like declaring the cursor,fetching values from the cursor and close cursor.
Explicit Cursor : Explicit cursor is a cursor which is defined by user to process set of
records.For multiple records user needs to use explicit cursor.Explicit cursor operations are
done by the user.
1.Declare cursor
2.Open cursor
4.Close cursor.
1.%Found
2.%Not Found
3.%Isopen
4.%Rowcount
example :
Answer:
Cursor declares %ROWTYPE as loop index implicitly. It then opens a cursor, gets rows of
values from the active set in fields of the record and shuts when all records are
processed.Means while using the for loop user dont need to Open the cursor and fetch the
values from cursor or close cursor explicitly.
Total_Salary=Total_Salary + Appraisals;
END LOOP;
Examples of Trigger :
1)Audit data modifications.
7.What is Raise_Application_Error?
Answer :
When user wants to insert Error message then user needs to use the
Raise_Application_Error procedure. Raise_Application_Error is the system defined
procedure of package named DBMS_STANDARD.
Syntax :
Raise_Application_Error(Error_Code,Error_Message);
Example :
Raise_Application_Error (-20343, ‘The balance is too low.’);
8.What is commit?RollBack?Savepoint?
Answer :
Commit :
When user commits the data after transaction that changes are permanent changes.
1.Other users can see the data changes made by the transaction.
Rollback :
When transaction become wrong user can rollback the data.
Savepoint :
It undoes all the work done by the user in a transaction. With SAVEPOINT, only part of
transaction can be undone.
2.Especially while creating the table if we specify the primary key then unique index is
automatically created on that column.
3.But for Unique key constaint columns you separately need to do indexing.Kindly make
sure that Unique key indexes created on the columns which has unique values only.
4.The unique indexes are also called as clustered indexes when primary key is defined on
the column.
Example:
Create Unique index Index_name on Table_name(Unique column name);
Example:
CREATE UNIQUE INDEX UI1_EMP on EMP(EMP_ID);
2.User should avoid the indexing on each and every row and do the indexing only on
distinct records of the table column.You should able to check drastic change in query cost
after changing the normal index to Bit map index.
3.The bit map indexes are very much useful in dataware housing where there are low level
of concurrent transactions.Bit map index stores row_id as associated key value with bitmap
and did the indexing only distinct values.
4.Means If in 1 million records only 20 distinct values are there so Bitmap index only stores
20 values as bitmap and fetches the records from that 20 values only.
Syntax:
Create bitmap index Index_name on Table_name(Columns which have distinct values);
Example:
CREATE BITMAP index BM_DEPT_NAME on DEPT(Department_name);
12. What are different cursor attributes?
Answer :
%ISOPEN :
Checks if the cursor is open or not
%ROWCOUNT :
The number of rows that are updated, deleted or fetched.
%FOUND :
Checks if the cursor has fetched any row. It is true if rows are fetched
%NOT FOUND :
Checks if the cursor has fetched any row. It is True if rows are not fetched.
Anonymous blocks are programs or unnamed block which is used to check some
functionality and which are not stored in database.
Subprograms :
Subprograms are stored blocks which are stored in to database. Subprograms are compiled
at runtime.
1.Predefined Exceptions :
User defined exceptions are exceptions which are defined by the user in the program.
ZERO_DIVIDE
NO_DATA_FOUND
TOO_MANY_ROWS
CURSOR_ALREADY_OPEN
INVALID_NUMBER
INVALID_CURSOR
PROGRAM_ERROR
TIMEOUT _ON_RESOURCE
STORAGE_ERROR
LOGON_DENIED
VALUE_ERROR
var:=NVL(var2,’Hi’);
IS NULL and IS NOT NULL can be used to check specifically to see whether the value of a
variable is NULL or not.
“Cost based optimizer considers the statistical information of the table for query execution”
20.What is difference between Decode and Case?
Answer :
DECODE and CASE statements are very similar, but CASE is extended version of
DECODE. DECODE does not allow Decision making statements in its place.
CASE is directly used in PL SQL, but DECODE is used in PL SQL through SQL only.
These are some important PL SQL interview questions,hope you like this article.