Sei sulla pagina 1di 13

Program Specification

Oracle 10g New Features in SQL


Oracle 10g New Features
Oracle 10g is release targetted on two goals : Manageability and performance I have provided the highlights on SQL Enhancements here. And planning to post more related items here.

New features with SQL in 10g


10g Release provides support for case-insensitive queries and sorts, which facilitates

to search and sort their data, Regardless of the casing and accent of the characters.
Regular expressions are also supported in SQL and PL/SQL, allowing developers to

write one-line queries that previously would have taken multiple lines of SQL code.
Now SQL is POSIX-compliant and also supports multilingual queries and is locale

sensitive.
A new capability, Expression Filtering, is also supported in this release, that allows

application developers to manage and evaluate conditional expressions that describe users' interests in data.
Other SQL improvements include new CONNECT BY processing that supports

ancestor-descendant pairs, and new collection performance and type evolution enhancements.

Case-Insensitive and Accent-Insensitive Query and Sort


10g has provided linguistic/accent based sorts and. Also you can write a sort or query on the base letters only (accent insensitive) or on the base letter and the accents (case insensitive).

New Data types - BINARY_DOUBLE, BINARY_FLOAT


These new types are single- and double-precision floating point number datatypes. With this types arithmetic calculations are faster and uses less storage. Also, you can implement algorithms with IEEE behavior for arithmetic operations. Intense number crunching computations (where scale and precision requests accommodated by the IEEE types) can run substantially faster using these types than using regular type NUMBER. Integration with XML and Java environments is an added merit(because it is now similar with Java/XML datatypes).

Collection Enhancements
Now collections are much morebetter in performance and functionality.

House Keeping

61997864.docFINANCIAL_YEAR

1 Page 1

Program Specification

Now, You can use


use varrays in temporary tables. Size of a VARRAY type object can be modified. Specify different tablespaces for different columns of nested table type. You can use comparison conditions (Equal, Not Equal) and ANSI Multiset operations

with collection/nested variables.

CONNECT BY - Enhancements
Connect by has also added a bunch of new and useful features.
All ancestor-dependent pairs can be returned (not just parent-child pairs) . A new pseudocolumn added to find whether a given node is a leaf or not. A cycle in a hierarchy triggers an error with details on rows afeected in the cycle

Supports simple subqueries.

Expression Filter Enhancements


Expression Filter provides an Expression datatype, SQL EVALUATE operator, and indexing. This allows conditional expressions to be stored in a column of a table and searched. The EVALUATE operator checks incoming data with the expressions to find affected rows. You can sort Incoming data in a table and compare it with expressions of another table by using a join. Yo can easily make very complex relationships between tables.

Extensible Indexing
Ability to alter user-defined domain operators, is possible with Extensible Indexing. You can maintain global and local domain indexes during partition maintenance. This enables parallel creation of local domain indexes.

Regular SQL Expressions


This release supports POSIX-compliant regular expressions. This incerases search and replace capability in programming environments like Java. In SQL,this is implemented by using new functions in equivalent to existing functions (For instance LIKE and REPLACE).Also, supports multilingual queries and locale sensitive expressions.

SCN or Row Timestamp

House Keeping

61997864.docFINANCIAL_YEAR

2 Page 2

Program Specification

This is a new pseudocolumn consisting of the date/time stamp (also called SCN - System change number) for last commit. You can efficiently implement optimistic locking by using this. Before 10g, we have to compare all columns with identical values of old row. Using SCN, this is simplified, just compare the row SCN to verify that the row has not changed after it is selected for a update

Oracle 10g PLSQL Compiler Enhancements


Let's start with the enhancements to the Oracle 10g PLSQL compiler. Oracle have improved integer and floating point performance, the elimination of unreachable code, and the calling of library routines to give an overall improvement of 50-75% in the performance of PL/SQL code compared to Oracle 9i. It needs to be stressed that this improvement is overall - PLSQL code with many database calls will benefit less than compute-intensive PLSQL code.

PLSQL Floating-point Performance


Floating-point performance has been improved by the introduction of 2 new data types BINARY_FLOAT and BINARY_DOUBLE which meet the IEEE 754 standard and have native support on many platforms making them much more efficient for use in scientific applications.

PLSQL Integer Performance


Integer performance has been improved by changing the BINARY_INTEGER data type to be the same as the PLS_INTEGER type which had better performance in Oracle 9i and below. These 2 data types are now interchangeable.

