New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley,...

49

Transcript of New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley,...

Page 1: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.
Page 2: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

New SQL Capabilities in Oracle Database 10g

Geoff Lee, Principal Product Manager

Peter Linsley, PMTS

Oracle Corporation

Session id: 40088

Page 3: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Agenda

Overview New Features Demo Summary Q&A

Page 4: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Oracle8

Evolution of Oracle SQL Engine

Oracle8i Oracle9i Oracle9i R2

SQL /XML Integration

(XMLType, URIType, etc.) OLAPDatetime Types

ANSI Joins

CASE Expressions

XML DBSQL/XMLW3C StandardsData Mining

GridWeb ServicesRegular ExpressionsNative NumbersBLASTExpression Filter

Objects Extension

Data Cartridges

SQL/Java Integration

interMedia Types

Dat

a an

d P

roce

ssin

g c

om

ple

xity

Page 5: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Oracle SQL Engine Architecture

Optimizer

Query Engine

Index Engine

Type Manager

Exten

sibility

Text

Text

SpatialUtilities Tools

Image

Image

Text

Spatial

Image

Data CartridgesSpatIal

Page 6: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Agenda

Overview New Features

– Regular Expressions– Native Numbers– LOB Enhancements– Collection Enhancements

Demo Summary Q&A

Page 7: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Introduction to Pattern Matching

Pattern matching and manipulation– Match 'abc', match email address, etc

LIKE often not expressive enough Non-native and client solutions have

drawbacks

Page 8: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Introduction to Regular Expressions

Origins in mathematics First computerized in UNIX

– From ed, grep, perl, cgi, web, to everywhere

Multitude of applications– Validation in HTML FORMS – Bioinformatics– Server configuration– Datamining

Page 9: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Oracle Regular Expressions

Native support to the database– Interfaces in SQL and PL/SQL– Based on POSIX standard– Sync with GNU, PERL, Java, XQuery, etc.

Patterns describing data become a property of the data

Powerful string manipulation within the database

Page 10: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Enhanced Data Flow

Validate and Format

Filter and Format

Page 11: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Key Features

POSIX Extended Regular Expressions Interfaces

– REGEXP_LIKE does pattern match?– REGEXP_SUBSTR what does it match?– REGEXP_INSTR where does it match?– REGEXP_REPLACE replace what matched.

Match options Locale Support LOB Support

Page 12: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

. match any character

a? match 'a' zero or one time

a* match 'a' zero or more times

a+ match 'a' one or more times

a|b match either 'a' or 'b'

a{m,n} match 'a' between m and n times

[abc] match either 'a' or 'b' or 'c'

(abc) match group 'abc'

\n match nth group

[:cc:] match character class

[.ce.] match collation element

[=ec=] match equivalence class

MetacharactersOperator DescriptionOperator Description

Page 13: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

REGEXP_LIKE

Determine whether pattern exists Find variations on the name 'Jon Stevens'

– John or Jon– Steven or Stevens or Stephen or Stephens

SELECT c1 FROM t1 WHERE REGEXP_LIKE(c1, ‘Joh?n Ste(ph|v)ens?’); Jon Stevens John Stephens John Stevens

Page 14: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

REGEXP_SUBSTR

Determine what text matched Extract matching variation

SELECT REGEXP_SUBSTR( ‘I am the real Jon Stevens’, ‘Joh?n Ste(ph|v)ens?’) FROM dual; Jon Stevens

Page 15: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

REGEXP_INSTR

Find out where the match occurred Find the matching word

SELECT REGEXP_INSTR( ‘I am the real Jon Stevens’, ‘Joh?n Ste(ph|v)ens?’) FROM dual; 15

Page 16: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

REGEXP_REPLACE

Replace matching text Supports back references in replacement text Fix alternative spellings

SELECT REGEXP_REPLACE (‘I am the real John Stephens.’, ‘Joh?n Ste(ph|v)ens?’,

‘Jon Stevens’) FROM t1; I am the real Jon Stevens.

Page 17: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Using with DDL

Filter allowable data with check constraint– ZIP code column is VARCHAR2(5) but can hold

any 5 characters.

Query subset and format with views– format phone number to (xxx) xxx-xxxx

Create functional based index

Page 18: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Using with PL/SQL

