You are on page 1of 21

ADVANCE PL-SQL

Why we going for advance pl-sql.


What is COLLECTIONS
COLLECTIONS
• Collection is a data type it is a single dimensional array
• It is Collection is a composite datatype
• Array is a set of components
• In collection Same data-type values can be stored
• it consists of one or more elements accessible through an index
value. Collections are used in some of the most important
performance optimization features of PL/SQL, such as. BULK COLLECT.
What are types of collections
What are types of collections
• Index by table.
• Varray
• Nested table
• records
Difference between cursor and collections
Difference between cursor and collections
Cursor :
• Its not datatype.
• Its pointer to context area.
• In cursor there is no array.
• Only forward declaration.
• It will fetch row by row and required low memory.
• Poor performance.
Collections:
• Its datatype.
• Its not pointer.
• Its an array either single dimensional or two dimensional array.
• It may used in forward , backward and random declaration.
• It fetch in single shot & stored in db need large memory
• It improve performance.
METHODS USED IN COLLECTIONS
METHODS USED IN COLLECTIONS
EXISTS (n) This method will return Boolean results.
It will return 'TRUE' if the nth element exists in that collection, else it will return FALSE.
Only EXISTS functions can be used in uninitialized collection <collection_name>.EXISTS(element_position)

COUNT Gives the total count of the elements present in a collection <collection_name>.COUNT
LIMIT It returns the maximum size of the collection.
For Varray, it will return the fixed size that has been defined.
For Nested table and Index-by-table, it gives NULL <collection_name>.LIMIT
FIRST Returns the value of the first index variable(subscript) of the collections <collection_name>.FIRST

LAST Returns the value of the last index variable(subscript) of the collections <collection_name>.LAST
PRIOR (n) Returns precedes index variable in a collection of the nth element. If there is no precedes index value NULL is returned
<collection_name>.PRIOR(n)
NEXT (n) Returns succeeds index variable in a collection of the nth element. If there is no succeeds index value NULL is returned
<collection_name>.NEXT(n)
EXTEND Extends one element in a collection at the end <collection_name>.EXTEND
EXTEND (n) Extends n elements at the end of a collection <collection_name>.EXTEND(n)
EXTEND (n,i) Extends n copies of the ith element at the end of the collection <collection_name>.EXTEND(n,i)
TRIM Removes one element from the end of the collection <collection_name>.TRIM
TRIM (n) Removes n elements from the end of collection <collection_name>.TRIM (n)
DELETE Deletes all the elements from the collection. Makes the collection empty <collection_name>.DELETE
DELETE (n) Deletes the nth element from the collection. If the nth element is NULL, then this will do nothing <collection_name>.DELETE(n)

DELETE m,n) Deletes the element in the range mth to nth in the collection <collection_name>.DELETE(m,n)
CHARACTERISTICS OF PL/SQL COLLECTION TYPES
CHARACTERISTICS OF PL/SQL COLLECTION TYPES

Collection Type Number of Elements Subscript Type Dense or Sparse Where Created Can Be Object Attribute
Type

Associative array (or Unbounded String or Either Only in PL/SQL block No


index-by table) integer

Nested table Unbounded Integer Starts dense, can Either in PL/SQL block or at Yes
become sparse schema level

Variable-size array Bounded Integer Always dense Either in PL/SQL block or at Yes
(varray) schema level
What is DBMS_Profiler
DBMS_profiler is used to get the time of each line
query’s.
we can find which line takes more time.
Why we go for Bulk collect
BULK COLLECT is one of the way of fetching bulk collection of data. With Oracle bulk collect, the
PL/SQL engine tells the SQL engine to collect many rows at once and place them into a collection.

During an Oracle bulk collect, the SQL engine retrieves all the rows and loads them into the collection
and switches back to the PL/SQL engine.

When rows are retrieved using Oracle bulk collect, context switch happens only once.

The larger the number of rows you would like to collect with Oracle bulk collect, the more
performance improvement you will see using an Oracle bulk collect.
Difference between bulk collect & bulk bind
BULK COLLECT is used to fetch the records through the cursor. Bulk collect extract
data from multiple rows in a single fetch thus improving the speed of data retrieval.
It also gives a command to PL/SQL engine for bulk-binding the input collections
before sending them to SQL engine.

FORALL is used to perform DML operation of the fetched data. It quickly INSERTs,
UPDATEs, and DELETEs that use collections to change multiple rows of
data. FORALL also command the PL/SQL engine to bulk-bind input collections before
sending them to the SQL engine.
Materialized view privileges: SELECT and
QUERY REWRITE
GRANT QUERY REWRITE TO userName;
What is Dynamic sql
Dynamic SQL is an enhanced form of Structured
Query Language (SQL) that, unlike standard (or
static) SQL, facilitates the automatic generation
and execution of program statements.

You might also like