Oracle 10g PLSQL Compiler Warnings


Another enhancement to the Oracle 10g PLSQL compiler is the introduction of compiler warnings to supplement the compiler errors that were generated in previous versions of Oracle. There are 3 levels of warnings: severe, informational and performance-related. The idea of these is to notify you of any potential problems or performance issues with your code so that you can review them and if necessary correct them. As with syntax errors, any warnings will be displayed by the show errors command after compilation. Unlike syntax errors, any warnings will not prevent the code from being compiled and run. PLSQL compilation warnings are enabled/disabled at the system level by the value of the plsql_warnings parameter or alter system command and at the session level by use of the alter session command. For example alter session set plsql_warnings='enable:performance' will turn on performance-related warning messages for the current session and

House Keeping

61997864.docFINANCIAL_YEAR

3 Page 3

Program Specification

alter system set plsql_warnings='disable:performance scope=memory' will turn off performance-related warning messages for all sessions.

PLSQL Regular Expressions


Regular expressions have long been a powerful feature of text editors and other utilities on UNIX and LINUX and have now been brought to the database greatly enhancing the primitive pattern matching facilities previously available in Oracle with the LIKE clause.

Oracle Tips & Tricks to SKYROCKET Your Career!


If you're not already a subscriber to Oracle Tips and Tricks, you're missing out on a myriad of tips and techniques to help you work better, faster and smarter. Subscribe now to enhance your career. In Oracle 10g PLSQL there are 4 new functions supporting pattern matching with regular expressions: REGEXP_LIKE, REGEXP_INSTR, REGEXP_SUBSTR and REGEXP_REPLACE which can be used anywhere you would previously have used LIKE, INSTR, SUBSTR and REPLACE. Of course the original functions can still be used, you only need to use the new ones when you want to use regular expressions. If you have used regular expressions before with UNIX utilities such as SED or AWK then the good news is that the meta symbols used in regular expressions in PLSQL and SQL in Oracle 10g and above are much the same. If you've not encountered regular expressions before they're easy to follow once you understand the meanings of the meta symbols - the most common of which are as follows. Symbol * Description Wild card matches zero or more occurrences Wild card matches zero or one characters Example '*Ad' matches 'mAd', 'bAd','sAdness', 'lAd' '?eg' matches 'eg', 'egg','beg','legging'

^ $ .

'^top' matches 'topping', matches beginning 'topper','topped' but not of string 'stop' matches end of string matches any character except NULL 'top$' matches 'stop' but not stopping 's.*s' matches 'success', 'stars','slaves'

Let's have a look at a few examples of how to use these new functions in Oracle 10g PLSQL.

House Keeping

61997864.docFINANCIAL_YEAR

4 Page 4

Program Specification

select 'True' from dual where regexp_like ('Heather','^Heath') returns 'True' because we've asked if our test string starts with a capital 'H' and is followed by 'eath' which it does. One thing to note is that these functions are case sensitive so 'Heather' would not match '^heath'. dnms_output.put_line(regexp_instr('Heather','THe')); This will display 0 because we've asked for the position of 'The' in our test string which is not present. dnms_output.put_line(regexp_instr('Theatre','The')); x will be 1 because we've asked for the position of 'The' in our test string. dnms_output.put_line(regexp_instr('Theatre','?he')); x will be 2 because the substring 'he' starts at the 2nd letter in our test string. dbms_output.put_line(regexp_substr('Theatre','?he')); This will display 'he' because the substring 'he' starts at the 2nd letter in our test string. dnms_output.put_line(regexp_substr('Theatre','^he')); This will print nothing because the substring 'he' does not start at the beginning of our test string. dnms_output.put_line(regexp_replace('Theatre','^The')); This will display 'atre' because the substring 'The' has been replaced with nulls. dnms_output.put_line(regexp_replace('Theatre','^The','***')); This will display '***atre' because the substring 'The' has been replaced with ***.

Oracle 10g PLSQL Collection Enhancements


Both Oracle 10g PLSQL and SQL support the ANSI multiset operators enabling nested tables to be compared for equality (=) and inequality (!= or <>) and with set operators [NOT] IN, [NOT] MEMBER [OF] and [NOT] SUBMULTISET. Various properties of a nested table collection can also be determined using the set operators CARDINALITY, IS [NOT] A SET, IS [NOT] EMPTY. Finally, you can assign nested tables using the set operators MULTISET UNION [DISTINCT], MULTISET INTERSECT [DISTINCT], MULTISET EXCEPT [DISTINCT] and SET. Let's look at some examples to see how these work.