Very powerful string manipulation abilitiessrc := REGEXP_REPLACE (src, ‘<regexp_1>’);src := REGEXP_REPLACE (src, ‘<regexp_2>’);

src := REGEXP_REPLACE (src, ‘<regexp_3>’);

Can enhance on existing abilities– Support PERL shorthand– Extract nth subexpression

Replace hundreds of lines of code– String manipulation functions can be simplified

Page 19: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Performance Considerations

Pattern matching can be complex– Need to compile to state machine– Lex and parse– Examine all possible branches until match found

Compiled once per statement– Can be faster than LIKE for complex scenarios– Usually faster than PL/SQL equivalent

ZIP code checking 5 times faster

Write fast performing expressions.

Page 20: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Agenda

Overview New Features

– Regular Expressions– Native Numbers– LOB Enhancements– Collection Enhancements

Demo Summary Q&A

Page 21: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Native Floating-Point Data Types

Two new numeric data types BINARY_FLOAT, BINARY_DOUBLE

– IEEE 754 Standard for binary floating point arithmetic

– Part of numerous other standards (e.g, Java, XML Schema) and hardware platforms

– Prevalent in Business Intelligence, Life Sciences, Engineering/Scientific Computation, etc.

Page 22: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Native Floating-Point Data Types vs. Number Data Type

More efficient than the NUMBER type– Hardware arithmetic/math are 5 – 10 times faster– Take up less space in memory/disk (5/9 vs. 1 –

22 Bytes each)– BINARY_DOUBLE has wider value range (e308

vs. e125)– No type convesion (use a byte-order neutral

storage format)

Page 23: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Native Floating-Point Functions

New type conversion functions– TO_BINARY_FLOAT, TO_BINARY_DOUBLE– TO_NUMBER

SQL function support– Numberic functions (sin, cos, etc.)– Aggregate functions (sum, avg, stddev, etc.)– Analytic functions (sum, avg, stddev, etc.)

Seamless support in SQL, PL/SQL, Java, XML Schema registration, ODP.NET and OCI/OCCI

Page 24: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Native Floating Point Constraints

create table floating_point_table1 (fltNnull binary_float constraint flt_null not null,dblNnull binary_double constraint dbl_null not null,fltUnq binary_float constraint flt_unq unique,dblUnq binary_double constraint dbl_unq unique,fltChk binary_float constraint

flt_chk check ( fltChk is not NaN ) ,dblChk binary_double constraint

dbl_chk check ( dblChk is not infinite) ,

fltPrm binary_float constraint flt_prm primary key);

* NaN (Not a Number) – e.g. 0/0, infinity/infinity

Page 25: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Native Floating Point Constraints

create table floating_point_table2 (dblPrm binary_double constraint

dbl_prm primary key,fltFrn binary_float constraint flt_frn references

floating_point_table1(fltPrm) on delete cascade);

Page 26: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Agenda

Overview New Features

– Regular Expressions– Native Numbers– LOB Enhancements– Collection Enhancements

Demo Summary Q&A

Page 27: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

LOB Enhancements LOBs are prevalent in storing

unstructured data (text, AVI, genomic/proteomic sequences, etc.)

Implicit charset conversion Between CLOB and NCLOB

Page 28: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

LOB Performance Improvements

5x performance gain for accessing inline (< 4KB) LOBs

Temporary LOBs uses reference counting to provide orders of magnitude performance gain

– Reference on Read– Copy on Write

Page 29: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Ultra-Sized LOBs

Terabyte (8 – 128 TB) sized Lobs– DB_BLOCK_SIZE (2 – 32 KB) x (4GB –1)– New DBMS_LOB.GET_STORAGE_LIMIT

function– OCI, JDBC, and DBMS_LOB now

supports LOBs greater than 4GB OCILobRead2(), OCIWriteAppend2(), and

OCILobWrite2() functions Same APIs for JDBC and DBMS_LOB

Page 30: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Data Interface for Persistent LOBs

Client DML (insert/update) can bind char buffers (up to 4GB) to LOB values without the locator

– OCI, JDBC, and ODP.NET support– Up to 32KB with PL/SQL

No server round-trip to get the locator before insert/update

Page 31: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Datetime Enhancements The best implementation of ANSI SQL

timestamp with (local) time zone– Expanded region time zone names support

Default: $ORACLE_HOME/oracore/zoneinfo/timezone.dat (146 KB)

