SlideShare une entreprise Scribd logo
1  sur  114
Lucas Jellema, AMIS
ABSOLUTELY TYPICAL -
THE WHOLE STORY ON TYPES AND HOW
THEY POWER PL/SQL INTEROPERABILITY



On Types and Objects, Collections and OO
UKOUG, December 2011, Birmingham, UK
OVERVIEW

•   History of Types
•   Areas of use
•   Type
•   True OO
•   Collections [of Types]
•   Table and Multiset
•   Interaction with the outside world
     – XML, JSON
     – Web Services
STANDARD TYPES IN ORACLE DATABASE

• Standard as in „installed out of the box‟
   – Number, Char, Date
   – Varchar2
   – RAW, LONG
   – SDO_GEOMETRY, …
   – BLOB, CLOB, TIMESTAMP, INTERVAL
   – XMLType
   – DICOM (Medical Records)
THE DATABASE SUFFIX

• 12c
• 11g
• 10g
• 9i
• 8i
• 8.0
   – That is 8.o (as in oh, not as in zero!)
                   o
• And: 8 really is o
                   o
• OO in Oracle turned out to mean
   – Define user defined types to use as SQL and PL/SQL
      data structure programming constructs
       • that have some OO characteristics as well
       • that can be used to define table columns for
AREAS OF USE FOR TYPES

• Structured programming in PL/SQL
• Interaction SQL and PL/SQL
   – Elegant, performing, organized
• Interaction with the outside world
   – Java, SOA Suite, other consumers
• OO-like storage of nested type structures
• Do OO design and application development
EXAMPLE OF TYPE DEFINITION

• Types are manipulated through             Type as Object
  DDL statements:
   – CREATE OR REPLACE TYPE                   PERSON_T




   – Object Types have properties (attributes)
   – Object Types are similar to PL/SQL records
   – Object Types live in Data Dictionary as primary
     database objects
INSTANTIATING AN OBJECT

• A variable based on a type (as object) needs to be
  instantiated before it can be assigned or read




• An instance of a type == an object
FUNCTION ACTING ON TYPE
CALLING FUNCTION WITH TYPE
PARAMETER FROM SQL
• Types can be instantiated from within SQL statements
  and passed to PL/SQL functions




   – SQL*Plus and other tools typically know how to render
     types in query results
SELECT OBJECT TYPE FROM SQL
SCALAR SUBQUERY

           • Inline query that returns a single result
              – One row, one column
select ename            Employees with their job and sal and the
,      job                   number of staff they manage
,      sal
,      (select count(empno) from emp s where s.mgr= e1.empno)
from emp e1


select   ename           Employees who earn between the average
,        sal                 salary for salesmen and analysts

from     emp
where    sal between
             (select avg(sal) from emp where job = 'SALESMAN')
             and
             (select avg(sal) from emp where job = 'ANALYST')
WORKAROUND TO RETRIEVE MULTIPLE
             VALUES: CONCATENATION OF VALUES
select ename
,       job
,       sal
,       substr(sal_aggs, 1, instr(sal_aggs,'x') -1)
                                     avg_sal_in_job
,       substr(sal_aggs, instr(sal_aggs,'x') +1)
                                  max_sal_in_job
from    ( select ename
             ,      job
             ,     sal
             ,     ( select avg(sal)||'x'||max(sal)
                      from   emp
                      where job = e1.job
                    ) sal_aggs
             from emp e1
        )
order   by        job, sal desc
MUCH BETTER WORK AROUND: ADT
select ename
                                                 create type
,       job
                                                 multivalue_return_type
,       sal
                                                 as object
,       emps.sal_aggs.value1 avg_sal_in_job
                                                 ( value1 number(20)
,       emps.sal_aggs.value2 max_sal_in_job
                                                 , value2 number(20)
from    ( select ename
                                                 , value3 number(20)
             ,     job
                                                 )
             ,     sal

             ,     ( select multivalue_return_type
                             ( avg(sal), max(sal), null)
                      from   emp
                      where job = e1.job
                   ) sal_aggs
             from emp e1
        ) emps
order   by       job, sal desc
TYPES AND THE DBA

• Before Oracle Database 11g – altering type definitions
  was not easy
   – Drop, Alter or Replace of a Type could only be done if no
     references existed to the type from other types or tables
   – That usually meant all types associated with an
     application were dropped and recreated – to alter one!




• Starting in 11g the DROP and REPLACE/ALTER TYPE
  operations can specify FORCE to ignore dependencies
   – Helps to overcome frowning, type-averse DBAs!
• Note: Data Dictionary Views are available to tell on types
• Types are editionable objects in terms of 11gR2 Edition
  Based Redefinition and can evolve gracefully
COMPLEX TYPES

• Attribute of a Type (as Object) can be based on an ADT
  aka UDT: Object or Collection
   – Limitation: Self-reference is not allowed


      Type as Object
                                     Type as Object
        PERSON_T
                                   SOCIAL_PROFILE_T
SOCIAL PROFILES STORED IN TABLES

• Two options for storing social profiles:
   – The normal, explicit
     relational way:




   – The nested table
     approach:
INSTANTIATING NESTED OBJECT IN SQL

• Instantiate „look up object‟ using Scalar Subquery




• Instantiate „look up object‟ from (outer) joined columns
COLLECTIONS IN ORACLE

• Oracle supports in-memory collections of type
  instances
   – Can be of standard type (number, varchar2, date,…) or
     complex User Defined Type (aka ADT)
• Three kinds of collections
   – Associative Array (PL/SQL only) – {key,value} pairs,
     very similar to Map in Java and Hashtable in C#
   – VARRAY (the variable array of fixed size)
   – Nested Table
• These collections are similar, yet quite distinct
   – Definition and instantiation
   – Similar operations (count, first, next, delete, …)
   – Sparse vs. Dense
   – SQL Interaction support
CREATING AND WORKING WITH AN
ASSOCIATIVE ARRAY (PL/SQL ONLY)
CREATING AND WORKING WITH A
NESTED TABLE
COLLECTION OPERATIONS

•   Exists – to check if element with/at index exists
•   Extend (only for Nested Table)
•   Count
•   First
•   Last
•   Next
•   Prior
•   Delete
•   Trim
COMPLEX TYPES

   Type as Object
                             Type as Object
     PERSON_T
                           SOCIAL_PROFILE_T




                       Type as Table
                    of email_address_t

                    EMAIL_ADDRESS_TBL

                             Type as Object

                           EMAIL_ADDRESS_T
CONSTRUCTING A COMPLEX OBJECT
IN PL/SQL
CONSTRUCTING A COMPLEX OBJECT
IN PL/SQL
TRUE OO: SUBTYPES AND INHERITANCE

• Types can be created as subtypes of another Type
• A subtype has multiple identities:
   – EMPLOYEE_T is both PERSON_T and EMPLOYEE_T
   – Anything that can handle a PERSON_T can also
     handle an EMPLOYEE_T and a CUSTOMER_T


                              Type as Object

                                 PERSON_T



                Type as Object                 Type as Object

                 EMPLOYEE_T                    CUSTOMER_T
CREATION OF TYPE HIERARCHY




Type as Object

EMPLOYEE_T
CREATE INSTANCES OF SUBTYPE IN
PL/SQL
OO OPERATORS IN TYPE HIERARCHY

• TREAT (AS type) – downcast an instance to a specific
  subtype – to access specialized subtype aspects
• IS OF ( [ONLY] type) – to identify type of an instance
MEMBER FUNCTIONS

• A type can have operations
   – Specification and Implementation (in the Body)
   – Acting on the members – public and private – of the
      object
   – Possibly overriding methods of the super-type
• Two types of operations
   – Constructor                     Type PERSON_T as
   – Normal member functions               Object
                                     <public methods>

                                         Type Body
                                         PERSON_T
                                     <implementation
                                       of private and
                                     public methods>
CONSTRUCTOR FUNCTIONS