House Keeping

61997864.docFINANCIAL_YEAR

5 Page 5

Program Specification

Comparing Oracle 10g PLSQL Collections

Example 1 - using "="


declare type nested_table is table of number; tab1 tab2 tab3 tab4 begin if tab1 = tab2 then dbms_output.put_line('tab1 is equal to tab2'); else dbms_output.put_line('tab1 differs from tab2'); end if; if tab1 = tab3 then dbms_output.put_line('tab1 is equal to tab3'); else dbms_output.put_line('tab1 differs from tab3'); end if; if tab1 = tab4 then dbms_output.put_line('tab1 is equal to tab4'); else dbms_output.put_line('tab1 differs from tab4'); end if; end; In the above example we compare two nested tables using "=" as if they were simple variables. Running this example produces the following results:tab1 is equal to tab2 tab1 differs from tab3 tab1 differs from tab4 This shows - as you would expect - that two empty nested tables match (tab1 and tab2) and that an empty table is not the same as a table which has been populated. The example also shows that a null table (tab4) is not the same as an empty table. We can reverse the equlaity test by replacing "=" with "!=" or "<>" nested_table := nested_table(); nested_table := nested_table(); nested_table := nested_table(1); nested_table;

Example 2 - using "IN" and "NOT IN"


The IN operator works on nested tables in Oracle 10g PLSQL in a similar way to how it works with other types of variables. In this case it checks whether the nested table on the left of the operator matches any of the nested tables on the right of the operator. There are a couple of points to note when using this operator with nested tables: there has to be an exact match, not a match as a subset

House Keeping

61997864.docFINANCIAL_YEAR

6 Page 6

Program Specification

to build a nested table at runtime for comparison you need to use the constructor method (type name) - you can't compare number constants or number variables as shown in the last 2 statements in the example

declare type nested_table is table of number; table_1 nested_table := nested_table(1); table_2 nested_table := nested_table(1,2,3); table_3 nested_table := nested_table(1); num NUMBER := 3; begin if table_1 in (table_2) then dbms_output.put_line('table_1 in table_2'); else dbms_output.put_line('table_1 not in table_2'); end if; if table_3 not in (table_2) then dbms_output.put_line('table_3 not in table_2'); else dbms_output.put_line('table_3 in table_2'); end if; if table_3 in (table_1,table_2) then dbms_output.put_line('table_3 in table 1 or 2'); else dbms_output.put_line('table_3 not in table 1 or 2'); end if; /* -- can't do this if 3 not in (table_2) then dbms_output.put_line('3 not in table_2'); else dbms_output.put_line('3 in table_2'); end if; -- can't do this if num not in (table_2) then dbms_output.put_line('3 not in table_2'); else dbms_output.put_line('3 in table_2'); end if;

*/ /*

*/ end;

Example 2 produces the following results: table_1 not in table_2 table_3 not in table_2 table_3 in table 1 or 2

House Keeping

61997864.docFINANCIAL_YEAR

7 Page 7

Program Specification

Example 3 - checking for membership


The "MEMBER OF" operator is used in Oracle 10g PLSQL to determine whether or not the specificied contsant or variable is in a nested table collection. Note that you can't use this to determine if a nested table is a subset of another. declare type nested_table is table_1 nested_table table_2 nested_table num begin if 1 member of table_2 then dbms_output.put_line('1 is a member of table_2'); else dbms_output.put_line('1 not member of table_2'); end if; if num not member of table_2 then dbms_output.put_line('num not a member of table_2'); else dbms_output.put_line('num is a member of table_2'); end if; /* can't do this if table_1 member of table_2 then dbms_output.put_line('table_1 member of table_2'); else dbms_output.put_line('table_1 not member of table_2'); end if; table of number; := nested_table(1); := nested_table(1,2,3); NUMBER :=3;

*/ end;

Example 3 produces the following results: 1 is a member of table_2 num is a member of table_2

Example 4 - using "SUBMULTISET"


The submultiset operator in Oracle 10g PLSQL enables you to determine whether or not one nested table is a subset of another nested table. declare type nested_table is table_1 nested_table table_2 nested_table num begin if table_1 submultiset table_2 then table of number; := nested_table(1); := nested_table(1,2,3,1); NUMBER :=3;