Larger set: ORACLE_HOME/oracore/zoneinfo/timezlrg.dat (380 KB)

– ORA_TZFILE specifies the file used by the database

– Loaded into SGA during instance startup– Valid region names are listed in

v$timezone_names

Page 32: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Agenda

Overview New Features

– Regular Expressions– Native Numbers– LOB Enhancements– Collection Enhancements

Demo Summary Q&A

Page 33: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Collection Types Enhancements User-defined types, collection types,

and Ref type simplify complex-structured data modeling

Collections types are used for mapping containment relationships in real world applications

– For example, a shopping cart contains a number of items

Page 34: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

VARRAY Enhancements Type evolution of VARRAYs

CREATE TYPE email_list_typ AS OBJECT ( section_no NUMBER, emails email_list_arr);/CREATE TYPE email_varray_typ AS VARRAY(5) OF

email_list_typ;/ALTER TYPE email_varray_typ MODIFY LIMIT 100

CASCADE;

Support VARRAY columns in temporary tables– Provides application development flexibility

Page 35: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Nested Table Enhancements

Use a different tablespace for a Nested Table’s storage table

– Tables with Nested Table columns can distribute I/O load among tablespaces

CREATE TABLE purchase_orders ( order_items_column order_items_typ )NESTED TABLE order_items_columnSTORE AS order_items_column_nt (TABLESPACE

users);

Page 36: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

ANSI SQL Multiset Operations for Nested Tables A Nested Table stores unordered

elements– A set contains only unique

elements– A multiset can contain duplicate

elements

Full range of Multiset operations on Nested Tables

Page 37: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Multiset Operations for Nested Tables Cardinality, Collect, Multiset Except, Multiset

Intersection, Multiset Union, Powermultiset, Powermultiset_by_Cardinality, and Set operations

– Powerful tools to find frequent item sets (market basket analysis)

Page 38: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Multiset Operation Examplecreate type categories as table of int;/ create table carts (c1 int, c2 categories)

nested table c2 store as tb1_c2; insert into carts values(1, categories(1,2,3,4));insert into carts values(2, categories(2,4,6)); select t1.c2 multiset intersect t2.c2 from carts

t1, carts t2 where t1.c1=1 and t2.c1=2;

categories(2,4) <- frequent set

Page 39: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Comparisons of Nested Tables

Equal and Not Equal, In, Submultiset, Member Of, Empty, and Is [Not] A Set

SELECT * FROM customer cWHERE item_typ(2) MEMBER OF c.freq_set;

Page 40: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Agenda

Overview New Features Demo Summary Q&A

Page 41: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

D E M O N S T R A T I O N

SQL for Data Grids

Page 42: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Aggregated Information

Web Service

JDBC/JXQISOAP

XQuery EngineAggregated Information

EISOracle SQL

Engine

HTTP/SOAP

J2EETM CA

Streams

HeterogeneousServices

Page 43: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

XQuery FLWOR Expressions A FLWOR (flower) expression binds some

expressions, applies a predicate, and constructs a new result.

FOR var IN expr

LET var := expr WHERE expr

RETURN expr

FOR and LET clauses generate a list of tuples of bound expressions

WHERE clause applies a predicate, eliminating some of the tuples

RETURN clause is executed for each surviving tuple, generating a list of outputs

ORDER BY expr

Page 44: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Agenda

Overview New Features Demo Summary Q&A

Page 45: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Summary

Oracle Database 10g SQL engine – Data Grid information aggregation from diverse

and distributed data sources– Seamless integration with Java, XML, and

essential data processing capabilities– A comprehensive set of high-performance and

standards-based (SQL-2003, W3C, J2SE, POSIX, etc.) features

– Simplified application development, deployment, and management

– RAS, manageability, and security

Page 46: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Next Steps….

Relevant web sites to visit for more information– http://otn.oracle.com/products/database/

application_development/– OTN SQL/PL-SQL discussion forum– http://otn.oracle.com/tech/xml/xmldb/htdocs

/xquery.html

Page 47: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

Reminder – please complete the OracleWorld online session survey

Thank you.

Page 48: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.

AQ&Q U E S T I O N SQ U E S T I O N S

A N S W E R SA N S W E R S

Page 49: New SQL Capabilities in Oracle Database 10 g Geoff Lee, Principal Product Manager Peter Linsley, PMTS Oracle Corporation Session id: 40088.