• A type is instantiated through a call to one of its
  constructor methods
• A type can have multiple, overloaded user defined
  constructor functions
   – In addition to the
      default system
      defined
      constructor that
      simply expects
      input for every
      public member
MULTIPLE USER DEFINED CONSTRUCTORS
MEMBER FUNCTIONS

• Types can have member functions – similar to
  functions in a package
   – Just like package can act on package state (globals),
     member functions act on object (type instance)
MEMBER FUNCTION DISPLAY_LABEL
OVERRIDING MEMBER FUNCTIONS

  • Sub types can override member functions from super
     – When the function is invoked on a PERSON_T and
       PERSON_T happens to be a CUSTOMER_T, then the
       function as defined on CUSTOMER_T is executed
     – Overriding subtype member function can invoke the
       overridden super typer function

                      Type PERSON_T as Object




Type EMPLOYEE_T as Object             Type CUSTOMER_T as Object
EXAMPLE OF OVERRIDING MEMBER
FUNCTION
              Type PERSON_T as Object




                        Type CUSTOMER_T as Object
MAP AND ORDER MEMBER FUNCTION
SORTING COLLECTIONS
• Map Member Function translates an object to a scalar
  data type that Oracle knows how to compare and sort
   – Varchar2, Number, Date or even an UDT with scalar
     attributes (or a Map function of its own)




• Note: Map member function is also used for equality
  comparison
   – In this case John Doe and Bill Doe are seen as equal!
MAP MEMBER FUNCTION IN ACTION -
SORTING IN SQL
• Map function dictates:
   – Women come first, then sort by birth date (young
     before old)
ORDER MEMBER FUNCTION USED TO
ORDER BY IN SQL
• Order member function to compare objects
   – returns -1 when self comes before other (when sorted),
     1 when self comes after and 0 when they draw
ORDER MEMBER FUNCTION IN ACTION
USER DEFINED AGGREGATION FUNCTIONS
IN SQL
  select avg(hiredate) from emp

    ORA-00932: inconsistent datatypes:
         expected NUMBER got DATE


• The Oracle Data Cartridge offers User Extensibility
  framework for the database
• Data Cartridge provides:
   – user defined aggregate functions
   – domain indexes and functions
       • used for Oracle Text and Oracle Spatial
   – Pipelined Table Functions – the interface approach
       • Dynamic handling of AnyData objects
IMPLEMENTING USER DEFINED
AGGREGATE
• Implement an object with the following operations:
   – ODCIAggregateInitialize
   – ODCIAggregateIterate
   – ODCIAggregateTerminate
   – ODCIAggregateMerge
       • Optional, to enable parallelism

    create type DateAvgImpl
    as object
     ( count number
     , sumdates NUMBER
     , function ODCIAggregateInitialize
     , function ODCIAggregateIterate
     , function ODCIAggregateTerminate
     , function ODCIAggregateMerge
     )
IMPLEMENTING USER DEFINED
AGGREGATE
• Register new aggregate function implemented by
  the object
   function dateavg (input date)
      return date
   PARALLEL_ENABLE
   AGGREGATE USING DATEAVGIMPL

• Use the new function in queries
   select DateAvg(hiredate) from emp

• “Analytic Function Friendly”
FUNCTION CHAINING

• Dot notation (navigation) is used to call a function on
  the result of a function (on the result…)
   – if the result of the nested functions are types
BULK COLLECT TO PREVENT MULTIPLE
ROW-BY-ROW PL/SQL TO SQL ACCESS
• Traditional cursor based approaches for fetching data
  from the database using SQL resulted in
   – Unnecessary SQL/PLSQL context switches
• By fetching multiple rows at once – the number of
  (expensive) switches can be reduced
• Several approaches exist – all rely on Collections
   – Bulk Collect
   – Select Collection
• Note: as of Oracle 10g the „normal‟ cursor-for-loop
  also implicitly does fetching in bulk
BULK COLLECT EXAMPLE
CREATE A COLLECTION IN SQL – COLLECT
OPERATOR
• COLLECT is an aggregation function (like MAX, SUM,
  COUNT) that aggregates into nested tables
   – Group by can be used to create ‘clusters’
SELECT COLLECT INTO PL/SQL VARIABLE
MULTISET TURNING A (SUB) QUERY RESULT
SET ON THE FLY INTO A NESTED TABLE
• MULTISET can be used inside SQL Queries to convert
  a query result set into a collection (nested table)
   – On the fly (in the middle of a query)
MULTISET EXAMPLE
MULTISET OPERATORS ACTING ON NESTED
TABLES IN SQL AND/OR PL/SQL
• C1 = C2
   – Comparison based on named type, cardinality and
     comparison of individual elements
• C1 <> C2 or C1 != C2
   – Inverse of equality test
• C1 IN C2 returns true if C1 is one of the collections in
  C2 which is a collection of collections
• POWERMULTISET C1 generates all non-empty sub-
  multisets from collection C1
   – All possible combinations created from the elements in
     C1, produced as collections of the same type as C1
• C1 IS EMPTY returns true if C1 is empty
• CARDINALITY C1 returns the number of elements in
  C1
MULTISET OPERATORS ACTING ON NESTED
TABLES IN SQL AND PL/SQL
• C1 SUBMULTISET C2 evaluates to true when the
  members of C1 are all found in C2
• X MEMBER OF C1 evaluates to true when X is found
  as a member of collection C1
• C1 MULTISET UNION [DISTINCT] C2 – combining two
  collections
   – Use DISTINCT to eliminate duplicate elements
• C1 MULTISET INTERSECT [DISTINCT] C2 – produces
  collection of elements that occur in both C1 and C2
• C1 MULTISET EXCEPT [DISTINCT] C2 – produces the
  collection of elements that appear in C1 and not in C2
   – Use ALL to allow (reduced number of )duplicates
• C1 IS A SET – tests if the collection C1 only has
  unique members (no duplicates)
COULD BE ANYTHING

• The Any… Types are like generic placeholders for data
  that is only known at run time
   – The contents of Any… instances is accessible through
     introspection


• AnyData – some thing, could be any thing (Object)
• AnyType – holds the definition of some thing
       • Like AnyData without the data – only meta data
• AnySet – some collection of things (all of the same
  type)
   – can be used for interface parameters to communicate
     self-descriptive sets of data
   – Used in Pipelined Table Functions created through
     Data Cartridge to return dynamically determined data
     structures
CREATING AND PROCESSING
A TABLE OF THINGS – STEP 1
CREATING AND PROCESSING
A TABLE OF THINGS – STEP 2
Process collection as query result
TABLE
TABLE FUNCTIONS

• In queries: select from collections as if they were a
  table using the TABLE operator
JUST BECAUSE WE CAN - POINTLESS
COMBINATION OF COLLECT AND TABLE
SORTING COLLECTIONS
LEVERAGE SQL TO DO THE ORDER BY




                 Build up collection of people
                 in variable l_people
EXTREME ENCAPSULATION

• View on top of table(collection)
   – With instead of trigger handling DML




   – Data queried from NUMBERS is produced in PL/SQL –
     no underlying table involved
   – Data manipulated in NUMBERS is processed in
     memory
EXTREME ENCAPSULATION
FOR GENERATING ROWS FOR SPECIAL
     DOMAINS OF ALLOWABLE VALUES
     • Have TABLE operate on an in-line created collection
with countries as
( select column_value country
   from    table(
                   string_table('Belgium','France'
                                ,'Egypt','Italy'
                                )
     • To save)on repeated
)         – select value from dual UNION ALL select   value …
select country
from    countries