House Keeping

61997864.docFINANCIAL_YEAR

8 Page 8

Program Specification

dbms_output.put_line('table_1 subset of table_2'); else dbms_output.put_line('table_1 not subset of table_2'); end if; if table_2 not submultiset table_3 then dbms_output.put_line('table_2 not subset of table_3'); else dbms_output.put_line('table_2 is subset of table_3'); end if; /* --can't do this if 3 not submultiset table_2 then dbms_output.put_line('table_2 does not contain 3'); else dbms_output.put_line('table_3 includes 3'); end if; */ end; Example 4 produces the following results: table_1 subset of table_2 table_2 not subset of table_3

PLSQL Collection Enhancements


Having looked at comparing nested table collections (part 2), let's look at using the set operators CARDINALITY, IS [NOT] A SET, IS [NOT] EMPTY to determine the properties of a nested table collection. Then in Oracle 10g PLSQL new features part 4 we'll look at how to assign to nested tables using the set operators MULTISET UNION [DISTINCT] , MULTISET INTERSECT [DISTINCT], MULTISET EXCEPT [DISTINCT] and SET.

Using Set Operators On Oracle 10g PLSQL Collections

Example 1 - CARDINALITY
The cardinality function returns the count of the number of elements in a nested table type collection. The points to note with this function are that an empty set returns a count of 0 as expected but a null set returns a value of NULL. declare type BOOK_LIST is table of varchar2(100); oracle_books book_list := book_list('Oracle 10g New Features' ,'Oracle 10g PLSQL New Features' ,'Oracle 10g Application Server');

House Keeping

61997864.docFINANCIAL_YEAR

9 Page 9

Program Specification

empty_list book_list := book_list(); other_books book_list; begin dbms_output.put_line('cardinality of oracle_books is '|| cardinality(oracle_books)); dbms_output.put_line('no. of books in other_books is '|| cardinality(other_books)); dbms_output.put_line('no. of books in empty_list is '|| cardinality(empty_book_list)); end; Example 1 produces the following results: cardinality of oracle_books is 3 number of books in other_books is number of books in empty_book_list is 0

Example 2 - IS [NOT] EMPTY


This PLSQL operator returns TRUE if a collection is empty or FALSE otherwise and of course the results can be inverted by use of the optional NOT operator. declare type book_list is table of varchar2(100); oracle_books book_list; oracle_books_2 book_list := book_list(); oracle_books_3 book_list := book_list('PLSQL New Features', 'Oracle 10g New Features','Oracle 10g Application Server'); begin if oracle_books is empty then dbms_output.put_line('oracle_books is empty'); elsif oracle_books is null then dbms_output.put_line('oracle_books is null'); end if; if oracle_books_2 is empty then dbms_output.put_line('oracle_books_2 is empty'); else dbms_output.put_line('oracle_books_2 NOT empty'); end if; if oracle_books_3 is not empty then dbms_output.put_line ('oracle_books_3 NOT empty'); end if; end; Example 2 produces the following results: oracle_books is null oracle_books_2 is empty oracle_books_3 NOT empty

Example 3 - IS [NOT] A SET


This is used to test whether or not a given PLSQL collection has all unqie elements. If any duplicates are found or the collection is null then it is not a set. declare type book_list is table of varchar2(100); null_list book_list; empty_list book_list := book_list();

House Keeping

61997864.docFINANCIAL_YEAR

10 Page 10

Program Specification

oracle_books book_list := book_list('PLSQL New Features', 'Oracle 10g New Features','Oracle 10g Application Server'); plsql_books book_list := book_list('PLSQL New Features', 'PLSQL New Features','PLSQL New Features'); rslt VARCHAR2(4); begin if empty_list is not a set then rslt := 'NOT '; end if; dbms_output.put_line('empty_list is '||rslt||'a set'); if null_list is a set then rslt := null; else rslt := 'NOT '; end if; dbms_output.put_line('null_list is '||rslt||'a set'); if plsql_books is not a set then rslt := 'NOT '; else rslt := null; end if; dbms_output.put_line('plsql_books is '||rslt||'a set'); if oracle_books is not a set then rslt := 'NOT '; else rslt := null; end if; dbms_output.put_line('oracle_books is '||rslt||'a set'); end; Example 3 produces the following results: empty_list is a set null_list is NOT a set plsql_books is NOT a set oracle_books is a set

