You are on page 1of 18

Oracle 11g Features

To the surprise of Database professionals, Oracle 11g no longer keeps


PL/SQL as a pure procedural language. Now PL/SQL is efficient to
implement Object Oriented Concepts, thus making it comparable to other
programming languages like C++ and JAVA.

Oracle 11g introduced new features and enhancements in below areas:


Performance Improvements
Enhancements to improvise the usability and compatibility of PL/SQL as a
language
Include earlier workaround implementations as language features

Enhancements in Oracle
Compiler enhancements (Real Native Compilation) Oracle 11g PL/SQL
compiler is no more dependent on third part C compiler but it can use
PL/SQL source code to directly generate the native code. This improves
compilation time and results in faster execution. The newly added
SQL> ALTER SYSTEM SET PLSQL_CODE_TYPE=NATIVE SCOPE=SPFILE;
SQL> ALTER PROCEDURE MY_PROC COMPILE PLSQL_CODE_TYPE=NATIVE;

Fresh Additional Features

Read Only Tables


In Oracle 11g, a table can be set READ ONLY mode to restrict write
operations on the table. A table can be altered to toggle over READ ONLY
and READ WRITE modes.
SQL> ALTER TABLE EMP READ ONLY;
SQL> ALTER TABLE EMP READ WRITE;

Invisible Indexes:
Oracle 11g provides flexibility in query performance testing by introducing
Invisible Indexes.
CREATE INDEX IDX_EMP_NAME ON EMP (ENAME) INVISIBLE;
SELECT /*+ index (ENAME IDX_EMP_NAME) */
FROM EMP WHERE ENAME LIKE %DBA%;

If the index usage makes considerable impact on the query performance,


the invisible index can be altered to VISIBLE mode.
ALTER INDEX IDX_EMP_NAME VISIBLE;

Virtual Columns
Oracle 11g allows a user to create virtual columns in a table whose
values are derived automatically from other actual columns of the
same table. They show same behavior as other columns in the table
in terms of indexing and statistics.
Currently, Oracle does not support LOB and RAW values in virtual
columns.
column [datatype] [GENERATED ALWAYS] AS ()[VIRTUAL]
[( inline_constraint [,...] )]
Here, GENERATED ALWAYS and VIRTUAL are optional keywords, but
included for more clarity.
A table ORDERS is created with ORDER_VAL_ANN as virtual column,
whose value is derived from ORDER_VAL column of the ORDERS table
CREATE TABLE ORDERS(ORDER_ID NUMBER PRIMARY
KEY,ORDER_VAL NUMBER
ORDER_VAL_ANN AS (ORDER_VAL*12));

Result Cache in SQL and PL/SQL


Oracle 11g has introduced a new SGA component (Shared Pool) as
Result Cache to retain SQL and PL/SQL results for same set of
inputs.
Size of result cache is determined by RESULT_CACHE_MAX_SIZE
parameter whose value depends on MEMORY_TARGET (0.25%),
SGA_TARGET (0.5%), and SHARED_POOL_SIZE (1%) parameters. It
can be increased at SYSTEM level but cannot exceed 75% of the
shared pool.
Result Cache Mode: Result Cache feature operates in two modes
namely, MANUAL (default mode) and FORCE. In MANUAL operation
mode, RESULT_CACHE has to be explicitly specified for Oracle to
cache the results. In FORCE operation mode, all query result sets are
forcibly cached in shared pool until NO_RESULT_CACHE hint is used
in the query.
In PL/SQL functions, Result Cache can be achieved by including an
additional RESULT_CACHE clause in the function definition. It is
optionally followed by RELIES_ON to specify the dependent tables.

Compound Trigger

In compound trigger logic, all timing point logics are clubbed in one
single body

resolves the issue where same set of session variables share common
data and the famous mutating table error(ORA-04091).

A compound trigger is a single trigger on a table that enables you to


specify actions for each of four timing points:
Before the firing statement
Before each row that the firing statement affects
After each row that the firing statement affects
After the firing statement