with gender_values as
( select column_value gender
   from    table( string_table('MALE', 'FEMALE',‘UNKNOWN' ))
)
select gender
from    gender_values
PIPING ROWS USING COLLECTIONS AND
THE „TABLE FUNCTION‟
• A Table Function normally returns the entire collection
  at once
• However: it can also return collection elements one at
  a time
    – That is called PIPELINED
• As soon as the function pipes a single element,
  processing that element can continue
• It‟s bit like the
  /*+ FIRST_ROWS */ Hint
THE SLOW ALPHABET…
create or replace
function alphabet
return letter_table
is
  l_alphabet letter_table:= letter_table();
begin
  l_alphabet.extend(26);
  for i in 1..26 loop
    l_alphabet(i):= chr(64+i);
    dbms_lock.sleep(0.1);
  end loop;
  return l_alphabet;
end alphabet;




Note: it is not just 2.79 seconds for all rows to appear:
it takes that long for any row to appear
THE PIPELINED SLOW ALPHABET…
create or replace
function alphabet return letter_table
pipelined
is
  l_alphabet letter_table:= letter_table();
begin
  l_alphabet.extend(26);
  for i in 1..26 loop
    l_alphabet(i):= chr(64+i);
    dbms_lock.sleep(0.1);
    pipe row (l_alphabet(i));
  end loop;
  return;
end alphabet;




Note: total processing time is just as long as before;
however, the first row appears after less than 0.5 sec!
MORE PERFORMANCE REQUIRES
PARALLEL
MORE PERFORMANCE REQUIRES
PARALLEL
DO NOT DO IT…
ON YOUR OWN
• Parallel means: multiple resources contributing to a
  task at the same time

• Introduce parallellism into your database application
   – parallel query and DML
   – coordinated jobs (dbms_job, dbms_scheduler)
   – 11g: dbms_parallel_execute
   – Pipelined & Parallel table functions
PANCAKE PARTY
BETTER PERFORMING PANCAKE
PARTY
PIPELINED PANCAKE PARTY: BEST
PERFORMANCE
PIPELINED PANCAKE PARTY

• Parallel Pipelined: multiple different resources working
  on different components of the task in [potentially]
  different tiers
   – From batch processing to unit processing => pass the
      unit on for further processing as soon as part of the
      task is done – to leverage resources (across tiers) in
      parallel
• Instead of baking the entire stack first and only then
  eating it…
   – … start eating as soon as the first one is done
   – Even the last guest ends earlier than without pipelining
      provided he eats more than one pancake
       • (he eats his first pancake when it is done, not when the
         stack is done)
   – The first eater is done much sooner
       • first rows/all rows ≈ first pancake/all pancakes
PANCAKE PARTY IN PL/SQL
PANCAKE PARTY IN PL/SQL
PANCAKE PARTY PIPELINED IN PL/SQL
PIPELINED PANCAKE BA-EAT-KING
INTRODUCING XML

• Structured ASCII
• Esperanto
• Cross technology – interoperability
• Tools & frameworks for common operations
   – Parsing, validation, construction, transformation and
     querying
• Standards:
   – XSD – design and contract
   – XPath - querying
   – XSLT - transformation
   – XQuery – querying and manipulation
WHAT IS XML?

 eXtensible Markup Language – for exchange of data
 Plain text / ASCII files
 Structured messages
    Human readable
    More important: machine interpreted
 Meaning defined with tags
    Elements and attributes
  <?xml version="1.0" encoding="UTF-8"?>
   <root element>
     <element1 attributeName="value">
         content</element1>
     <element2 attributeName="value" />
     <element3>
       <element4>content</element4>
     </element3>
   </root element>
TYPE TO HOLD XML DATA IN ORACLE




         XMLType
CONSTRUCTING XML IN DATABASE
APPLICATIONS
• Many ways to produce XML content in Oracle
   – XMLType – from text, types, cursor, bfile contents, …
   – SQL/XML (XMLAgg, XMLElement, XMLForest, …)
   – DBMS_XMLGEN
   – SYS_XMLGEN and SYS_XMLAGG
   – DBURIType and XDBURIType
   – XML SQL Utility (XSU) – command line, Java, PL/SQL
   – fn:doc and fn:collection (replacing ora:view)




                               XMLType
CONVERTING TYPE STRUCTURE TO
XMLTYPE
• XMLType can be instantiated based on a single
  complex User Defined Type instance
   – Not (directly) on a nested table
CONVERTING NESTED TABLE TO XMLTYPE
CONVERT XMLTYPE TO NESTED USER
DEFINED TYPE
• XMLType supports conversion directly in a –
  potentially nested – user defined type
   – Provided element names match names of type,
     subtypes and attributes
XML CAN BE SOMEWHAT HEAVY

• Size of XML documents compared to the actual data
  content of those documents is „XXL‟
• Complex nested structure that requires parsing
• Turning XML into native data structures and vice versa
  is expensive (Marshalling/Unmarshalling )
• XML Programming facilities not available on all
  platforms and in all languages
   – Objective C, JavaScript, …


• The search for alternatives
  is on: structured, contract,
  standardized, facilities,
  lighter weight!
JavaScript Object Notation
Lightweight data-interchange format
Name : Value
Name : Value,
Name : Value,
Name : Value
,                   ,
Name : Value,       Name : Value,       Name : Value,
Name : Value,       Name : Value,       Name : Value,
Name : Value        Name : Value        Name : Value
{"ACCOUNTING" : {
    "EMPLOYEES" : [
    {"ENAME" : "KING",
      "JOB" : "PRESIDENT",
      "SAL" : 5000
    },
    {"ENAME" : "MILLER",
      "JOB" : "CLERK",
      "SAL" : 1300
    }]
  }
}
<department name="ACCOUNTING">
  <employees>
    <employee>
      <ename>KING</ename>
      <job>PRESIDENT</job>
      <sal>5000</sal>
    </employee>
    <employee>
      <ename>MILLER</ename>
      <job>CLERK</job>
      <sal>1300</sal>
    </employee>
  </employees>
</department>
PL/JSON EXAMPLE – CREATING AND
QUERYING JSON
MANIPULATION OF JSON OBJECT
FROM TYPES TO XML TO JSON
FROM JSON TO XML TO TYPES
PUBLISH PACKAGE AS HTTP-BASED API
USING DBMS_EPG
                                                       http
• Hide database protocol
   – Not its physical location nor
      the schema, and user authentication
• HTTP communication is truly cross technology
   – Browser, Java, .Net, JavaScript & RIA clients, …
• Is also possibly remote, across networks, firewalls etc.
   – easier than normal JDBC connections
• Can publish in various formats
   – Text, HTML, CSV, JSON, XML, RSS
• Use case:cross-technology, internal no WS*/ESB
SIMPLE DBMS_EPG EXAMPLE
                            sys




            scott


                    scott
RESTFUL WEBSERVICES

• Simple, stateless, light weight, http-based message
  exchange protocol
   – Use standard get, put, post, delete operations
   – Use URL to pass resource reference
• Small, easy-to-understand messages
• Typically XML or JSON based
• Not using SOAP, or the WS*-stack
• Often used directly from User Interface – (AJAX
  enabled) JavaScript
RESTFUL ARCHITECTURE




           RESTful PL/SQL API
       exposed through dbms_epg
RESTFUL RESOURCE NAVIGATION
PUBLISH REST-FUL HTTP API –
DIRECTLY ON TOP OF THE RDBMS
PUBLISH REST-FUL HTTP API –
DIRECTLY ON TOP OF THE RDBMS
JSON RESPONSE – WROUGHT FROM
TYPES AND COLLECTIONS
TURNING ANY OBJECT INTO JSON
CONSUMING REST-FUL SERVICES

• Invoking a REST-ful service is simply making an HTTP
  request to some URL
• Can be done through:
   – utl_http
   – httpuritype
   – Stored Java
• Result can be processed
  as just a string or
  as XML, JSON
  or other format
   – Libraries (PL/JSON) can help with special formats
SOAP WEB SERVICES

• All messages (input and output) are XML
• The message consists of two parts inside an envelope
  (a SOAP XML wrapper)
   – The header with meta-data
   – The body with the contents to be handled by or
      returned by the service
• The WebService Definition Language (WSDL)
  document describes the service
• An XML Schema Document (XSD) describes the
  structure of the XML messages
   – XSD is like an ERD or Table Design
ORACLE RDBMS 11G –
NATIVE DATABASE WEB SERVICES
• Database Schema can be published                        WS/SOAP
  through native database web services
   – Each package corresponds with a WSDL
      • With an operation for each Procedure or Function
      • Auto-mapping from PL/SQL input and output parameters
        to WSDL (XSD) Types
   – WSDL and XSD are dynamically generated
   – A generic Query Service (across schema) is exposed
      • To execute user defined queries
      • With support for pagination and some formatting

            – http and https is supported
            – Limited control over WSDL & XSD
        – Use case: internal, cross technology, WS enabled
          client, no ESB or Application Server available
STUFF INC

• Challenge: publish SOAP Web Services to expose data
  services based on an Oracle Database
   – Read data and Manipulate data
• Use as decoupled an approach
  as possible
   – Java developers do not
     touch SQL or PL/SQL
   – Database developers are not
     aware of web service context



•   See white paper on OTN
    http://www.oracle.com/technetwork/articles/soa/jellema-esb-pattern-
    1385306.html for details
XML
                                                                  Relational/Oracle Type

                           JEE Server                                                                 Database

                                                                                           Native DB
                                                                                           WebService
                                                              HTTP
                     http                                                               EPG
                                    ADF BC                                                          JSON/ CSV
                     SDO           /SDO WS                                                             XML          PL/SQL
                                                                                                    XML & XSD
 SOA                 WS
                                  JAX-WS
                                                                                                                   package
                                                                                                    Ref Cursor
 Suite                              JPublisher
                     DB                                                                             Types & Coll
                                       WS                     JDBC                      XML
                                                                                   AQ   Types
          Adapters




                     AQ
                                  JMS Queue                                  JMS
                                                                                    utl_file,                View
                     JMS
                                                                                     BFILE,
Oracle               EJB
                                  EJB/JPA                                           URITYPE
Service                                 Pojo                 Other                                                   Table
                                                         (Email, FTP/File,                    XML
  Bus                File
                                                           XMPP/Chat)                          DB
                      FTP           UMS

                                                       Chat/IM XMPP
                                                           Server
                                                                  File/FTP Server
                                                 Email Server
PL/SQL MUSIC API EXPRESSED IN
TYPES AND COLLECTIONS


  Type




         Package
FOR JAVA DEVELOPERS BENEFIT:
SOAP WebService   WRAP TYPE IN XMLTYPE




                                    Java Class       Java Class
                   JAX-WS ESB Architecture pattern:
                          The




                                                                  XMLType
                                                    Oracle JDBC




                                                                   Type
                                                                            Package
                                    Mediator
                                     Decouple        XMLType
                  Java Class
                                                     exchange
                      Validate, Enrich, Transform, Route, …
TO ACCOMMODATE FRAMEWORKS
SOAP WebService   THAT DO NOT UNDERSTAND XMLTYPE




                               Java Class    Java Class
                   JAX-WS
                                            Oracle JDBC




                                                                   XMLType
                                                          String




                                                                    Type
                                                                    CLOB
                               Mediator      XMLType                         Package
                  Java Class                              JDBC
                                             exchange
USING THE OSB OR SOA SUITE DATABASE
                          ADAPTER – USER DEFINED TYPES ARE FINE
                          • Database adapter interacting with Type based PL/SQL
                            API
                             – Derives XSD from input and output parameters
                             – Allows for perfect decoupling between PL/SQL on one
                               side of the fence and Web Service/XML on the other

                         Validate   Enrich    Transform Route & Operate
       SOAP WebService




                                                                           User
XML
                                    Proxy Service                         Defined
                                                             Business




                                                                                    Type
                                                                           Type            Package
HTTP                                                          Service
SOAP                                                                       JDBC
                                                              Database
                                                              Adapter
JUKEBOX SERVICE - COMPLETE




                         Validate   Enrich    Transform Route & Operate
       SOAP WebService




                                                                           User
XML
                                    Proxy Service                         Defined
                                                             Business




                                                                                    Type
                                                                           Type            Package
HTTP                                                          Service
SOAP                                                                       JDBC
                                                              Database
                                                              Adapter
SUMMARY

• Long live types!
• Structured programming in PL/SQL
   – Multiple input and output parameters, step by step
      result constructions
• Integration between SQL and PL/SQL
   – Scalar Subquery, Bulk Collect and Collect Aggregator
   – Table and Multiset operators
   – Pipelined Table Functions
• Integrating with the external world
   – Type turning XML and/or JSON
   – Native Database Web Services
   – Database Adapter in SOA Suite and Service Bus

Contenu connexe

Tendances

Beyond SQL - Comparing SQL to TypeQL
Beyond SQL - Comparing SQL to TypeQLBeyond SQL - Comparing SQL to TypeQL
Beyond SQL - Comparing SQL to TypeQLVaticle
 
Coding for Scale and Sanity
Coding for Scale and SanityCoding for Scale and Sanity
Coding for Scale and SanityJimKellerES
 
Object.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesObject.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesRobert Lujo
 
CSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+ReflectionCSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+ReflectionMohammad Shaker
 
STC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSTC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSarah Kiniry
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascripttonyh1
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To HibernateAmit Himani
 
Oop in-php
Oop in-phpOop in-php
Oop in-phpRajesh S
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperNyros Technologies
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmersAlexander Varwijk
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc csKALAISELVI P
 
Dependency Injection in Spring
Dependency Injection in SpringDependency Injection in Spring
Dependency Injection in SpringASG
 

Tendances (20)

OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
Beyond SQL - Comparing SQL to TypeQL
Beyond SQL - Comparing SQL to TypeQLBeyond SQL - Comparing SQL to TypeQL
Beyond SQL - Comparing SQL to TypeQL
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
Coding for Scale and Sanity
Coding for Scale and SanityCoding for Scale and Sanity
Coding for Scale and Sanity
 
Object.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesObject.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examples
 
CSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+ReflectionCSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+Reflection
 
STC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSTC 2016 Programming Language Storytime
STC 2016 Programming Language Storytime
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 
Design Patterns and Usage
Design Patterns and UsageDesign Patterns and Usage
Design Patterns and Usage
 
Lab 4
Lab 4Lab 4
Lab 4
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To Hibernate
 
Oop in-php
Oop in-phpOop in-php
Oop in-php
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros Developer
 
Building a SQL Database that Works
Building a SQL Database that WorksBuilding a SQL Database that Works
Building a SQL Database that Works
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
 
Dependency Injection in Spring
Dependency Injection in SpringDependency Injection in Spring
Dependency Injection in Spring
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 

Similaire à Absolutely Typical - The whole story on Types and how they power PL/SQL Interoperability (UKOUG, 2011)

Oracle Objects And Transactions
Oracle Objects And TransactionsOracle Objects And Transactions
Oracle Objects And Transactionstepsum
 
Adv DB - Full Handout.pdf
Adv DB - Full Handout.pdfAdv DB - Full Handout.pdf
Adv DB - Full Handout.pdf3BRBoruMedia
 
Advance database system(part 4)
Advance database system(part 4)Advance database system(part 4)
Advance database system(part 4)Abdullah Khosa
 
27f157al5enhanceder diagram-111005002740-phpapp02
27f157al5enhanceder diagram-111005002740-phpapp0227f157al5enhanceder diagram-111005002740-phpapp02
27f157al5enhanceder diagram-111005002740-phpapp02marangburu42
 
Adbms 19 object technology in rdbms
Adbms 19 object technology in rdbmsAdbms 19 object technology in rdbms
Adbms 19 object technology in rdbmsVaibhav Khanna
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagramMayank Jain
 
PLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptxPLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptxRichard Martens
 
implementing oop_concept
 implementing oop_concept implementing oop_concept
implementing oop_conceptAmit Gupta
 
Synapse india reviews on drupal 7 entities (stanford)
Synapse india reviews on drupal 7 entities (stanford)Synapse india reviews on drupal 7 entities (stanford)
Synapse india reviews on drupal 7 entities (stanford)Tarunsingh198
 
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSeyed Ibrahim
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
Object relational database management system
Object relational database management systemObject relational database management system
Object relational database management systemSaibee Alam
 
ER Digramms by Harshal wagh
ER Digramms by Harshal waghER Digramms by Harshal wagh
ER Digramms by Harshal waghharshalkwagh999
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.pptMARasheed3
 
CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3Duong Thanh
 
Function in Python
Function in PythonFunction in Python
Function in PythonYashdev Hada
 

Similaire à Absolutely Typical - The whole story on Types and how they power PL/SQL Interoperability (UKOUG, 2011) (20)

Oracle Objects And Transactions
Oracle Objects And TransactionsOracle Objects And Transactions
Oracle Objects And Transactions
 
Adv DB - Full Handout.pdf
Adv DB - Full Handout.pdfAdv DB - Full Handout.pdf
Adv DB - Full Handout.pdf
 
Advance database system(part 4)
Advance database system(part 4)Advance database system(part 4)
Advance database system(part 4)
 
27f157al5enhanceder diagram-111005002740-phpapp02
27f157al5enhanceder diagram-111005002740-phpapp0227f157al5enhanceder diagram-111005002740-phpapp02
27f157al5enhanceder diagram-111005002740-phpapp02
 
Adbms 19 object technology in rdbms
Adbms 19 object technology in rdbmsAdbms 19 object technology in rdbms
Adbms 19 object technology in rdbms
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagram
 
PLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptxPLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptx
 
implementing oop_concept
 implementing oop_concept implementing oop_concept
implementing oop_concept
 
Synapse india reviews on drupal 7 entities (stanford)
Synapse india reviews on drupal 7 entities (stanford)Synapse india reviews on drupal 7 entities (stanford)
Synapse india reviews on drupal 7 entities (stanford)
 
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functions
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Sameer
SameerSameer
Sameer
 
DB2 on Mainframe
DB2 on MainframeDB2 on Mainframe
DB2 on Mainframe
 
Object relational database management system
Object relational database management systemObject relational database management system
Object relational database management system
 
Helberg acl-final
Helberg acl-finalHelberg acl-final
Helberg acl-final
 
ER Digramms by Harshal wagh
ER Digramms by Harshal waghER Digramms by Harshal wagh
ER Digramms by Harshal wagh
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3
 
Unit ii
Unit iiUnit ii
Unit ii
 
Function in Python
Function in PythonFunction in Python
Function in Python
 

Plus de Lucas Jellema

Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Lucas Jellema
 
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...Lucas Jellema
 
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...Lucas Jellema
 
Apache Superset - open source data exploration and visualization (Conclusion ...
Apache Superset - open source data exploration and visualization (Conclusion ...Apache Superset - open source data exploration and visualization (Conclusion ...
Apache Superset - open source data exploration and visualization (Conclusion ...Lucas Jellema
 
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...Lucas Jellema
 
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...Lucas Jellema
 
Op je vingers tellen... tot 1000!
Op je vingers tellen... tot 1000!Op je vingers tellen... tot 1000!
Op je vingers tellen... tot 1000!Lucas Jellema
 
IoT - from prototype to enterprise platform (DigitalXchange 2022)
IoT - from prototype to enterprise platform (DigitalXchange 2022)IoT - from prototype to enterprise platform (DigitalXchange 2022)
IoT - from prototype to enterprise platform (DigitalXchange 2022)Lucas Jellema
 
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...Lucas Jellema
 
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...Lucas Jellema
 
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...Lucas Jellema
 
Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...Lucas Jellema
 
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...Lucas Jellema
 
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Lucas Jellema
 
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)Lucas Jellema
 
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...Lucas Jellema
 
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)Lucas Jellema
 
Tech Talks 101 - DevOps (jan 2022)
Tech Talks 101 - DevOps (jan 2022)Tech Talks 101 - DevOps (jan 2022)
Tech Talks 101 - DevOps (jan 2022)Lucas Jellema
 
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...Lucas Jellema
 
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...Lucas Jellema
 

Plus de Lucas Jellema (20)

Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
 
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
 
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
 
Apache Superset - open source data exploration and visualization (Conclusion ...
Apache Superset - open source data exploration and visualization (Conclusion ...Apache Superset - open source data exploration and visualization (Conclusion ...
Apache Superset - open source data exploration and visualization (Conclusion ...
 
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
 
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
 
Op je vingers tellen... tot 1000!
Op je vingers tellen... tot 1000!Op je vingers tellen... tot 1000!
Op je vingers tellen... tot 1000!
 
IoT - from prototype to enterprise platform (DigitalXchange 2022)
IoT - from prototype to enterprise platform (DigitalXchange 2022)IoT - from prototype to enterprise platform (DigitalXchange 2022)
IoT - from prototype to enterprise platform (DigitalXchange 2022)
 
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
 
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
 
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
 
Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...
 
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
 
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
 
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
 
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
 
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
 
Tech Talks 101 - DevOps (jan 2022)
Tech Talks 101 - DevOps (jan 2022)Tech Talks 101 - DevOps (jan 2022)
Tech Talks 101 - DevOps (jan 2022)
 
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
 
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
 

Dernier

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Dernier (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

Absolutely Typical - The whole story on Types and how they power PL/SQL Interoperability (UKOUG, 2011)

  • 1. Lucas Jellema, AMIS ABSOLUTELY TYPICAL - THE WHOLE STORY ON TYPES AND HOW THEY POWER PL/SQL INTEROPERABILITY On Types and Objects, Collections and OO UKOUG, December 2011, Birmingham, UK
  • 2. OVERVIEW • History of Types • Areas of use • Type • True OO • Collections [of Types] • Table and Multiset • Interaction with the outside world – XML, JSON – Web Services
  • 3. STANDARD TYPES IN ORACLE DATABASE • Standard as in „installed out of the box‟ – Number, Char, Date – Varchar2 – RAW, LONG – SDO_GEOMETRY, … – BLOB, CLOB, TIMESTAMP, INTERVAL – XMLType – DICOM (Medical Records)
  • 4. THE DATABASE SUFFIX • 12c • 11g • 10g • 9i • 8i • 8.0 – That is 8.o (as in oh, not as in zero!) o • And: 8 really is o o • OO in Oracle turned out to mean – Define user defined types to use as SQL and PL/SQL data structure programming constructs • that have some OO characteristics as well • that can be used to define table columns for
  • 5. AREAS OF USE FOR TYPES • Structured programming in PL/SQL • Interaction SQL and PL/SQL – Elegant, performing, organized • Interaction with the outside world – Java, SOA Suite, other consumers • OO-like storage of nested type structures • Do OO design and application development
  • 6. EXAMPLE OF TYPE DEFINITION • Types are manipulated through Type as Object DDL statements: – CREATE OR REPLACE TYPE PERSON_T – Object Types have properties (attributes) – Object Types are similar to PL/SQL records – Object Types live in Data Dictionary as primary database objects
  • 7. INSTANTIATING AN OBJECT • A variable based on a type (as object) needs to be instantiated before it can be assigned or read • An instance of a type == an object
  • 9. CALLING FUNCTION WITH TYPE PARAMETER FROM SQL • Types can be instantiated from within SQL statements and passed to PL/SQL functions – SQL*Plus and other tools typically know how to render types in query results
  • 10. SELECT OBJECT TYPE FROM SQL
  • 11. SCALAR SUBQUERY • Inline query that returns a single result – One row, one column select ename Employees with their job and sal and the , job number of staff they manage , sal , (select count(empno) from emp s where s.mgr= e1.empno) from emp e1 select ename Employees who earn between the average , sal salary for salesmen and analysts from emp where sal between (select avg(sal) from emp where job = 'SALESMAN') and (select avg(sal) from emp where job = 'ANALYST')
  • 12. WORKAROUND TO RETRIEVE MULTIPLE VALUES: CONCATENATION OF VALUES select ename , job , sal , substr(sal_aggs, 1, instr(sal_aggs,'x') -1) avg_sal_in_job , substr(sal_aggs, instr(sal_aggs,'x') +1) max_sal_in_job from ( select ename , job , sal , ( select avg(sal)||'x'||max(sal) from emp where job = e1.job ) sal_aggs from emp e1 ) order by job, sal desc
  • 13. MUCH BETTER WORK AROUND: ADT select ename create type , job multivalue_return_type , sal as object , emps.sal_aggs.value1 avg_sal_in_job ( value1 number(20) , emps.sal_aggs.value2 max_sal_in_job , value2 number(20) from ( select ename , value3 number(20) , job ) , sal , ( select multivalue_return_type ( avg(sal), max(sal), null) from emp where job = e1.job ) sal_aggs from emp e1 ) emps order by job, sal desc
  • 14. TYPES AND THE DBA • Before Oracle Database 11g – altering type definitions was not easy – Drop, Alter or Replace of a Type could only be done if no references existed to the type from other types or tables – That usually meant all types associated with an application were dropped and recreated – to alter one! • Starting in 11g the DROP and REPLACE/ALTER TYPE operations can specify FORCE to ignore dependencies – Helps to overcome frowning, type-averse DBAs! • Note: Data Dictionary Views are available to tell on types • Types are editionable objects in terms of 11gR2 Edition Based Redefinition and can evolve gracefully
  • 15. COMPLEX TYPES • Attribute of a Type (as Object) can be based on an ADT aka UDT: Object or Collection – Limitation: Self-reference is not allowed Type as Object Type as Object PERSON_T SOCIAL_PROFILE_T
  • 16. SOCIAL PROFILES STORED IN TABLES • Two options for storing social profiles: – The normal, explicit relational way: – The nested table approach:
  • 17. INSTANTIATING NESTED OBJECT IN SQL • Instantiate „look up object‟ using Scalar Subquery • Instantiate „look up object‟ from (outer) joined columns
  • 18. COLLECTIONS IN ORACLE • Oracle supports in-memory collections of type instances – Can be of standard type (number, varchar2, date,…) or complex User Defined Type (aka ADT) • Three kinds of collections – Associative Array (PL/SQL only) – {key,value} pairs, very similar to Map in Java and Hashtable in C# – VARRAY (the variable array of fixed size) – Nested Table • These collections are similar, yet quite distinct – Definition and instantiation – Similar operations (count, first, next, delete, …) – Sparse vs. Dense – SQL Interaction support
  • 19. CREATING AND WORKING WITH AN ASSOCIATIVE ARRAY (PL/SQL ONLY)
  • 20. CREATING AND WORKING WITH A NESTED TABLE
  • 21. COLLECTION OPERATIONS • Exists – to check if element with/at index exists • Extend (only for Nested Table) • Count • First • Last • Next • Prior • Delete • Trim
  • 22. COMPLEX TYPES Type as Object Type as Object PERSON_T SOCIAL_PROFILE_T Type as Table of email_address_t EMAIL_ADDRESS_TBL Type as Object EMAIL_ADDRESS_T
  • 23. CONSTRUCTING A COMPLEX OBJECT IN PL/SQL
  • 24. CONSTRUCTING A COMPLEX OBJECT IN PL/SQL
  • 25. TRUE OO: SUBTYPES AND INHERITANCE • Types can be created as subtypes of another Type • A subtype has multiple identities: – EMPLOYEE_T is both PERSON_T and EMPLOYEE_T – Anything that can handle a PERSON_T can also handle an EMPLOYEE_T and a CUSTOMER_T Type as Object PERSON_T Type as Object Type as Object EMPLOYEE_T CUSTOMER_T
  • 26. CREATION OF TYPE HIERARCHY Type as Object EMPLOYEE_T
  • 27. CREATE INSTANCES OF SUBTYPE IN PL/SQL
  • 28. OO OPERATORS IN TYPE HIERARCHY • TREAT (AS type) – downcast an instance to a specific subtype – to access specialized subtype aspects • IS OF ( [ONLY] type) – to identify type of an instance
  • 29. MEMBER FUNCTIONS • A type can have operations – Specification and Implementation (in the Body) – Acting on the members – public and private – of the object – Possibly overriding methods of the super-type • Two types of operations – Constructor Type PERSON_T as – Normal member functions Object <public methods> Type Body PERSON_T <implementation of private and public methods>
  • 30. CONSTRUCTOR FUNCTIONS • A type is instantiated through a call to one of its constructor methods • A type can have multiple, overloaded user defined constructor functions – In addition to the default system defined constructor that simply expects input for every public member
  • 31. MULTIPLE USER DEFINED CONSTRUCTORS
  • 32. MEMBER FUNCTIONS • Types can have member functions – similar to functions in a package – Just like package can act on package state (globals), member functions act on object (type instance)
  • 34. OVERRIDING MEMBER FUNCTIONS • Sub types can override member functions from super – When the function is invoked on a PERSON_T and PERSON_T happens to be a CUSTOMER_T, then the function as defined on CUSTOMER_T is executed – Overriding subtype member function can invoke the overridden super typer function Type PERSON_T as Object Type EMPLOYEE_T as Object Type CUSTOMER_T as Object
  • 35. EXAMPLE OF OVERRIDING MEMBER FUNCTION Type PERSON_T as Object Type CUSTOMER_T as Object
  • 36. MAP AND ORDER MEMBER FUNCTION SORTING COLLECTIONS • Map Member Function translates an object to a scalar data type that Oracle knows how to compare and sort – Varchar2, Number, Date or even an UDT with scalar attributes (or a Map function of its own) • Note: Map member function is also used for equality comparison – In this case John Doe and Bill Doe are seen as equal!
  • 37. MAP MEMBER FUNCTION IN ACTION - SORTING IN SQL • Map function dictates: – Women come first, then sort by birth date (young before old)
  • 38. ORDER MEMBER FUNCTION USED TO ORDER BY IN SQL • Order member function to compare objects – returns -1 when self comes before other (when sorted), 1 when self comes after and 0 when they draw
  • 40. USER DEFINED AGGREGATION FUNCTIONS IN SQL select avg(hiredate) from emp ORA-00932: inconsistent datatypes: expected NUMBER got DATE • The Oracle Data Cartridge offers User Extensibility framework for the database • Data Cartridge provides: – user defined aggregate functions – domain indexes and functions • used for Oracle Text and Oracle Spatial – Pipelined Table Functions – the interface approach • Dynamic handling of AnyData objects
  • 41. IMPLEMENTING USER DEFINED AGGREGATE • Implement an object with the following operations: – ODCIAggregateInitialize – ODCIAggregateIterate – ODCIAggregateTerminate – ODCIAggregateMerge • Optional, to enable parallelism create type DateAvgImpl as object ( count number , sumdates NUMBER , function ODCIAggregateInitialize , function ODCIAggregateIterate , function ODCIAggregateTerminate , function ODCIAggregateMerge )
  • 42. IMPLEMENTING USER DEFINED AGGREGATE • Register new aggregate function implemented by the object function dateavg (input date) return date PARALLEL_ENABLE AGGREGATE USING DATEAVGIMPL • Use the new function in queries select DateAvg(hiredate) from emp • “Analytic Function Friendly”
  • 43. FUNCTION CHAINING • Dot notation (navigation) is used to call a function on the result of a function (on the result…) – if the result of the nested functions are types
  • 44. BULK COLLECT TO PREVENT MULTIPLE ROW-BY-ROW PL/SQL TO SQL ACCESS • Traditional cursor based approaches for fetching data from the database using SQL resulted in – Unnecessary SQL/PLSQL context switches • By fetching multiple rows at once – the number of (expensive) switches can be reduced • Several approaches exist – all rely on Collections – Bulk Collect – Select Collection • Note: as of Oracle 10g the „normal‟ cursor-for-loop also implicitly does fetching in bulk
  • 46. CREATE A COLLECTION IN SQL – COLLECT OPERATOR • COLLECT is an aggregation function (like MAX, SUM, COUNT) that aggregates into nested tables – Group by can be used to create ‘clusters’
  • 47. SELECT COLLECT INTO PL/SQL VARIABLE
  • 48. MULTISET TURNING A (SUB) QUERY RESULT SET ON THE FLY INTO A NESTED TABLE • MULTISET can be used inside SQL Queries to convert a query result set into a collection (nested table) – On the fly (in the middle of a query)
  • 50. MULTISET OPERATORS ACTING ON NESTED TABLES IN SQL AND/OR PL/SQL • C1 = C2 – Comparison based on named type, cardinality and comparison of individual elements • C1 <> C2 or C1 != C2 – Inverse of equality test • C1 IN C2 returns true if C1 is one of the collections in C2 which is a collection of collections • POWERMULTISET C1 generates all non-empty sub- multisets from collection C1 – All possible combinations created from the elements in C1, produced as collections of the same type as C1 • C1 IS EMPTY returns true if C1 is empty • CARDINALITY C1 returns the number of elements in C1
  • 51. MULTISET OPERATORS ACTING ON NESTED TABLES IN SQL AND PL/SQL • C1 SUBMULTISET C2 evaluates to true when the members of C1 are all found in C2 • X MEMBER OF C1 evaluates to true when X is found as a member of collection C1 • C1 MULTISET UNION [DISTINCT] C2 – combining two collections – Use DISTINCT to eliminate duplicate elements • C1 MULTISET INTERSECT [DISTINCT] C2 – produces collection of elements that occur in both C1 and C2 • C1 MULTISET EXCEPT [DISTINCT] C2 – produces the collection of elements that appear in C1 and not in C2 – Use ALL to allow (reduced number of )duplicates • C1 IS A SET – tests if the collection C1 only has unique members (no duplicates)
  • 52. COULD BE ANYTHING • The Any… Types are like generic placeholders for data that is only known at run time – The contents of Any… instances is accessible through introspection • AnyData – some thing, could be any thing (Object) • AnyType – holds the definition of some thing • Like AnyData without the data – only meta data • AnySet – some collection of things (all of the same type) – can be used for interface parameters to communicate self-descriptive sets of data – Used in Pipelined Table Functions created through Data Cartridge to return dynamically determined data structures
  • 53. CREATING AND PROCESSING A TABLE OF THINGS – STEP 1
  • 54. CREATING AND PROCESSING A TABLE OF THINGS – STEP 2
  • 55. Process collection as query result TABLE
  • 56. TABLE FUNCTIONS • In queries: select from collections as if they were a table using the TABLE operator
  • 57. JUST BECAUSE WE CAN - POINTLESS COMBINATION OF COLLECT AND TABLE
  • 58. SORTING COLLECTIONS LEVERAGE SQL TO DO THE ORDER BY Build up collection of people in variable l_people
  • 59. EXTREME ENCAPSULATION • View on top of table(collection) – With instead of trigger handling DML – Data queried from NUMBERS is produced in PL/SQL – no underlying table involved – Data manipulated in NUMBERS is processed in memory
  • 61. FOR GENERATING ROWS FOR SPECIAL DOMAINS OF ALLOWABLE VALUES • Have TABLE operate on an in-line created collection with countries as ( select column_value country from table( string_table('Belgium','France' ,'Egypt','Italy' ) • To save)on repeated ) – select value from dual UNION ALL select value … select country from countries with gender_values as ( select column_value gender from table( string_table('MALE', 'FEMALE',‘UNKNOWN' )) ) select gender from gender_values
  • 62. PIPING ROWS USING COLLECTIONS AND THE „TABLE FUNCTION‟ • A Table Function normally returns the entire collection at once • However: it can also return collection elements one at a time – That is called PIPELINED • As soon as the function pipes a single element, processing that element can continue • It‟s bit like the /*+ FIRST_ROWS */ Hint
  • 63. THE SLOW ALPHABET… create or replace function alphabet return letter_table is l_alphabet letter_table:= letter_table(); begin l_alphabet.extend(26); for i in 1..26 loop l_alphabet(i):= chr(64+i); dbms_lock.sleep(0.1); end loop; return l_alphabet; end alphabet; Note: it is not just 2.79 seconds for all rows to appear: it takes that long for any row to appear
  • 64. THE PIPELINED SLOW ALPHABET… create or replace function alphabet return letter_table pipelined is l_alphabet letter_table:= letter_table(); begin l_alphabet.extend(26); for i in 1..26 loop l_alphabet(i):= chr(64+i); dbms_lock.sleep(0.1); pipe row (l_alphabet(i)); end loop; return; end alphabet; Note: total processing time is just as long as before; however, the first row appears after less than 0.5 sec!
  • 67. DO NOT DO IT… ON YOUR OWN • Parallel means: multiple resources contributing to a task at the same time • Introduce parallellism into your database application – parallel query and DML – coordinated jobs (dbms_job, dbms_scheduler) – 11g: dbms_parallel_execute – Pipelined & Parallel table functions
  • 70. PIPELINED PANCAKE PARTY: BEST PERFORMANCE
  • 71. PIPELINED PANCAKE PARTY • Parallel Pipelined: multiple different resources working on different components of the task in [potentially] different tiers – From batch processing to unit processing => pass the unit on for further processing as soon as part of the task is done – to leverage resources (across tiers) in parallel • Instead of baking the entire stack first and only then eating it… – … start eating as soon as the first one is done – Even the last guest ends earlier than without pipelining provided he eats more than one pancake • (he eats his first pancake when it is done, not when the stack is done) – The first eater is done much sooner • first rows/all rows ≈ first pancake/all pancakes
  • 76. INTRODUCING XML • Structured ASCII • Esperanto • Cross technology – interoperability • Tools & frameworks for common operations – Parsing, validation, construction, transformation and querying • Standards: – XSD – design and contract – XPath - querying – XSLT - transformation – XQuery – querying and manipulation
  • 77. WHAT IS XML?  eXtensible Markup Language – for exchange of data  Plain text / ASCII files  Structured messages  Human readable  More important: machine interpreted  Meaning defined with tags  Elements and attributes <?xml version="1.0" encoding="UTF-8"?> <root element> <element1 attributeName="value"> content</element1> <element2 attributeName="value" /> <element3> <element4>content</element4> </element3> </root element>
  • 78. TYPE TO HOLD XML DATA IN ORACLE XMLType
  • 79. CONSTRUCTING XML IN DATABASE APPLICATIONS • Many ways to produce XML content in Oracle – XMLType – from text, types, cursor, bfile contents, … – SQL/XML (XMLAgg, XMLElement, XMLForest, …) – DBMS_XMLGEN – SYS_XMLGEN and SYS_XMLAGG – DBURIType and XDBURIType – XML SQL Utility (XSU) – command line, Java, PL/SQL – fn:doc and fn:collection (replacing ora:view) XMLType
  • 80. CONVERTING TYPE STRUCTURE TO XMLTYPE • XMLType can be instantiated based on a single complex User Defined Type instance – Not (directly) on a nested table
  • 82. CONVERT XMLTYPE TO NESTED USER DEFINED TYPE • XMLType supports conversion directly in a – potentially nested – user defined type – Provided element names match names of type, subtypes and attributes
  • 83. XML CAN BE SOMEWHAT HEAVY • Size of XML documents compared to the actual data content of those documents is „XXL‟ • Complex nested structure that requires parsing • Turning XML into native data structures and vice versa is expensive (Marshalling/Unmarshalling ) • XML Programming facilities not available on all platforms and in all languages – Objective C, JavaScript, … • The search for alternatives is on: structured, contract, standardized, facilities, lighter weight!
  • 84. JavaScript Object Notation Lightweight data-interchange format
  • 86. Name : Value, Name : Value, Name : Value
  • 87. , , Name : Value, Name : Value, Name : Value, Name : Value, Name : Value, Name : Value, Name : Value Name : Value Name : Value
  • 88. {"ACCOUNTING" : { "EMPLOYEES" : [ {"ENAME" : "KING", "JOB" : "PRESIDENT", "SAL" : 5000 }, {"ENAME" : "MILLER", "JOB" : "CLERK", "SAL" : 1300 }] } }
  • 89. <department name="ACCOUNTING"> <employees> <employee> <ename>KING</ename> <job>PRESIDENT</job> <sal>5000</sal> </employee> <employee> <ename>MILLER</ename> <job>CLERK</job> <sal>1300</sal> </employee> </employees> </department>
  • 90.
  • 91. PL/JSON EXAMPLE – CREATING AND QUERYING JSON
  • 93. FROM TYPES TO XML TO JSON
  • 94. FROM JSON TO XML TO TYPES
  • 95. PUBLISH PACKAGE AS HTTP-BASED API USING DBMS_EPG http • Hide database protocol – Not its physical location nor the schema, and user authentication • HTTP communication is truly cross technology – Browser, Java, .Net, JavaScript & RIA clients, … • Is also possibly remote, across networks, firewalls etc. – easier than normal JDBC connections • Can publish in various formats – Text, HTML, CSV, JSON, XML, RSS • Use case:cross-technology, internal no WS*/ESB
  • 96. SIMPLE DBMS_EPG EXAMPLE sys scott scott
  • 97. RESTFUL WEBSERVICES • Simple, stateless, light weight, http-based message exchange protocol – Use standard get, put, post, delete operations – Use URL to pass resource reference • Small, easy-to-understand messages • Typically XML or JSON based • Not using SOAP, or the WS*-stack • Often used directly from User Interface – (AJAX enabled) JavaScript
  • 98. RESTFUL ARCHITECTURE RESTful PL/SQL API exposed through dbms_epg
  • 100. PUBLISH REST-FUL HTTP API – DIRECTLY ON TOP OF THE RDBMS
  • 101. PUBLISH REST-FUL HTTP API – DIRECTLY ON TOP OF THE RDBMS
  • 102. JSON RESPONSE – WROUGHT FROM TYPES AND COLLECTIONS
  • 103. TURNING ANY OBJECT INTO JSON
  • 104. CONSUMING REST-FUL SERVICES • Invoking a REST-ful service is simply making an HTTP request to some URL • Can be done through: – utl_http – httpuritype – Stored Java • Result can be processed as just a string or as XML, JSON or other format – Libraries (PL/JSON) can help with special formats
  • 105. SOAP WEB SERVICES • All messages (input and output) are XML • The message consists of two parts inside an envelope (a SOAP XML wrapper) – The header with meta-data – The body with the contents to be handled by or returned by the service • The WebService Definition Language (WSDL) document describes the service • An XML Schema Document (XSD) describes the structure of the XML messages – XSD is like an ERD or Table Design
  • 106. ORACLE RDBMS 11G – NATIVE DATABASE WEB SERVICES • Database Schema can be published WS/SOAP through native database web services – Each package corresponds with a WSDL • With an operation for each Procedure or Function • Auto-mapping from PL/SQL input and output parameters to WSDL (XSD) Types – WSDL and XSD are dynamically generated – A generic Query Service (across schema) is exposed • To execute user defined queries • With support for pagination and some formatting – http and https is supported – Limited control over WSDL & XSD – Use case: internal, cross technology, WS enabled client, no ESB or Application Server available
  • 107. STUFF INC • Challenge: publish SOAP Web Services to expose data services based on an Oracle Database – Read data and Manipulate data • Use as decoupled an approach as possible – Java developers do not touch SQL or PL/SQL – Database developers are not aware of web service context • See white paper on OTN http://www.oracle.com/technetwork/articles/soa/jellema-esb-pattern- 1385306.html for details
  • 108. XML Relational/Oracle Type JEE Server Database Native DB WebService HTTP http EPG ADF BC JSON/ CSV SDO /SDO WS XML PL/SQL XML & XSD SOA WS JAX-WS package Ref Cursor Suite JPublisher DB Types & Coll WS JDBC XML AQ Types Adapters AQ JMS Queue JMS utl_file, View JMS BFILE, Oracle EJB EJB/JPA URITYPE Service Pojo Other Table (Email, FTP/File, XML Bus File XMPP/Chat) DB FTP UMS Chat/IM XMPP Server File/FTP Server Email Server
  • 109. PL/SQL MUSIC API EXPRESSED IN TYPES AND COLLECTIONS Type Package
  • 110. FOR JAVA DEVELOPERS BENEFIT: SOAP WebService WRAP TYPE IN XMLTYPE Java Class Java Class JAX-WS ESB Architecture pattern: The XMLType Oracle JDBC Type Package Mediator Decouple XMLType Java Class exchange Validate, Enrich, Transform, Route, …
  • 111. TO ACCOMMODATE FRAMEWORKS SOAP WebService THAT DO NOT UNDERSTAND XMLTYPE Java Class Java Class JAX-WS Oracle JDBC XMLType String Type CLOB Mediator XMLType Package Java Class JDBC exchange
  • 112. USING THE OSB OR SOA SUITE DATABASE ADAPTER – USER DEFINED TYPES ARE FINE • Database adapter interacting with Type based PL/SQL API – Derives XSD from input and output parameters – Allows for perfect decoupling between PL/SQL on one side of the fence and Web Service/XML on the other Validate Enrich Transform Route & Operate SOAP WebService User XML Proxy Service Defined Business Type Type Package HTTP Service SOAP JDBC Database Adapter
  • 113. JUKEBOX SERVICE - COMPLETE Validate Enrich Transform Route & Operate SOAP WebService User XML Proxy Service Defined Business Type Type Package HTTP Service SOAP JDBC Database Adapter
  • 114. SUMMARY • Long live types! • Structured programming in PL/SQL – Multiple input and output parameters, step by step result constructions • Integration between SQL and PL/SQL – Scalar Subquery, Bulk Collect and Collect Aggregator – Table and Multiset operators – Pipelined Table Functions • Integrating with the external world – Type turning XML and/or JSON – Native Database Web Services – Database Adapter in SOA Suite and Service Bus

Notes de l'éditeur

  1. Process
  2. http://technology.amis.nl/blog/6122/oracle-rdbms-11gr2-drop-and-replace-user-defined-types-even-when-there-are-dependencies
  3. http://technology.amis.nl/blog/1217/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-liftinghttp://technology.amis.nl/blog/1214/sorting-plsql-collections-the-hard-way-the-intermediate-way-and-the-quite-simple-way-part-one
  4. Compare ECT:Unload all containers, than start moving out (train?)Unload one, put on truck and start driving; then unload next one
  5. http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16659/xdb13gen.htm#i1027254XSU – PL/SQL API http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10708/adx_j_xsu.htm#BABGGGAH
  6. http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16659/xdb13gen.htm#CHEHAECDhttp://nuijten.blogspot.com/2010/12/creating-xmltype-based-on-object-types.htmlhttp://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/t_xml.htm#BABFEGCBhttp://askanantha.blogspot.com/2008/07/xml-type-conversions-in-oracle.htmlhttp://technology.amis.nl/blog/6131/oracle-sql-and-plsql-juggling-with-user-defined-types-adt-and-xmltype-for-creating-an-adt-based-xml-service-api
  7. JavascriptPhpWeb wereld
  8. Very compact, with lots of information.
  9. Same information, now represented in XML – lot more text
  10. Available Open Source projects for JSON in combination with PL/SQL