Oracle Database 10g: SQL and PL/SQL New Features Content Details
Using Oracle Database 10g Data Types Working with the New BINARY_FLOAT and BINARY_DOUBLE Numeric Data Types The Floating-Point Special Values Using Comparison Operations on Binary-Floats Using the FloatingPoint Literals Using the FloatingPoint Functions Using Conversion Operations on Binary-Floats Examining BinaryFloat Performance Using Regular Expressions and Linguistic Sort and Comparison Using Regular Expressions Functions, Conditions, and Meta Characters in SQL and PL/SQL Performing a Basic Search Using the REGEXP_LIKE Condition Finding Patterns Using the REGEXP_INSTR Function Extracting Sub-strings Using the REGEXP_SUBSTR Function Replacing Patterns Using the REGEXP_REPLACE Function Performing a Case-Insensitive or Accent-Insensitive Linguistic Sort Using NLS_SORT Performing a Linguistic Comparison Using the NLS_COMP

House Keeping

61997864.docFINANCIAL_YEAR

11 Page 11

Program Specification

Initialization Parameter Supporting NCHAR String Literals Using Large Objects (LOB) Enhancements Identifying the Large Objects Enhancements Migrating from LONG to LOB Using the DBMS_LOB Package Initializing, Populating, and Removing LOB Columns Selecting CLOB Values by Using SQL and DBMS_LOB Conversion Between CLOB and NCLOB Data Interface for LOBs in Abstract Data Types and Remote LOBs

The NLSSORT Function: Case Insensitive and Accent Insensitive Support Using the New PL/SQL Compiler Identifying the New Initialization Parameters for PL/SQL Compilation Using the New PL/SQL Compile Time Warnings for Subprograms Setting the Warning Messages Levels Using the PLSQL_WARNINGS initialization parameter Setting the Warning Messages Levels Using the DBMS_WARNING Package Subprograms Viewing the Current Setting of PLSQL_WARNINGS Using SQL*Plus Viewing the Current Setting of PLSQL_WARNINGS Using the Data Dictionary Views Guidelines for Using PLSQL_WARNINGS

Support for LOB Array Read and Write Using Nested Table and VARRAY Enhancements Collections: Overview Adjusting the Size of an Element Type Using the VARRAY LIMIT Size Using VARRAY Columns in Temporary Tables Changing a Nested Tables Storage Tablespace ANSI Support for Nested Tables

Introducing the Multiset Operators Using General SQL Enhancements Introducing the VERSIONS Clause

Viewing the Current Setting of PLSQL_WARNINGS Using the Data Dictionary Views Programming with PL/SQL Enhancements Using Conditional Compilation Using the Selection, Inquiry, and Error Directives Displaying the PLSQL_CCFLAGS Setting Identifying the Database Version and Release Using the DBMS_DB_VERSION Package Boolean Constants Using the DBMS_PREPROCESSOR Procedures to Print or Retrieve the PL/SQL PostProcessed Source Text Obfuscating (hiding) PL/SQL Source Code Bulk Binding: FORALL Support for Sparse Collections and Index Array

House Keeping

61997864.docFINANCIAL_YEAR

12 Page 12

Program Specification

Using the Row Versions Feature Using Flashback Query Introducing the FLASHBACK TABLE and FLASHBACK DATABASE Statements Overview of Table Functions Understanding the Enhanced ODCI Functions Using Alternative Quotes

Using the DROP TABLE PURGE statement

Maintaining Valid PL/SQL Program Units and Views Using the SQL Model Clause Learning the Concepts and Reviewing the Sample Data Using Cell and Range References Using the CV() Function Using the FOR Construct Using Analytic Functions in the SQL Model Clause Using the UPDATE, UPSERT, and UPSERT ALL Options Nested Cell References and Reference Models

Cyclic Rules in Models, Cycles, and Simultaneous Equations Using SQL Enhancements for Data Warehousing MERGE Improvements and Extensions Using Conditional Updates Cleansing Data Using the DELETE Clause Densifying Data with Partitioned Outer Joins Repeating Data Values to Fill Gaps Computing Data Values to Fill Gaps Time Series Calculations on Densified Data

Period-to-Period Comparison of One Time Level

House Keeping

61997864.docFINANCIAL_YEAR

13 Page 13

Potrebbero piacerti anche