The compound trigger is useful when you want to accumulate facts that
characterize the "for each row" changes and then act on them as a body
at "after statement" time. Sometimes you are forced to use this approach
(to avoid the mutating table error). Sometimes this approach gives better
performance;
for example, when maintaining a denormalized aggregate value in a
master table in response to changes in a detail table, or when
maintaining an audit table.

Set trigger firing order using FOLLOWS


Oracle 11g enables user to control the order of trigger execution. If
multiple triggers are created for the same timing point and event on
the same table, it order of execution can be set using FOLLOWS
clause. FOLLOWS clause in a trigger specifies that the current trigger
would follow the execution of specified triggers.
CREATE [OR REPLACE] TRIGGER TRIGGER_NAME
BEFORE [INSERT | UPDATE | DELETE] ON [TABLE NAME] FOLLOWS
[TRIGGER1, TRIGGER2]
WHEN
Creating a trigger in DISABLED mode
Prior to Oracle 11g, a trigger can be created in ENABLED mode only.
Oracle 11g provides flexibility to create a Trigger in DISABLED mode
also. They remain deactivated until they are enabled.
CREATE TRIGGER [TRIGGER NAME]
BEFORE [INSERT | UPDATE | DELETE] ON [TABLE]
DISABLED
WHEN

Secure Files to handle Large Objects


Oracle 11g has brought major changes by calling LOB storage as
Secure Files. These are completely different from previous LOB
data which would be now categorized under Basic Files.
SecureFile(s) primarily focuses on performance, space
consumption and security of objects.

This provides storage scalability and object organization


manageability.
SecureFile usage policy can be enabled by setting DB_SECUREFILE
parameter at SYSTEM level

ALTER SYSTEM SET DB_SECUREFILE = [PERMITTED | FORCE |


ALWAYS |
IGNORE | NEVER]
CREATE TABLE employees( [COLUMN] BLOB )TABLESPACE

tools
LOB ([COLUMN]) STORE AS SECUREFILE (LOB storage
parameters);

Partitioning Enhancements

Partitioning was first introduced in Oracle 8 release to achieve


scalability and effective data maintenance.
Over the period of time, it has emerged as one of the strongest
feature for Large Scale Data Warehouses.
In earlier version of Oracle, the most common type of Partitioning
method used was Range Partitioning
Oracle 11g introduces below additional partitioning
strategies.
Extended composite partitioning strategies Imposing multiple
partitioning methods likeList-Range combination
Virtual column based partitioning Partition based on Virtual
Column is known as Virtual Colum Based Partitioning
Interval Partitioning Extension of Range Partitioning.
REF Partitioning The Child table follows the same Partitioning
scheme as specified for the parent node through PK-FK.

Interval partitioning for tables:

This is a new 11g partitioning scheme that automatically creates timebased partitions as new data is added. We can now partition by date, one
partition per month for example, with automatic partition creation.
Partitioning Enhancements

Partition by parent/child reference


Partition orders and order lines together
Virtual column partitioning
Partition on virtual order status: active, less active
Referential partitioning
More composite partitioning : List/range, range/range, list/hash, list/list

create table selling_stuff_daily ( prod_id number not null, cust_id


number not null, sale_dt date not null, qty_sold number(3) not null,
unit_sale_pr number(10,2) not null
, total_sale_pr number(10,2) not null, total_disc number(10,2) not null)
partition by range (sale_dt)
interval (numtoyminterval(1,'MONTH'))
( partition p_before_1_jan_2007 values less than (to_date('01-012007','dd-mm-yyyy')));

Program Inlining (A new PLSQL_OPTIMIZE_LEVEL)


Program inlining refers to replacing of the program call with a copy
of the program.
There can be selective scenarios in cumbersome applications where
subprogram inlining improves performance
Prior to Oracle 11g, PLSQL_OPTIMIZE_LEVEL initialization parameter
had 1 and 2 as admissible values to make decision over optimizer
level.
Oracle 11g introduces additional value 3 in the bracket, which
directs the optimizer to inline the subprograms at high priority.
Note that optimizer does not performs any inlining at level 1, while
logical inlining of subprograms at level 2. At level 3, optimizer
inlines all the subprograms calls.
A new pragma PRAGMA INLINE has been introduced to specify
whether a subprogram call has to be inlines or not. It intakes two
parameters namely, subprogram name and [YES | NO].
Regular Expression enhancement REGEXP_COUNT
Oracle 11g adds REGEXP_COUNT as the latest member in the
regular expression family. It is used to count the occurrence of a
character or string expression in another string.

