Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
Collection Enhancements
Now collections are much morebetter in performance and functionality.
House Keeping
61997864.docFINANCIAL_YEAR
1 Page 1
Program Specification
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
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.
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
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.
^ $ .
'^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 ***.
House Keeping
61997864.docFINANCIAL_YEAR
5 Page 5
Program Specification
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
*/ end;
Example 3 produces the following results: 1 is a member of table_2 num is a member of table_2
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
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
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
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
House Keeping
61997864.docFINANCIAL_YEAR
13 Page 13