SQL,
PL/SQL FAQ
About
Triggers:
1. What is triggers? What are the different types of triggers?
A Database Trigger is a stored procedure that is fired
when a DML operation is performed on the table.In total there are 13 types of
Triggers
Sytax for creating a trigger:
CREATE
OR REPLACE TRIGGER before / after
[INSERT
/ UPDATE / DELTE ] ON
{For
each Statement / Row}
{When
}
Types of Triggers:
Before
After
For each Row
For each Statement (default)
Instead of
Trigger: This trigger is defined on a
view rather than a table.
System
Triggers: A new feature of Oracle8i,
wherein the trigger is fired when the database startup / shutdown process.
Schema
Triggers: These triggers are fired
whenever a DDL statement is executed.
(Creation or Deletion of any DB Objects)
Order of Trigger Firing:
·
Before
Statement trigger (If present)
·
Each row
affected by the statement
(a) Execute row level trigger (If
present)
(b) Execute the statement itself
(c) Execute the after row level trigger
(If Present)
·
After
statement trigger (If Present)
2. What are the different types of joins
available in Oracle?
Equi Join: When primary and foreign key
relationship exists between the tables that are going to be joined.
Self Join : If comparision comes in a single table
Cartesian
Join: When tables are joined without
giving any join condition.
Inner Join: The resultant set includes all the
rows that satisfy the join condition.
Outer Join: The resultant set includes the rows
which doesn’t satisfy the join condition. The outer join operator Plus sign (+) will be
included in the join condiiton.
Example: SELECT a. column1, a. column2,
b.column3….. from a, b where
a.column1(+)=b.Column1
Here the rows from table a which
doesn’t satisfy the join condition will also be fetched.
3. What are Indexes? What are the different types of Index? If a
table consists of more than one Index how to enforce the statement to use the
second Index?
An Index is a DB object, which is
used to improve the performance of the
data retrieval.
CREATE INDEX ON
.(
Types of Indexes:
Bitmap Index (Used for Low
cardinality column)
Btree Index (Used for high cardinality column)
4. What is Mutating Table?
Table under transition is called
Mutating Table.
5. What is views? What is Inline View & Forced View??
Views are window to a table. It contains no data, it is based on the
actual table called the base table or a view. Views won’t occupy any space it
is just a logical
Inline View means writing select statement in the Query itself instead of selecting
a Column Name.
Force View is nothing but creation of view without table. Once after you create a
table this view will be enables:
Create Forced view as select * from
- What is a Cursor?
When it is used? What are
different types of Cursors?
Cursor is a
private SQL area created in SGA to do multi row operation in a PL/SQL program
Explicit Cursor,
Implicit Cursor.
Implicit Cursor:
System (Oracle) automatically declares and uses for all DML SQL Statements.
Explicit Cursor:
Cursor declared explicitly in the PL/SQL program to do multi row operation
Syntax:
Declare
Cursor C1 is
SELECT SAL, EMPNO FROM EMP
X number;
Y Varchar2(30);
Begin
Open
C1;
Loop
Fetch C1 INTO x, y;
Exit when c1%NOTFOUND
End Loop;
End;
- What is for
Cursor? When it is used? Is it necessary to write an explicit
exit in case for Cursor?
A Cursor for loop can be used simplify the explicit cursor, no need to
explicitly
Open, fetch and close. No explicity
EXIT statement is required.
- What are Cursor attributes? What is use of FOR UPDATE
in Cursor?
%Found
%NotFound
%RowCount
%IsOpen
FOR UPDATE statement in Cursor is Used to Update a
Column in the Selected table by using the CURRENT OF .
- What is a Package?
What is the advantage of using Packages?
A Package is a
PL/SQL Construct that allow related object to be stored together. Package contains 2 parts, Package
Specification and Package Body, each stored separately in the Data Dictionary.
Once the Package
is called all the related Procedure and functions of the package gets compiled
and stored in the memory as P-code.
How do u call a
Package.
- Name some important Packages provided by Oracle?
DBMS_SQL,
DBMS_JOBS, DBMS_DDL, DBMS_LOCK
- What is Overloading?
Overloading is
oops concept (Object Oriented Programming)
By Using the
same name we can write any number of Procedure or functions in a package but
either number of parameters in the procedure/function must be vary or parameter
data type must vary.
- What is a Function?
Difference between Procedure and Function?
Function is a
object that takes one or more arguments and returns only value. But in case of
procedures we can return more than one parameters.
Function always
returns a value, whereas procedure may or may not return a value.
- What is the Package used in Oracle to do the File
Operation?
UTL_FILE
- What is Dynamic SQL?
How Dynamic SQL can be built?
The SQL statement
which are built at run time are called the Dynamic SQL. Dynamic SQL can be built by using DBMS_SQL
package.
Procedure of
Dynamic SQL
OPEN_CURSOR,
PARSE, BIND_VARIABLE, DEFINE_COLUMN, EXECUTE, FETCH_ROWS, CLOSE_CURSOR.
Oracle8i onwards
there is another built in to construct Dynamic SQL called EXECUTE_IMMEDIATE.
- What is an exception?
What are the different types of Exception? How do u
declare a user defined exception?
The error condition in PL/SQL is
termed as an exception. Two types of
Exception:
Pre-Defined Exception:
Example No_Data_Found, Storage_Error,
Zero_Error, Invlid_Cursor, Too_Many_Rows
User-Defined Exception:
Anything
Syntax:
Declare
Xyz Exception;
Begin
SELECT ENAME FROM EMP
RAISE XYZ;
End;
- what could happen if we use WHEN OTHERS before any
predefined exceptions
According to the
Oracle standards “ When Others “ exception must be the last exception. All the
Predefined exceptions must be used before the “When others” exception.
If “ When others” exception used
before any pre-defined exceptions then
procedure/function shows the compilations errors
- List out some features in 8i
Bitmap Indexes,
Drop a Column, Bulk Insert and Bulk Update
Materialized
views, Dynamic Sql(Execute Immediate etc)
- List some 9iFeatures
External tables
( We query the data directly from a file like select * from “c:/abcd.csv” )
Multi Table
Insert with single command, presumable process etc.
- What are SQLCODE and SQLERRM and why are they
important for PL/SQL
developers?
SQLCODE returns
the value of the error number for the last error encountered. The SQLERRM
returns the actual error message for the last error encountered. They can be
used in exception handling to report, or, store in an error log table, the
error that occurred in the code. These are especially useful for the WHEN
OTHERS exception
- What is the use of Pragma_Init exception
By using this we
can define our messages by handling the oracle messages
- What are temporary tables? How many types?
Temporary tables
are used to store the data temporarily. Mainly there are 2 types
They are
transaction and Session types
Syntax: Create
global temporary table as select * from emp;
This temporarly
table is used to store the data temparorly once you exit from session then that
table will get erased
- Some of the System Tables
a.
User_source table will stores the information of the
user defined definitions
b.
All_Source and dba_source tables will stores the system
defined schema objects definitions as well as user defined.
c.
All_Tab_Columns and ben_all_tab_columns are used to
list out the all the columns name and
respected table names also.
- Write a query to list out the employees with their
respective manager levels?
select lpad('*',
level * 2), empno, ename, mgr from emp
connect by prior
empno = mgr start with empno = 7839
It results the
hierarchy of the employees
- Write a Query to fetch the details of an employee
having max sal without using any group functions.
select empno,
ename, sal
from emp
where rownum
< 2
order by sal
- Generic Query to find the second or third third Max
Sal’s
select
* from Emp a where &s = (SELECT count(*) FROM EMP b WHERE
b.sal >= a.sal)
Note : For Answers Check the Next Page
* What is PL/SQL and what is it used for?
* Should one use PL/SQL or Java to code
procedures and triggers?
* How can one see if somebody modified any
code?
* How can one search PL/SQL code for a
key?
* How can one keep a history of PL/SQL
code changes?
* How can I protect my PL/SQL source code?
* Can one print to the screen from PL/SQL?
* Can one read/write files from PL/SQL?
* Can one call DDL statements from PL/SQL?
* Can one use dynamic SQL statements from
PL/SQL?
* What is the difference between %TYPE and
%ROWTYPE?
* How does one get the value of a sequence
into a PL/SQL variable?
* Can one execute an operating system
command from PL/SQL?
* How does one loop through tables in
PL/SQL?
* How often should one COMMIT in a PL/SQL
loop? / What is the best commit strategy?
* I can SELECT from SQL*Plus but not from
PL/SQL. What is wrong?
* What is a mutating and constraining
table?
* Can one pass an object/table as an
argument to a remote procedure?
* Is it better to put code in triggers or
procedures? What is the difference?
* Is there a PL/SQL Engine in SQL*Plus?
* Is there a limit on the size of a PL/SQL
block?
* Where can one find more info about
PL/SQL?
What is PL/SQL and what is it used for?
PL/SQL is Oracle's Procedural Language
extension to SQL. PL/SQL's language syntax, structure and data types are
similar to that of ADA. The PL/SQL language includes object oriented
programming techniques such as encapsulation, function overloading, information
hiding (all but inheritance). PL/SQL is commonly used to write data-centric
programs to manipulate data in an Oracle database.
Should one use PL/SQL or Java to code
procedures and triggers?
Internally the Oracle database supports
two procedural languages, namely PL/SQL and Java. This leads to questions like
"Which of the two is the best?" and "Will Oracle ever desupport
PL/SQL in favour of Java?".
Many Oracle applications are based on
PL/SQL and it would be difficult of Oracle to ever desupport PL/SQL. In fact,
all indications are that PL/SQL still has a bright future ahead of it. Many enhancements
are still being made to PL/SQL. For example, Oracle 9iDB supports native
compilation of Pl/SQL code to binaries.
PL/SQL and Java appeal to different people
in different job roles. The following table briefly describes the difference
between these two language environments:
PL/SQL:
Data centric and tightly integrated into
the database
Proprietary to Oracle and difficult to
port to other database systems
Data manupilation is slightly faster in
PL/SQL than in Java
Easier to use than Java (depending on your
background)
Java:
Open standard, not proprietary to Oracle
Incurs some data conversion overhead
between the Database and Java type systems
Java is more difficult to use (depending
on your background)
How can one see if somebody modified any
code?
Code for stored procedures, functions and
packages is stored in the Oracle Data Dictionary. One can detect code changes
by looking at the LAST_DDL_TIME column in the USER_OBJECTS dictionary view.
Example:
SELECT OBJECT_NAME,
TO_CHAR(CREATED, 'DD-Mon-RR HH24:MI') CREATE_TIME,
TO_CHAR(LAST_DDL_TIME,
'DD-Mon-RR HH24:MI') MOD_TIME,
STATUS
FROM USER_OBJECTS
WHERE LAST_DDL_TIME >
'&CHECK_FROM_DATE';
How can one search PL/SQL code for a key?
The following query is handy if you want
to know where a certain table, field or expression is referenced in your PL/SQL
source code.
SELECT TYPE, NAME, LINE
FROM USER_SOURCE
WHERE UPPER(TEXT) LIKE
'%&KEYWORD%';
* By useing DBA_DEPENDENCIES table you can
find out. - Ezhil
How can one keep a history of PL/SQL code
changes?
One can build a history of PL/SQL code
changes by setting up an AFTER CREATE schema (or database) level trigger
(available from Oracle 8.1.7). This way one can easily revert to previous code
should someone make any catastrophic changes. Look at this example:
CREATE TABLE SOURCE_HIST -- Create history table
AS SELECT SYSDATE CHANGE_DATE, USER_SOURCE.*
FROM USER_SOURCE WHERE 1=2;
CREATE OR REPLACE TRIGGER change_hist -- Store code in hist table
AFTER CREATE ON
SCOTT.SCHEMA -- Change SCOTT to
your schema name
DECLARE
BEGIN
if DICTIONARY_OBJ_TYPE in ('PROCEDURE', 'FUNCTION',
'PACKAGE', 'PACKAGE
BODY', 'TYPE') then
-- Store old code in SOURCE_HIST
table
INSERT INTO SOURCE_HIST
SELECT sysdate, user_source.*
FROM USER_SOURCE
WHERE TYPE = DICTIONARY_OBJ_TYPE
AND NAME = DICTIONARY_OBJ_NAME;
end if;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20000,
SQLERRM);
END;
/
show errors
How can I protect my PL/SQL source code?
PL/SQL V2.2, available with Oracle7.2,
implements a binary wrapper for PL/SQL programs to protect the source code.
This is done via a standalone utility that
transforms the PL/SQL source code into portable binary object code (somewhat
larger than the original). This way you can distribute software without having
to worry about exposing your
proprietary algorithms and methods.
SQL*Plus and SQL*DBA will still understand and know how to execute such
scripts. Just be careful, there is no "decode" command available.
The syntax is:
wrap
iname=myscript.sql oname=xxxx.plb
Can one print to the screen from PL/SQL?
One can use the DBMS_OUTPUT package to
write information to an output buffer. This buffer can be displayed on the
screen from SQL*Plus if you issue the SET SERVEROUTPUT ON; command. For
example:
set
serveroutput on
begin
dbms_output.put_line('Look Ma, I can print
from PL/SQL!!!');
end;
/
DBMS_OUTPUT is useful for debugging PL/SQL
programs. However, if you print too much, the output buffer will overflow. In
that case, set the buffer size to a larger value, eg.: set serveroutput on size
200000
If you forget to set serveroutput on type
SET SERVEROUTPUT ON once you remember, and then EXEC NULL;. If you haven't
cleared the DBMS_OUTPUT buffer with the disable or enable procedure, SQL*Plus
will display the entire contents of the buffer when it executes this dummy
PL/SQL block.
Can one read/write files from PL/SQL?
Included in Oracle 7.3 is an UTL_FILE
package that can read and write operating system files. The directory you
intend writing to has to be in your INIT.ORA file (see UTL_FILE_DIR=...
parameter). Before Oracle 7.3 the only means of writing a file was to use
DBMS_OUTPUT with the SQL*Plus SPOOL command.
Copy this example to get started:
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('/tmp',
'myfile', 'w');
UTL_FILE.PUTF(fileHandler, 'Look ma, I''m
writing to a file!!!\n');
UTL_FILE.FCLOSE(fileHandler);
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20000, 'ERROR:
Invalid path for file or path not in INIT.ORA.');
END;
/
Can one call DDL statements from PL/SQL?
One can call DDL statements like CREATE,
DROP, TRUNCATE, etc. from PL/SQL by using the "EXECUTE IMMEDATE"
statement. Users running Oracle versions below 8i can look at the DBMS_SQL
package (see FAQ about Dynamic SQL).
begin
EXECUTE IMMEDIATE 'CREATE TABLE X(A DATE)';
end;
NOTE: The DDL statement in quotes should
not be terminated with a semicolon.
Can one use dynamic SQL statements from
PL/SQL?
From PL/SQL V2.1 one can use the DBMS_SQL
package to execute dynamic SQL statements. Eg:
CREATE
OR REPLACE PROCEDURE DYNSQL AS
cur integer;
rc
integer;
BEGIN
cur := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cur, 'CREATE TABLE X (Y
DATE)', DBMS_SQL.NATIVE);
rc := DBMS_SQL.EXECUTE(cur);
DBMS_SQL.CLOSE_CURSOR(cur);
END;
/
Another example:
CREATE
OR REPLACE PROCEDURE DEPARTMENTS(NO IN DEPT.DEPTNO%TYPE) AS
v_cursor integer;
v_dname
char(20);
v_rows
integer;
BEGIN
v_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(v_cursor, 'select dname from
dept where deptno > :x', DBMS_SQL.V7);
DBMS_SQL.BIND_VARIABLE(v_cursor, ':x', no);
DBMS_SQL.DEFINE_COLUMN_CHAR(v_cursor, 1,
v_dname, 20);
v_rows := DBMS_SQL.EXECUTE(v_cursor);
loop
if DBMS_SQL.FETCH_ROWS(v_cursor) = 0 then
exit;
end if;
DBMS_SQL.COLUMN_VALUE_CHAR(v_cursor, 1,
v_dname);
DBMS_OUTPUT.PUT_LINE('Deptartment name:
'||v_dname);
end loop;
DBMS_SQL.CLOSE_CURSOR(v_cursor);
EXCEPTION
when others then
DBMS_SQL.CLOSE_CURSOR(v_cursor);
raise_application_error(-20000, 'Unknown
Exception Raised: '||sqlcode||' '||sqlerrm);
END;
/
What is the difference between %TYPE and
%ROWTYPE?
The %TYPE and %ROWTYPE constructs provide
data independence, reduces maintenance costs, and allows programs to adapt as
the database changes to meet new business needs.
%ROWTYPE is used to declare a record with
the same types as found in the specified database table, view or cursor.
Example:
DECLARE
v_EmpRecord
emp%ROWTYPE;
%TYPE is used to declare a field with the
same type as that of a specified table's column. Example:
DECLARE
v_EmpNo
emp.empno%TYPE;
How does one get the value of a sequence
into a PL/SQL variable?
As you might know, oracle prohibits this:
i
:= sq_sequence.NEXTVAL;
(for some silly reason). But you can do
this:
select
sq_sequence.NEXTVAL into :i from dual;
Thanks to Ronald van Woensel
Can one execute an operating system
command from PL/SQL?
There is no direct way to execute
operating system commands from PL/SQL in Oracle7. However, one can write an
external program (using one of the precompiler languages, OCI or Perl with
Oracle access modules) to act as a listener on a database pipe (SYS.DBMS_PIPE).
Your PL/SQL program then put requests to run commands in the pipe, the listener
picks it up and run the requests. Results are passed back on a different
database pipe. For an Pro*C example, see chapter 8 of the Oracle Application
Developers Guide.
In Oracle8 one can call external 3GL code
in a dynamically linked library (DLL or shared object). One just write a
library in C/ C++ to do whatever is required. Defining this C/C++ function to
PL/SQL makes it executable. Look at this External Procedure example.
How does one loop through tables in
PL/SQL?
Look at the following nested loop code
example.
DECLARE
CURSOR dept_cur IS
SELECT deptno
FROM dept
ORDER BY deptno;
-- Employee cursor all employees for a dept
number
CURSOR emp_cur (v_dept_no DEPT.DEPTNO%TYPE)
IS
SELECT ename
FROM emp
WHERE deptno = v_dept_no;
BEGIN
FOR dept_rec IN dept_cur LOOP
dbms_output.put_line('Employees in
Department '||TO_CHAR(dept_rec.deptno));
FOR emp_rec in emp_cur(dept_rec.deptno)
LOOP
dbms_output.put_line('...Employee is
'||emp_rec.ename);
END LOOP;
END LOOP;
END;
/
How often should one COMMIT in a PL/SQL
loop? / What is the best commit strategy?
Contrary to popular believe, one should
COMMIT less frequently within a PL/SQL loop to prevent ORA-1555 (Snapshot too
old) errors. The higher the frequency of commit, the sooner the extents in the
rollback segments will be cleared for new transactions, causing ORA-1555
errors.
To fix this problem one can easily rewrite
code like this:
FOR
records IN my_cursor LOOP
...do some stuff...
COMMIT;
END
LOOP;
... to ...
FOR
records IN my_cursor LOOP
...do some stuff...
i := i+1;
IF mod(i, 10000) THEN -- Commit every 10000 records
COMMIT;
END IF;
END
LOOP;
If you still get ORA-1555 errors, contact
your DBA to increase the rollback segments.
NOTE: Although fetching across COMMITs
work with Oracle, is not supported by the ANSI standard.
I can SELECT from SQL*Plus but not from
PL/SQL. What is wrong?
PL/SQL respect object privileges given
directly to the user, but does not observe privileges given through roles. The
consequence is that a SQL statement can work in SQL*Plus, but will give an
error in PL/SQL. Choose one of the following solutions:
Grant direct access on the tables to your
user. Do not use roles!
GRANT
select ON scott.emp TO my_user;
Define your procedures with invoker rights
(Oracle 8i and higher);
Move all the tables to one user/schema.
What is a mutating and constraining table?
"Mutating" means
"changing". A mutating table is a table that is currently being
modified by an update, delete, or insert statement. When a trigger tries to
reference a table that is in state of flux (being changed), it is considered
"mutating" and raises an error since Oracle should not return data
that has not yet reached its final state.
Another way this error can occur is if the
trigger has statements to change the primary, foreign or unique key columns of
the table off which it fires. If you must have triggers on tables that have
referential constraints, the workaround is to enforce the referential integrity
through triggers as well.
There are several restrictions in Oracle
regarding triggers:
A row-level trigger cannot query or modify
a mutating table. (Of course, NEW and OLD still can be accessed by the trigger)
.
A statement-level trigger cannot query or
modify a mutating table if the trigger is fired as the result of a CASCADE
delete.
Etc.
Can one pass an object/table as an
argument to a remote procedure?
The only way the same object type can be
referenced between two databases is via a database link. Note that it is not
enough to just use the same type definitions. Look at this example:
--
Database A: receives a PL/SQL table from database B
CREATE
OR REPLACE PROCEDURE pcalled(TabX DBMS_SQL.VARCHAR2S) IS
BEGIN
-- do something with TabX from database B
null;
END;
/
--
Database B: sends a PL/SQL table to database A
CREATE
OR REPLACE PROCEDURE pcalling IS
TabX DBMS_SQL.VARCHAR2S@DBLINK2;
BEGIN
pcalled@DBLINK2(TabX);
END;
/
Is it better to put code in triggers or
procedures? What is the difference?
In earlier releases of Oracle it was
better to put as much code as possible in procedures rather than triggers. At
that stage procedures executed faster than triggers as triggers had to be
re-compiled every time before executed (unless cached). In more recent releases
both triggers and procedures are compiled when created (stored p-code) and one
can add as much code as one likes in either procedures or triggers.
Is there a PL/SQL Engine in SQL*Plus?
No. Unlike Oracle Forms, SQL*Plus does not
have a PL/SQL engine. Thus, all your PL/SQL is sent directly to the database
engine for execution. This makes it much more efficient as SQL statements are
not stripped off and sent to the database individually.
Is there a limit on the size of a PL/SQL
block?
Yes, the max size is not an explicit byte
limit, but related to the parse tree that is created when you compile the code.
You can run the following select statement to query the size of an existing
package or procedure:
SQL>
select * from dba_object_size where name = 'procedure_name';
Some Useful Tips:
CURSORS
--------
Cursor can be of two types
Explicit Cursor....
It is declared and can be
OPEN/FETCH and CLOSE programatically.
Implict
REFRENCE CURSOR
-------------------
Ref cursor is nothing but the
pointer which is of a type as Ref cursor or in other
words REF CURSOR is a datatype
for a cursor variable.
we don't attach any select string
with ref cursor. it is declared in the declare part of pl/sql
block e,g
DECLARE
TYPE myRefCur IS REF CURSOR
RETURN
mytable%ROWTYPE
BEGIN
-------
-------
--------
EXCEPTION
END;
REF cursor can be STRONG
TYPE(Restrictive) or of WEAK TYPE(non restrictive)
If we attach the return type with
REF Cursor then it becomes Strong else it is of weak type.
It is of Strong Type:
TYPE myRefCur IS REF CURSOR
RETURN
mytable%ROWTYPE
Weak Type:
TYPE myRefCur IS REF CURSOR;
SNAPSHOT VS MATERIALIZED VIEW
-----------------------------
Materialized Views are the
special type of views which are stored into the database unlike the normal
views. It is generally used when the base tables are distributed among remote
database or when the joining conditions are very complex. It allows the user to
query and join tables which are in different schema.
Snapshot is nothing but the
materialized views. Snapshot is the synonym of Materialized Views (Doubt)
EXCEPTIONS
----------
Exceptions could be of two types
predefined and userdefined
Predefined exceptions are raised
implicitly when Pl/sql block violates some Oracle rule or exceeds the system
defined limit. Every Oracle error has a number but exceptions are handled by
using name.
eg,DUP_VAL_ON_INDEX,
INVALID_CURSOR, INVALID_NUMBER, NO_DATA_FOUND, MORE_THAN_ONE_RECORD,
ZERO_DIVIDE, CURSOR_ALREADY_OPEN etc
User Defined Exceptions
Oracle provides the user to
declare their own exceptions using datatype exception but these exceptions are
raised explicitly, using RAISE keyword. an exception can't be declared twice in
the same block
PRAGMA EXCEPTION
----------------
Pragmas are nothing but the
pseudoinstructions. Pragmas are processed at the compile time not at the run
time. Pragma Exception is a compiler directive. Which is used in the declare
section of the Pl/sql block, it is not the executable statement.
The main purpose of Pragma
Exception is to name the unnamed internal exception, these unnamed internal
exceptions are handled either using WHEN OTHERS in exception block or PRAGMA
EXCEPTION_INIT
eg,
DECLARE
mgr_resgnd EXCEPTION;
PRAGMA EXCEPTION_INIT(mgr_resgnd, -60);
BEGIN
...
EXCEPTION
When mgr_resgnd THEN
....
END;
INDEXES
--------
Indexes are created in oracle to
enable faster access of data. In Oracle B-Tree index is used.
COLLECTIONS
-----------
Collection is an ordered group of
elements all of same type. Each element has unique subscript which determines
its position in the collection. There are two collection types TABLES and
VARRAYS. Tables can be index-by table or nested tables (Nested tables are
extended version of index-by table).Varrays is nothing but variable arrays.
DIFFERENCE BETWEEN VARRAYS AND NESTED TABLES
--------------------------------------------
Nested Tables are like arrays but
they don't have any upper bound.
Nested Tables are sparse i,e they
can have non-consecutive subscript. Hence elements can be deleted from nested
tables by using built-in procedure DELETE.
Oracle stores varray data
in-line(in the same table) unless it exceeds the limit of 4K otherwise it is
stored out-of-line but in the same tablespace. whereas Nested tables are always
stored in out-of-line, but in the same tablespace.
When stored, varrays retain their
ordering and subscripts whereas nested table does not.
Varrays are stored as opaque
objects whereas each element of nested tables are mapped to the entire row. So
for efficient query nested table can be used but where there is a need to
access the entire collection then use of varrays is advisable. Varrays are
generally used for small collection.
Forms/Reports
1. How you declare global
variables in forms ?
Global variable will declared in
When-New-Form-Instance Triggers
2. What are Table Handlers and
Event Handlers?
3. What are new feature in forms
6i compared to forms4.5
4.What is the Difference between
callform, Newform, Openform
5.What is the Use of Program
Units in form/reports ?
6.How many triggers is there in
reports and what are they and what is the Order of firing
Before Parameter
Form
After Parameter
Form
Before report
Between pages
After Report
7.Which trigger will get fired
while opening an LOV in forms
Key-List-Value
8. How Many Types of reports are
there? Name it??
9.What is the Use of Anchors in
Reports
10. What is the uses and
differences between Summary Column, Formula column and Place holder column?
11. What is the Difference
between Bind parameter and lexical
parameter? Which trigger will be used to specify the conditions for a lexical
parameter.
12. What is the use of Destype,
Desname, Desformat in Parameter form.
13.When the Between Pages Trigger
will fire?
After first page this trigger will fire
until last
page and after that for last page it wont
fire.
14. What are the form Modules?
They are 4 types of form modules are
there 1) Alerts 2) Forms Modules 3) Menu
Modules 4) PLSQL Libraries
15.Some of the New Features in
Reports6i
In 6i we can generate the report in different types like PDF,HTML,XML,
RTF etc
In reports goto -> Layout model à
Header or Body or Margin sections à
property
Pallateà Distributions. Specify the Type and file name with
path.
Then gotoà File à Distribute.
16. What is the difference
between Format Triggers and Action Triggers
Action Trigger is Procedure whereas Format
Trigger is Procedure
By using Action trigger we can open the
other form or report
17 What is the Difference between
FlexMode and Confine Mode and their differences
18. What is the Order of triggers
firing
W-N-F-I, Pre-Form, W-N-I-I, W-N-B-I ??
19 What is the Major Differences
and uses between Property Class and Visual Attribute
20. Other than Run_Product how
can we run a report from a form
By using Run_Report_Object
function we can run the reports( This is 6i New Feature)
To use this Add that report in Form Object Navigator and pass the Id of
that report.
21. What are the Default triggers
will be created when a master-detail form is created
There are 3 types are triggers will be created
in form level when a master-detail form is
created.
22. What is the Diiference
between .pll, .pls and .plx in Libraries
23. What is Object Library and
Attached Library
Object Library can be used to stored
Function, Procedure, Package. Attached library will be used to avoid any change
in source code. Object library can be converted into .PLX and attached to
Attache library.
24 What is the difference between writing code
in Programme Unit and Library Files?
The code written in Programme unit is
form’s specific, whereas code written in
Library files, can be used across the forms.
25. When
a form is run, which are the triggers fire, and in what sequence they fire?
PRE-FORM
WHEN-NEW-FORM-INSTANCE
PRE-BLOCK
WHEN-NEW-BLOCK-INSTANCE
WHEN-NEW-ITEM-INSTANCE
POST-BLOCK
POST-FORM
- What is the difference between Forms 4.5 and Forms 6i
Tab Page utility
is not available in 4.5 Version
- What is the utility used to call the report from the
forms?
RUN_REPORT
- What is a Property Class? Different methods of
creating property class?
Property Class
is defining properties of objects along with their settings. The property class inheritance allows the
user to perform global changes very quickly and efficiently.
Methods:
Object Navigator
Method
Properties
Window Method
- WHEN-NEW-FORM trigger written at Form Level, Block
Level and Item Level
which one will
fire first?
The trigger written at the lower level Item
Level Fires first then at Block Level and at last it fires in Form Level.
- In the previous question circumstance, is it possible
to change the order of trigger
Execution? If Yes, where it needs to be changed?
Yes, in the
trigger property (Before, After, Default)by changing the attributes.
- What are the different kinds of Parameters available
in the report?
System and User defined
Parameters.(Bind and Lexical Parameters)
No comments:
Post a Comment