New Analytic Functions Below new Analytic functions


were introduced:

LISTAGG Prior to Oracle 11g, conversion of rows into columns


using a delimiter was done by workaround solution using XMLAGG
or DECODE function.
This function aggregates the result set in multiple rows into one
single column
NTH_VALUE The nth value range in a column can be determined
using NTH_VALUE function.

Oracle 11g XML data storage :


We can store XML either as a CLOB or a binary data
type, adding flexibility. Oracle11g will support query
mechanisms for XML including XQuery and SQL XML,
emerging standards for querying XML data stored inside
tables.

Coding Enhancements
Fast DML triggers In Oracle 11g, DML triggers have shown
performance upgrade by 25%.
Default Value in Table ALTER command In the Oracle version earlier
than 11g, if a table has to be altered to add a column, the very next
step was to update the existent rows to some default value.
Oracle 11g allows providing DEFAULT value for a column during table
alteration. This has resolved the overhead of updating column with
default value.
ALTER TABLE [TABLE NAME] ADD [COLUMN] [DATA TYPE] [NOT NULL]
DEFAULT [DEFAULT VALUE]
Sequence Assignment
Prior to Oracle 11g, sequence assignment to a number variable could
be done through a SELECT statement only.
This was the gray area which could have degraded performance due to
context switching from PL/SQL engine to SQL engine. Oracle 11g has
transformed this feature of Sequence assignment to a PL/SQL construct.

Functions in SQL-Named Notation

In Oracle 11g, functions can now be called using Named, Positional


and Mixed notation while calling from SQL SELECT statement.
Below function uses Mixed notation of parameter passing in the
Function call
SQL> SELECT F_SUMNUM (P_A => 10, 20) FROM DUAL;

CONTINUE in FOR LOOP

Prior to Oracle 11g, if a value in an iterating loop has to be ignored,


NULL operation was assigned.

Oracle 11g identified it as bad code practice to assign NULL


operation to the compiler. CONTINUE
statement can be used to direct the pointer to continue its
iteration if it matches the ignore condition.
FOR I IN 100..200 LOOP
IF I IN (100,200) THEN
CONTINUE;
ELSE
SUM := SUM + I;
END IF;

Prevent guessing of open cursor numbers:


A new error, ORA-29471, will be raised when any DBMS_SQL subprogram
is called with a cursor number that does not denote an open cursor.
When the error is raised, an alert is issued to the alert log and DBMS_SQL
becomes inoperable for the life of the session. As a consequence there
may be runtime errors for DBMS_SQL post-upgrade.
ORA-06531 11g issue: UnInitialized collections (VARRAYs)
Issue: 'ORA-06531: Reference to uninitialized collection is introduced by
the stricter PL/SQL code checking since 10g release.

Oracle Suggested Solution:


Please fix the code to handle proper initialization. Use pre-defined
exception handling to address this scenario. The Pre-defined PL/SQL
Exceptions are listed in the Oracle 11g PL/SQL Language reference.

Though not recommended by GCSDBA, in certain circumstances where


significant code change is required the below setting will allow the pl/sql
parser to allow this scenario and ignore this error.
Set event='10943 trace name context level 2097152

WHEN OTHERS compile time warning


Oracle 11g discourages the use of WHEN OTHERS generic exception as it
suppresses the important exceptions in the program. In oracle 11g, such code
would raise a warning PLW-06009. Note that this is a PL/SQL warning and not
an exception. Program continues the execution but traces the coding standard
failure.
New data types
Oracle 11g has designed a new data type SIMPLE_INTEGER, SIMPLE_FLOAT,
and SIMPLE_DOUBLE keeping in view the hardware requirements and
expectations with an Integer value. They are compatible with the native
compilation feature of Oracle 11g, which makes supports their faster
implementation.
SIMPLE_INTEGER restricts NULL values and provide number range from
-2147483648 to 2147483647. Similarly, the other two data types avoid NULL
check and data overflow checks, thereby enhancing performance to a notable
extent.
SKIP LOCKED for locked tables Oracle 11g introduced SKIP LOCKED
clause to query the records from the table which are not locked in any other
active session of the database. This looks quite similar to exclusive mode of
locking.
SELECT * FROM EMP FOR UPDATE SKIP LOCKED

IGNORE_ROW_ON_DUPKEY_INDEX Hint for INSERT Statements

In Oracle 11g, the INSERT statements which use other table to load the data can
make use of the hint IGNORE_ROW_ON_DUPKEY_INDEX to avoid the unique key conflict
with the existing row. It ignores the unique key violation during insertion.
It is similar to handling of DUP_VAL_ON_INDEX exception, but comparatively it is slower
than a single INSERT statement and carries the overhead of creating a PL/SQL block.

DATABASE_ROLE constant for SYS_CONTEXT


A new parameter is introduced in USERENV namespace which returns the database role
currently used by the Oracle server. Possible values of DATABASE_ROLE constant are
PRIMARY, PHYSICAL STANDBY, LOGICAL STANDBY, and SNAPSHOT STANDBY.

SELECT sys_context(USERENV, DATABASE_ROLE) FROM dual;

NO_DATA_NEEDED new exception For parallel access and pipelined table functions,
ORA-06528 exception was included in predefined exception list as NO_DATA_NEEDED.

Encrypted Tablespace
Encryption of Tablespace was introduced with Oracle 10g version but was deprecated
due to multiple existing issues. Tablespace encryption in Oracle 11g extends the concept
of Transparent Data Encryption and resolves the limitations of range scan and primary
key issues. A new tablespace can be created in Encrypted form, with all of its tables and
indexes in Encrypted form.
CREATE TABLESPACE
[ENCRYPTION [USING ]] DEFAULT STORAGE(ENCRYPT)

Tablespace specification for GTT Oracle 11g provides provision


to specify tablespace for Global Temporary tables. In earlier versions,
GTT used to consume current users default temporary tablespace.
CREATE GLOBAL TEMPORARY TABLE G_ORDERS
(ORDER_ID NUMBER, ORDER_DATE DATE, ORDER_QTY NUMBER)
ON COMMIT PRESERVE ROWS TABLESPACE GTT_TEMP;

Restore Points in Database


In Oracle 11g, similar to SAVEPOINT in TCL commands, a RESTORE
POINT can be created in the Database for a particular SCN or till a
timestamp.

SQL> CREATE RESTORE POINT RP_ID AS OF SCN 310000


SQL> CREATE RESTORE POINT RP_ID AS OF TIMESTAMP
TO_TIMESTAMP(23-JAN-2011)
Advanced Compression Option

Oracle 11g can now efficiently compress Structured/Unstructured


data, back up data (RMAN), Data pump export files, and network
transport data. Having first introduced in Oracle 9i.

Reversing Transactions Accurately


Via Flashback Transaction Backout

Oracle Database 11gs new Flashback Transaction Backout (FTB) feature


allows an authorized user session to back out a single transaction -- as well
as any corresponding dependent transactions -- by applying appropriate
compensating statements for the affected transaction(s). FTB uses undo
data, redo data generated for the UNDO blocks, and supplemental logging
to accomplish this.

First select the data in recyclebin and then insert into original table as
below

SELECT * FROM pos_seed_labels AS OF TIMESTAMP TO_TIMESTAMP('28-SEP11 08.46.17 PM') WHERE label


='CASH_DRAWER_NOT_CONFIGURED_CONFIRM' and id_sls_org = '1583' and
locale = 'en_GB' and APP_COMPONENT = 'I' ;

INSERT INTO pos_seed_labels(SELECT * FROM pos_seed_labels AS OF


TIMESTAMP TO_TIMESTAMP('28-SEP-11 08.46.17 PM') WHERE id_sls_org =
'1583' AND locale = 'en_GB' AND APP_COMPONENT = 'I' );

You might also like