SlideShare a Scribd company logo
1 of 77
Lucas Jellema
Singapore Oracle Sessions III - 14th July 2015
What is truly relevant for database
developers in Oracle Database 12c
The Presenter:
Lucas Jellema
• Lives in The Netherlands
(close to Amsterdam)
• Started doing Oracle in 1994 with
Oracle Consulting (Oracle Designer, Forms, Database)
• Joined AMIS in 2002 – now working as CTO,
Consultant (Architect, Technical Lead, Programmer)
and Trainer
• Oracle ACE (2005) & ACE Director (2006)
• Author of ‘Oracle SOA Suite 11g Handbook’
(Oracle Press, 2010), ‘Oracle SOA Suite 12c Handbook’ (2015)
• Presenter at Oracle OpenWorld, JavaOne and
many Oracle and Java User Group Conferences
• Frequent blogger at http://technology.amis.nl
• Active with SQL & PL/SQL, Java EE & ADF,
SOA, BPM & more Fusion Middleware
3
Oracle Database 12c =
• Multitenant Architecture aka Pluggable Database
4
Oracle Database 12c –
12.1.0.2 =
• In-Memory Database Option
5
Oracle Database 12c for
Database Developers
JavaScript Object Notation
Lightweight data-interchange format
Support in Oracle Database 12c – 12.1.0.2
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
, ,
{ "NAME" :"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>
12
JSON
• Light Weight, Structured, fairly tied coupled (low bandwidth) interactions
between application[component]s
• Very popular in rich client web applications and mobile apps – usually as
the format used in REST-services
• Oracle Database 12c is JSON aware
– Store documents (in a column VARCHAR2, CLOB, NCLOB, BLOB, RAW, BFILE –
and have them checked for JSON validity
– Create Indexes on JSON contents
– Access JSON content directly from SQL queries
– Note: similar to but only a subset of XML support in Oracle Database
(as JSON in terms of functionality is a somewhat pale subset of XML)
• Oracle Driver for Node.js – similar to JBDC, all in JSON
alter table X
add CONSTRAINT ensure_json_chk CHECK (column_y IS JSON))
13
JSON in the Oracle Database
• Why JSON in relational database?
– Consistency (integrity, transaction ACIDity) for storing JSON documents
– Quickly interpret data received (and stored?) in JSON format
– Leverage JSON as a convenient way to handle structured data as a string
– Easy data transfer over some protocols, including HTTP – especially when database
engages directly in HTTP interactions
14
A sample JSON document
{"matches":
[ {"matchLineUp": "NED-ESP"
, "score": "5-2"
,"matchDate":"13-06-2014"
}
, {"matchLineUp": "SWI-FRA"
, "score": "2-5"
,"matchDate":"20-06-2014"
}
, {"matchLineUp": "GER-BRA"
, "score": "1-7"
,"matchDate":"08-07-2014"
}
]
}
15
Check for a valid JSON
document and/or path result
• IS JSON can be used in the WHERE clause to filter on rows that contain a
valid JSON document
– It can be used in CHECK Constraints for that same reason
• JSON_EXISTS is typically used in the WHERE clause to filter on rows
whose JSON content satisfies some JSON path condition
select *
from customers
where json_exists(doc, '$.addresses.privateAddress')
select *
from customers
where doc IS JSON
16
JSON_VALUE to retrieve scalar
value from JSON document
• JSON_VALUE is a SQL Function used to retrieve a scalar value from a
JSON document
– JSON_VALUE can be used like any other SQL Function in queries and DML – in
various clauses like SELECT, WHERE, GROUP BY, etc.
select json_value
( '{"matches":
[ {"matchLineUp": "NED-ESP"
, "score": "5-2","matchDate":"13-06-2014"}
, {"matchLineUp": "SWI-FRA"
, "score": "2-5","matchDate":"20-06-2014"}
, {"matchLineUp": "GER-BRA"
, "score": "1-7","matchDate":"08-07-2014"}
]
}'
, '$.matches[1].score') as "2nd_match_score"
from dual
17
JSON_QUERY to retrieve JSON-
snippets from a JSON document
select json_query
( '{"matches":
[ {"matchLineUp": "NED-ESP"
, "score": "5-2","matchDate":"13-06-2014"}
, {"matchLineUp": "SWI-FRA"
, "score": "2-5","matchDate":"20-06-2014"}
, {"matchLineUp": "GER-BRA"
, "score": "1-7","matchDate":"08-07-2014"}
]
}'
, $.matches[*].score' WITH WRAPPER) as scores
from dual
• JSON_QUERY is a SQL Function used to retrieve a JSON snippet from a
JSON document - the result is a string that contains valid JSON
– Use WRAPPER to wrap an Array result in an object to return a valid document
18
JSON_TABLE to expose records
from a JSON document relationally
with match_results as
( select '...' json_doc from dual)
select lineUp, score
, to_date(matchDate, 'DD-MM-YYYY') matchDate
from match_results
, json_table( json_doc, '$.matches[*]'
COLUMNS
( lineUp varchar2(20) PATH '$.matchLineUp'
, score varchar2(20) PATH '$.score'
, matchDate varchar2(20) PATH '$.matchDate'
)
)
• JSON_TABLE is used in the FROM clause of SQL statements to project
data from a JSON document as a virtual relation view
– JSON_TABLE is very similar to XML_TABLE
19
12.1.0.2 – JSON
What it does not do?
• Support for variable strings as JSON_PATH in JSON-functions
• Deal with JSON in PL/SQL
– JSON_VALUE and JSON_QUERY cannot be used directly from PL/SQL
• Construct JSON documents
– Not supported: conversion from ADT (to XMLType) to JSON type and vice versa
– Not supported: a SQL/JSON syntax similar to SQL/XML for querying together a
JSON document
– Not supported: facilities that inject JSON into RESTful Services implemented through
the PL/SQL Embedded Gateway
Types
OBJECTS,
NESTED TABLE XMLType
The PL/JSON library
• This library has been around for several years – and is still pretty much
relevant
• Especially useful
– For composing JSON documents
– And for converting back and forth from and to JSON to XMLType and ADT/UDT
21
Bringing closer together
PL/SQL and SQL
In-line PL/SQL Functions and
procedures
• Procedures are also allowed in-line
• In-Line Functions and Procedures can invoke each other
WITH
procedure increment( operand in out number
, incsize in number)
is
begin
operand:= operand + incsize;
end;
FUNCTION inc(value number) RETURN number IS
l_value number(10):= value;
BEGIN
increment(l_value, 100);
RETURN l_value;
end;
SELECT inc(sal)
from emp
In-line PL/SQL Functions and
procedures
• In-Line Functions and Procedures can invoke each other
– And themselves (recursively)
WITH
FUNCTION inc(value number)
RETURN number IS
BEGIN
if value < 6000
then
return inc(value+100);
else
return value + 100;
END if;
end;
SELECT inc(sal)
from emp
Dynamic (PL/)SQL is allowed
inside inline functions
• EXECUTE IMMEDIATE can be used inside an inline PL/SQL function to
dynamically construct and execute SQL and PL/SQL
WITH
FUNCTION EMP_ENRICHER(operand varchar2) RETURN varchar2 IS
sql_stmt varchar2(500);
job varchar2(500);
BEGIN
sql_stmt := 'SELECT job FROM emp WHERE ename = :param';
EXECUTE IMMEDIATE sql_stmt INTO job USING operand;
RETURN ' has job '||job;
END;
SELECT ename || EMP_ENRICHER(ename)
from emp
Note: do not try this at home!
It is a horrible query!
(looks too much like POST_QUERY for comfort)
In-Line PL/SQL is not an excuse for lousy SQL
Combining in-line Views and
PL/SQL Functions & Procedures
WITH
procedure camel(p_string in out varchar2)
is
begin
p_string:= initcap(p_string);
end;
function obfuscate(p_string in varchar2)
return varchar2
is
l_string varchar2(100);
begin
l_string:= translate(upper(p_string), 'AEUIO','OIEUA');
camel(l_string);
return l_string;
end;
my_view as (
select obfuscate('Goedemorgen')
from dual
)
select *
from my_view
PL/SQL Functions That Run
Faster in SQL
• As of Oracle Database Release 12c, two kinds of PL/SQL functions
might run faster in SQL:
– PL/SQL functions that are defined in the WITH clauses of SQL SELECT
statements, described in Oracle Database SQL Language Reference
– PL/SQL functions that are defined with the "UDF Pragma"
• Pragma UDF means: compile in the ‘SQL way’ as to eliminate SQL 
PL/SQL context switch
FUNCTION inc(string VARCHAR2)
RETURN VARCHAR2 IS
PRAGMA UDF;
value number(10):= to_number(string);
BEGIN
if value < 6000
then
return inc(value+100);
else
return to_char(value + 100);
end if;
end;
SQL PLSQL
SQL
plsql plsql
SQL Translation
SQL Statement Preprocessor
• A mechanism to allow the text of a SQL statement, submitted from a client
program (e.g. via ODBC or JDBC), to be translated by user-supplied code
before it is submitted to the Oracle Database SQL compiler.
– Positioned to allow 3rd party apps to (better) run against Oracle Database
– Additionally, any other use case where it is useful to intervene between the SQL
statement that the client submits and what is actually executed
– Some associations: VPD policies, Data Redaction, MV query rewrite, Advanced
Query Rewrite, Temporal Validity (time slice)
Application
SQLPre
proce
ssor
SQL
engine SQL
SQL Translation – set up
AS SYS:
grant create sql translation profile to oow;
grant alter session to oow;
AS Application Owner:
-- Create a Translation Profile
exec dbms_sql_translator.create_profile('HR_PROFILE');
BEGIN
DBMS_SQL_TRANSLATOR.REGISTER_SQL_TRANSLATION(
profile_name => 'HR_PROFILE',
sql_text => 'select ename, job, hiredate
from emp',
translated_text => 'select initcap(ename) as ename
, job, hiredate
from emp where job<>''MANAGER'' ‘
);
END;
select * FROM USER_SQL_TRANSLATION_PROFILES;
select * from USER_SQL_TRANSLATIONS;
SQL Translation – in action
-- to enable the profile (usually in logon trigger)
alter session set sql_translation_profile = HR_PROFILE
-- to pretend we are a foreign application, subject to
-- SQL Translation
alter session set events = '10601 trace name context forever, level
32';
-- execute query that is to be translated
select ename, job, hiredate
from emp
-- results are produced as if the translated text had been submitted
SQLPre
proce
ssor
SQL
engine SQL
32
SQL Translation
• Support for bind parameters
• Support for rewriting PL/SQL calls
• Translation of Error Messages (ORA-xxxx to SYB-yyyy or YOURAPP-zzz)
• Out of the box translators for Sybase, SQL Server and some DB2
• Optionally: register a custom translator package
– PROCEDURE TRANSLATE_SQL( sql_text IN CLOB, translated_text OUT CLOB);
Some SQL evolution
35
• Maximum length for VARCHAR2 is
now 32KB (up from 4KB)
• Invisible Columns
• One unified audit trail
• PL/SQL DBMS_UTILITY.EXPAND_SQL_TEXT can be used to uncover the real
SQL executed for a given query
– Expressed only in the underlying base tables, including VPD policies
• Export View as Table with Data Pump – fine grained projection of columns
and rows that will be part of the Dump and subsequent Import
• Creation of multiple indexes on same set of columns is allowed
– Although only one can be live at any one time
• Cross PDB queries
API for inspecting the PL/SQL
callstack
• New PL/SQL Package UTL_CALL_STACK provides API for inspecting the
PL/SQL Callstack
– Complements the DBMS_ UTILITY.FORMAT_CALL_STACK that returns a pretty
print human readable overview of the callstack
procedure tell_on_call_stack
is
l_prg_uqn UTL_CALL_STACK.UNIT_QUALIFIED_NAME;
begin
dbms_output.put_line('==== TELL ON CALLSTACK ==== '
||UTL_CALL_STACK.DYNAMIC_DEPTH );
for i in 1..UTL_CALL_STACK.DYNAMIC_DEPTH loop
l_prg_uqn := UTL_CALL_STACK.SUBPROGRAM(i);
dbms_output.put_line( l_prg_uqn(1)
||' line '||UTL_CALL_STACK.UNIT_LINE(i)
||' '
||UTL_Call_Stack.Concatenate_Subprogram
( UTL_Call_Stack.Subprogram(i))
);
end loop;
end tell_on_call_stack;
API for inspecting the PL/SQL
callstack
create or replace package body callstack_demo
as
function b( p1 in number, p2 in number) return number is
l number:=1;
begin
tell_on_call_stack;
return l;
end b;
procedure a ( p1 in number, p2 out number) is
begin
tell_on_call_stack;
for i in 1..p1 loop p2:= b(i, p1); end loop;
end a;
function c( p_a in number) return number is
l number;
begin
tell_on_call_stack;
a(p_a, l);
return l;
end c;
end callstack_demo;
UTL_CALL_STACK
• Functions for retrieving
– BACKTRACE:
• DEPTH, LINE and UNIT
– ERROR:
• DEPTH, MSG and NUMBER
– OWNER, SUBPROGRAM,
UNIT_LINE
– LEXICAL DEPTH (NESTING LEVEL)
DEFAULT
• Default applied (also) when NULL was explicitly specified
• Default based on Sequence
• Identity Column that is automatically assigned generated sequence
number value
• Meta Data Only Defaults
– Data applies to potentially many records but hard takes up any space – only some
meta-data are required to declaratively describe the data
alter table emp
modify (sal number(10,2)
DEFAULT ON NULL 1000
)
alter table emp
modify (empno number(5) NOT NULL
DEFAULT ON NULL EMPNO_SEQ.NEXTVAL
)
The Top-3 Earning Employees
• What can you say about the result of this query with respect to the
question: "Who are our top three earning employees?"
A. Correct Answer
B. Sometimes correct
C. Correct if there are never duplicate
salaries
D. Not Correct
In-Line Views
TOP-N Queries in 12c
• Last part of a query to be evaluated – to fetch only selected rows from
the result set:
– To select the next set of rows (pagination):
select *
from emp
order
by sal desc
FETCH FIRST 3 ROWS ONLY;
select *
from emp
order
by sal desc
OFFSET 3 FETCH NEXT 4 ROWS ONLY;
Pagination is just a convenient
syntax…
• OFFSET and FETCH NEXT are replaced by optimizer with Analytic
Functions such as ROW_NUMBER()
c##tkyte%CDB1> select /*+ first_rows(5) */ owner, object_name, object_id
2 from t
3 order by owner, object_name
4 OFFSET 5 ROWS FETCH NEXT 5 ROWS ONLY;
…
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 1450 | 7 (0)| 00:00:01 |
|* 1 | VIEW | | 5 | 1450 | 7 (0)| 00:00:01 |
|* 2 | WINDOW NOSORT STOPKEY | | 5 | 180 | 7 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| T | 87310 | 3069K| 7 (0)| 00:00:01 |
| 4 | INDEX FULL SCAN | T_IDX | 5 | | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("from$_subquery$_003"."rowlimit_$$_rownumber"<=CASE WHEN (5>=0)
THEN 5 ELSE 0 END +5 AND "from$_subquery$_003"."rowlimit_$$_rownumber">5)
2 - filter(ROW_NUMBER() OVER ( ORDER BY "OWNER","OBJECT_NAME")<=CASE WHEN
(5>=0) THEN 5 ELSE 0 END +5)
BOTTOM-N QUERY in 12c
• Return only the last three rows in the ordered result set (in the proper
order)
– or:
select *
from emp
order
by sal desc
OFFSET ((select count(*) from emp)-3) ROWS
FETCH NEXT 3 ROWS ONLY
select *
from ( select *
from emp
order
by sal asc
FETCH FIRST 3 ROWS ONLY
)
order
by sal desc;
TOP-n% querying
• To query for a percentage of the result set (rather than an absolute
number of rows)
• And the next batch
select *
from emp
order
by sal desc
FETCH FIRST 30 PERCENT ROWS ONLY;
select *
from emp
order
by sal desc
OFFSET (0.3*(select count(*) from emp)) ROWS
FETCH NEXT (0.3*(select count(*) from emp)) ROWS
ONLY;
Apply for joining
• APPLY is used to join with a Collection
• The function employees_in_department
returns a collection (TABLE OF
VARCHAR2 in this case)
• The function takes the DEPTNO value
from the DEPT records as input
• Only when the returned collection is not
empty will the DEPT record be produced
by this join
• Use OUTER APPLY to get a result row
even for an empty collection
SELECT *
FROM DEPT d
CROSS APPLY
employees_in_department(deptno) staff
DDDD
OUTER Apply for joining
• APPLY is used to join with a Collection
• With OUTER APPLY, each DEPT record is
produced at least once
– depending on the collection
returned by the function for
the DEPT record, multiple
joins may be produced
SELECT *
FROM DEPT d
OUTER APPLY
employees_in_department(deptno) staff
Data Masking
Data Redaction
• At runtime, you can optionally have the query results modified to
reset/scramble/randomize sensitive data
– Through ‘data redaction’ policies associated with tables and view and applied at
query time
• Because the data is masked in real-time, Data Redaction is well suited to
environments in which data is constantly changing.
• You can create the Data Redaction policies in one central location and
easily manage them from there.
SQL
engine SQL
POLICY
POLICY
RESULTS
My first Data redaction policy
• Access to DBMS_REDACT package
• Create Data Redaction Policy for SAL column in EMP table – hide salaries
from view
• Find that querying EMP has changed forever…
– Note: the expression can be used to dynamically decide whether or not to apply the policy
grant execute on dbms_redact to scott;
BEGIN
DBMS_REDACT.ADD_POLICY(
object_schema => 'scott',
object_name => 'emp',
column_name => 'sal',
policy_name => 'hide_salary',
function_type => DBMS_REDACT.FULL,
expression => '1=1' );
END;
Querying EMP with DATA
REDACTION in place
• Note: drop Redaction Policy
DBMS_REDACT.DROP_POLICY
( object_schema => 'scott'
, object_name => 'emp'
, policy_name => 'hide_salary'
);
Partial Column masking – mask
Day and month from hiredate
BEGIN
DBMS_REDACT.ADD_POLICY(
object_schema => 'scott',
object_name => 'emp',
column_name => 'hiredate',
policy_name => 'partially mask hiredate',
expression => 'SYS_CONTEXT(''USERENV'',''SESSION_USER'')!= ''GOD'''
function_type => DBMS_REDACT.PARTIAL,
function_parameters => 'm1d31YHMS',
expression => '1=1'
);
END;
More Security stuff…
Security
Real Application Security
57
White List
• A white list of allowed invokers can be defined for a PL/SQL unit
– supports the robust implementation of a module, consisting of a main unit and
helper units, by allowing the helper units to be inaccessible from anywhere
except the unit they are intended to help.
accessible by clause
package Helper authid Definer accessible by (Good_Guy, Bad_Guy)
is
procedure p;
end Helper;
package body Good_Guy is
procedure p is
begin
Helper.p();
...
end p;
end Good_Guy;
package body Bad_Guy is
procedure p is
begin
Helper.p();
...
end p;
end Bad_Guy;
PLS-00904: insufficient privilege to access object HELPER
_______
View with invoker’s rights
• As of Oracle Database Release 12c, a view can be either
– BEQUEATH DEFINER (the default), which behaves like a Definer’s Rights unit
(functions in the view are executed using the view owner’s rights)
– or BEQUEATH CURRENT_USER, which behaves somewhat like an invoker’s rights
unit (functions in the view are executed using the current user’s rights)
create or replace view managers
( name, sal, deptno, experience)
BEQUEATH CURRENT_USER
as
select ename, sal, deptno, some_function(hiredate)
from emp
where job = ‘MANAGER’
61
(More) Security related
features
• Attach database roles to the program units functions, procedures,
packages, and types.
– The role then becomes enabled during execution of the program unit (but not during
compilation of the program unit).
– This feature enables you to temporarily escalate privileges in the PL/SQL code
without granting the role directly to the user. The benefit of this feature is that it
increases security for applications and helps to enforce the principle of least
privilege.
• An Invoker's Rights Function Can Be Result-Cached
• READ privilege to allow SELECT but no SELECT FOR UPDATE
• A new built-in namespace, SYS_SESSION_ROLES, allows you to
determine if a specified role is enabled for the querying user
GRANT clerk_admin TO procedure scott.process_salaries;
SYS_SESSION_ROLES
• A new built-in namespace, SYS_SESSION_ROLES, allows you to
determine if a specified role is enabled for the querying user.
• The following example determines if the DBA role is enabled for user OE:
CONNECT OE/password
SELECT SYS_CONTEXT('SYS_SESSION_ROLES', 'DBA')
FROM DUAL;
SYS_CONTEXT('SYS_SESSION_ROLES','DBA')
--------
FALSE
Audit the real privilege
requirements of an application
• Objective: restrict privileges for a role to those that are really required for
using an application
• A privilege capture displays privilege usage for a database according to a
specified condition
– such as privileges to run an application module
– or privileges used in a given user session.
• When a user performs an action and you want to monitor the privileges
that are used for this action, you can create a privilege capture to capture
privilege usage.
• Afterwards, you can view a report that describes the behavior the privilege
capture defined.
– The privilege capture includes both system privileges and object privileges.
• Part of Database Vault option
Inherit or not in Invoker rights
program units
• When a user runs an invoker's rights procedure (or program unit), it runs
with the privileges of the invoking user.
• As the procedure runs, the procedure’s owner temporarily has access to
the invoking user's privileges.
• [If the procedure owner has fewer privileges than an invoking user,] the
procedure owner could use the invoking user’s privileges to perform
operations
procedure
owner
Invoker’s rights
invoker
procedure Special_
Table
Tap_
Table
65
New privilege:
INHERIT PRIVILEGES
• To be used for owners of (schemas with) Invoker’s Rights PL/SQL
program units
• Invoker’s rights procedure executions only can run with the privileges of
the invoker if the procedure’s owner has the INHERIT PRIVILEGES
privilege on the invoker (do not stealthily use invoker’s privileges as
owner)
– or if the procedure’s owner has the INHERIT ANY PRIVILEGES privilege
GRANT INHERIT PRIVILEGES
ON USER invoking_user
TO procedure_owner
REVOKE INHERIT PRIVILEGES ON invoking_user
FROM procedure_owner;
Pattern Matching
67
Raw Data Refinement
based on pattern matching
14,0
16,1
14,1
16,1
16,0
13,1
14,0
16,0
13,1
13,0
14,1
16,0
14,1
13,0
14,1
16,0
13,1
14,0
Processing
• Information
• Conclusion
• Alert
• Recommendation
• Action
Who is afraid of Red, Yellow
and blue
• Table Events
– Column Seq number(5)
– Column Payload varchar2(200)
Solution using Lead
• With LEAD it is easy to compare a row with its successor(s)
– As long as the pattern is fixed, LEAD will suffice
with look_ahead_events as
( SELECT e.*
, lead(payload) over (order by seq) next_color
, lead(payload,2) over (order by seq) second_next_color
FROM events e
)
select seq
from look_ahead_events
where payload ='red'
and next_color ='yellow'
and second_next_color='blue'
Find the pattern red, yellow and
blue
• Using the new 12c Match Recognize operator for finding patterns in
relational data
SELECT *
FROM events
MATCH_RECOGNIZE
(
ORDER BY seq
MEASURES RED.seq AS redseq
, MATCH_NUMBER() AS match_num
ALL ROWS PER MATCH
PATTERN (RED YELLOW BLUE)
DEFINE
RED AS RED.payload ='red',
YELLOW AS YELLOW.payload ='yellow',
BLUE AS BLUE.payload ='blue'
) MR
ORDER
BY MR.redseq
, MR.seq;
Match_recognize for finding
patterns in relational data
• The expression MATCH_RECOGNIZE provides native SQL support to
find patterns in sequences of rows
• Match_recognize returns Measures for selected (pattern matched) rows
– Similar to MODEL clause
• Match Conditions are expressed in columns from the Table Source,
aggregate functions and pattern functions FIRST, PREV, NEXT, LAST
• Patterns are regular expressions using match conditions to express a
special sequence of rows satisfying the conditions
Table
Source
&
Where
Match_
Recognize
Process
and Filter
Select &
Order By
Did we ever consecutively hire
three employees in the same job?
• Find a string of three subsequent hires where each hire has the same job
• Order by hiredate, pattern is two records that each have the same job as
their predecessor
SELECT *
FROM EMP
MATCH_RECOGNIZE
(
ORDER BY hiredate
MEASURES SAME_JOB.hiredate AS hireday
, MATCH_NUMBER() AS match_num
ALL ROWS PER MATCH
PATTERN (SAME_JOB{3})
DEFINE
SAME_JOB AS SAME_JOB.job = FIRST(SAME_JOB.job)
) MR
Pattern clause is a regular
expression
• Supported operators for the pattern clause include:
– * for 0 or more iterations
– + for 1 or more iterations
– ? for 0 or 1 iterations
– { n } for exactly n iterations (n > 0)
– { n, } for n or more iterations (n >= 0)
– { n, m } for between n and m (inclusive) iterations (0 <= n <= m, 0 < m)
– { , m } for between 0 and m (inclusive) iterations (m > 0)
– reluctant qualifiers - *?, +?, ??, {n}?, {n,}?, { n, m }?, {,m}?
– | for alternation (OR)
– grouping using () parentheses
– exclusion using {- and -}
– empty pattern using ()
– ^ and $ for start and end of a partition
Two steps forward… and one
step back
• Common expression … common pattern as well?
• Investigate salary evolution
– using Flashback Query and Match_Recognize
match_recognize (
partition by empno
order by the_time
MEASURES MATCH_NUMBER() AS match_num
, classifier() as match_role
ALL ROWS PER MATCH
PATTERN (STRT UP UP DOWN )
DEFINE UP as UP.sal > PREV(UP.SAL)
, DOWN as DOWN.SAL < PREV(DOWN.SAL)
) MR
Two steps forward… and one
step backwith sal_history as
( select empno
, ename
, sal
, nvl(versions_starttime, versions_endtime) the_time
from emp versions between timestamp minvalue and maxvalue
)
select *
from sal_history
match_recognize (
partition by empno
order by the_time
MEASURES MATCH_NUMBER() AS match_num
, classifier() as match_role
ALL ROWS PER MATCH
PATTERN (STRT UP UP DOWN )
DEFINE UP as UP.sal > PREV(UP.SAL)
, DOWN as DOWN.SAL < PREV(DOWN.SAL)
) MR
Find the longest sequence of
related observations
• Records are ordered
• Each record is qualified: assigned
to a certain category
• Examples:
– Voting records
– Ball possession in football
– Days with or without rain
– Passing vehicles (make and model
or category)
– DNA records
• The challenge: find the longest string
of consecutive observations in
the same category
Find the longest sequence of
related observations
SELECT section_category
, section_start
FROM observations
MATCH_RECOGNIZE
(
ORDER BY seq
MEASURES SAME_CATEGORY.category as section_category
, FIRST(SAME_CATEGORY.seq) as section_start
ONE ROW PER MATCH
PATTERN (SAME_CATEGORY* DIFFERENT_CATEGORY) -- as many times as possible
DEFINE
SAME_CATEGORY AS SAME_CATEGORY.category = FIRST(SAME_CATEGORY.category)
, DIFFERENT_CATEGORY AS DIFFERENT_CATEGORY.category !=
NEXT(DIFFERENT_CATEGORY.category)
) MR
order
by rows_in_section desc
)
Suppose we allow a single
interruption of a sequence
• One record with a different category
will not end the sequence – it might after
all be a fluke or an incident
• Rewrite the pattern match
to also accept one entry
with a different category
ONE ROW PER MATCH
AFTER MATCH SKIP TO NEXT ROW
-- a next row in the current match may be start of a next string
PATTERN (SAME_CATEGORY* DIFFERENT_CATEGORY{0,1} SAME_CATEGORY* )
DEFINE
SAME_CATEGORY AS SAME_CATEGORY.category = FIRST(SAME_CATEGORY.category)
, DIFFERENT_CATEGORY AS DIFFERENT_CATEGORY.category !=
SAME_CATEGORY.category
Find sequence (with one accepted
interruption) from all records
SELECT substr(section_category,1,1) cat
, section_start
, seq
FROM observations
MATCH_RECOGNIZE
( ORDER BY seq
MEASURES SAME_CATEGORY.category as section_category
, FIRST(SAME_CATEGORY.seq) as section_start
, seq as seq
ONE ROW PER MATCH
AFTER MATCH SKIP TO NEXT ROW -- a next row in the current match may be
-- start of a next string
PATTERN (SAME_CATEGORY* DIFFERENT_CATEGORY{0,1} SAME_CATEGORY* )
DEFINE
SAME_CATEGORY AS SAME_CATEGORY.category = FIRST(SAME_CATEGORY.category)
, DIFFERENT_CATEGORY AS DIFFERENT_CATEGORY.category !=
SAME_CATEGORY.category
) MR
order
by rows_in_section desc
87
Summary
Security
Scripts can be downloaded from https://github.com/lucasjellema/OracleDatabase12c-development-demonstration
Default
88
89

More Related Content

What's hot

OWB11gR2 - Extending ETL
OWB11gR2 - Extending ETL OWB11gR2 - Extending ETL
OWB11gR2 - Extending ETL Suraj Bang
 
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File ServerUKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File ServerMarco Gralike
 
BGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index StrategiesBGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index StrategiesMarco Gralike
 
Mindmap: Oracle to Couchbase for developers
Mindmap: Oracle to Couchbase for developersMindmap: Oracle to Couchbase for developers
Mindmap: Oracle to Couchbase for developersKeshav Murthy
 
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Marco Gralike
 
JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...Anatole Tresch
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJosé Paumard
 
Oracle Database 11g Release 2 - XMLDB New Features
Oracle Database 11g Release 2 - XMLDB New FeaturesOracle Database 11g Release 2 - XMLDB New Features
Oracle Database 11g Release 2 - XMLDB New FeaturesMarco Gralike
 
XFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in thereXFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in thereMarco Gralike
 
Couchbase N1QL: Language & Architecture Overview.
Couchbase N1QL: Language & Architecture Overview.Couchbase N1QL: Language & Architecture Overview.
Couchbase N1QL: Language & Architecture Overview.Keshav Murthy
 
Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Patrycja Wegrzynowicz
 
BGOUG 2012 - Design concepts for xml applications that will perform
BGOUG 2012 - Design concepts for xml applications that will performBGOUG 2012 - Design concepts for xml applications that will perform
BGOUG 2012 - Design concepts for xml applications that will performMarco Gralike
 
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...Marco Gralike
 
whats New in axapta 2012
whats New in axapta 2012whats New in axapta 2012
whats New in axapta 2012H B Kiran
 
Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...
Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...
Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...InSync2011
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...Marco Gralike
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPHP Barcelona Conference
 

What's hot (20)

OWB11gR2 - Extending ETL
OWB11gR2 - Extending ETL OWB11gR2 - Extending ETL
OWB11gR2 - Extending ETL
 
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File ServerUKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
 
BGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index StrategiesBGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index Strategies
 
Mindmap: Oracle to Couchbase for developers
Mindmap: Oracle to Couchbase for developersMindmap: Oracle to Couchbase for developers
Mindmap: Oracle to Couchbase for developers
 
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
 
JSR 354 LJC-Hackday
JSR 354 LJC-HackdayJSR 354 LJC-Hackday
JSR 354 LJC-Hackday
 
JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) Bridge
 
Oracle Database 11g Release 2 - XMLDB New Features
Oracle Database 11g Release 2 - XMLDB New FeaturesOracle Database 11g Release 2 - XMLDB New Features
Oracle Database 11g Release 2 - XMLDB New Features
 
XFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in thereXFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in there
 
Couchbase N1QL: Language & Architecture Overview.
Couchbase N1QL: Language & Architecture Overview.Couchbase N1QL: Language & Architecture Overview.
Couchbase N1QL: Language & Architecture Overview.
 
Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1
 
BGOUG 2012 - Design concepts for xml applications that will perform
BGOUG 2012 - Design concepts for xml applications that will performBGOUG 2012 - Design concepts for xml applications that will perform
BGOUG 2012 - Design concepts for xml applications that will perform
 
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
 
Postgresql
PostgresqlPostgresql
Postgresql
 
whats New in axapta 2012
whats New in axapta 2012whats New in axapta 2012
whats New in axapta 2012
 
Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...
Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...
Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi Mensah
 

Similar to Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c for database developers

Everything That Is Really Useful in Oracle Database 12c for Application Devel...
Everything That Is Really Useful in Oracle Database 12c for Application Devel...Everything That Is Really Useful in Oracle Database 12c for Application Devel...
Everything That Is Really Useful in Oracle Database 12c for Application Devel...Lucas Jellema
 
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Red Hat Developers
 
Webinar: What's New in Solr 6
Webinar: What's New in Solr 6Webinar: What's New in Solr 6
Webinar: What's New in Solr 6Lucidworks
 
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...NoSQLmatters
 
Optimizer percona live_ams2015
Optimizer percona live_ams2015Optimizer percona live_ams2015
Optimizer percona live_ams2015Manyi Lu
 
Expose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridExpose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridVinay Kumar
 
Native JSON Support in SQL2016
Native JSON Support in SQL2016Native JSON Support in SQL2016
Native JSON Support in SQL2016Ivo Andreev
 
SQL for Web APIs - Simplifying Data Access for API Consumers
SQL for Web APIs - Simplifying Data Access for API ConsumersSQL for Web APIs - Simplifying Data Access for API Consumers
SQL for Web APIs - Simplifying Data Access for API ConsumersJerod Johnson
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for CassandraEdward Capriolo
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"DataStax Academy
 
REST Enabling Your Oracle Database
REST Enabling Your Oracle DatabaseREST Enabling Your Oracle Database
REST Enabling Your Oracle DatabaseJeff Smith
 
Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQLjeykottalam
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuseejlp12
 
Spark streaming , Spark SQL
Spark streaming , Spark SQLSpark streaming , Spark SQL
Spark streaming , Spark SQLYousun Jeong
 
Building Robust ETL Pipelines with Apache Spark
Building Robust ETL Pipelines with Apache SparkBuilding Robust ETL Pipelines with Apache Spark
Building Robust ETL Pipelines with Apache SparkDatabricks
 

Similar to Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c for database developers (20)

Everything That Is Really Useful in Oracle Database 12c for Application Devel...
Everything That Is Really Useful in Oracle Database 12c for Application Devel...Everything That Is Really Useful in Oracle Database 12c for Application Devel...
Everything That Is Really Useful in Oracle Database 12c for Application Devel...
 
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
 
Webinar: What's New in Solr 6
Webinar: What's New in Solr 6Webinar: What's New in Solr 6
Webinar: What's New in Solr 6
 
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
 
Optimizer percona live_ams2015
Optimizer percona live_ams2015Optimizer percona live_ams2015
Optimizer percona live_ams2015
 
Expose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridExpose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug Madrid
 
Native JSON Support in SQL2016
Native JSON Support in SQL2016Native JSON Support in SQL2016
Native JSON Support in SQL2016
 
SQL for Web APIs - Simplifying Data Access for API Consumers
SQL for Web APIs - Simplifying Data Access for API ConsumersSQL for Web APIs - Simplifying Data Access for API Consumers
SQL for Web APIs - Simplifying Data Access for API Consumers
 
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
 
User Group3009
User Group3009User Group3009
User Group3009
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
 
REST Enabling Your Oracle Database
REST Enabling Your Oracle DatabaseREST Enabling Your Oracle Database
REST Enabling Your Oracle Database
 
Google cloud Dataflow & Apache Flink
Google cloud Dataflow & Apache FlinkGoogle cloud Dataflow & Apache Flink
Google cloud Dataflow & Apache Flink
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
 
Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQL
 
Naver_alternative_to_jpa
Naver_alternative_to_jpaNaver_alternative_to_jpa
Naver_alternative_to_jpa
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuse
 
Spark streaming , Spark SQL
Spark streaming , Spark SQLSpark streaming , Spark SQL
Spark streaming , Spark SQL
 
Building Robust ETL Pipelines with Apache Spark
Building Robust ETL Pipelines with Apache SparkBuilding Robust ETL Pipelines with Apache Spark
Building Robust ETL Pipelines with Apache Spark
 

More from 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
 

More from 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 ...
 

Recently uploaded

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 

Recently uploaded (20)

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 

Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c for database developers

  • 1. Lucas Jellema Singapore Oracle Sessions III - 14th July 2015 What is truly relevant for database developers in Oracle Database 12c
  • 2. The Presenter: Lucas Jellema • Lives in The Netherlands (close to Amsterdam) • Started doing Oracle in 1994 with Oracle Consulting (Oracle Designer, Forms, Database) • Joined AMIS in 2002 – now working as CTO, Consultant (Architect, Technical Lead, Programmer) and Trainer • Oracle ACE (2005) & ACE Director (2006) • Author of ‘Oracle SOA Suite 11g Handbook’ (Oracle Press, 2010), ‘Oracle SOA Suite 12c Handbook’ (2015) • Presenter at Oracle OpenWorld, JavaOne and many Oracle and Java User Group Conferences • Frequent blogger at http://technology.amis.nl • Active with SQL & PL/SQL, Java EE & ADF, SOA, BPM & more Fusion Middleware
  • 3. 3 Oracle Database 12c = • Multitenant Architecture aka Pluggable Database
  • 4. 4 Oracle Database 12c – 12.1.0.2 = • In-Memory Database Option
  • 5. 5 Oracle Database 12c for Database Developers
  • 6. JavaScript Object Notation Lightweight data-interchange format Support in Oracle Database 12c – 12.1.0.2
  • 8. Name : Value, Name : Value, Name : Value
  • 9. Name : Value, Name : Value, Name : Value Name : Value, Name : Value, Name : Value Name : Value, Name : Value, Name : Value , ,
  • 10. { "NAME" :"ACCOUNTING" , "EMPLOYEES" : [ {"ENAME" : "KING", "JOB" : "PRESIDENT", "SAL" : 5000 }, {"ENAME" : "MILLER", "JOB" : "CLERK", "SAL" : 1300 }] }
  • 12. 12 JSON • Light Weight, Structured, fairly tied coupled (low bandwidth) interactions between application[component]s • Very popular in rich client web applications and mobile apps – usually as the format used in REST-services • Oracle Database 12c is JSON aware – Store documents (in a column VARCHAR2, CLOB, NCLOB, BLOB, RAW, BFILE – and have them checked for JSON validity – Create Indexes on JSON contents – Access JSON content directly from SQL queries – Note: similar to but only a subset of XML support in Oracle Database (as JSON in terms of functionality is a somewhat pale subset of XML) • Oracle Driver for Node.js – similar to JBDC, all in JSON alter table X add CONSTRAINT ensure_json_chk CHECK (column_y IS JSON))
  • 13. 13 JSON in the Oracle Database • Why JSON in relational database? – Consistency (integrity, transaction ACIDity) for storing JSON documents – Quickly interpret data received (and stored?) in JSON format – Leverage JSON as a convenient way to handle structured data as a string – Easy data transfer over some protocols, including HTTP – especially when database engages directly in HTTP interactions
  • 14. 14 A sample JSON document {"matches": [ {"matchLineUp": "NED-ESP" , "score": "5-2" ,"matchDate":"13-06-2014" } , {"matchLineUp": "SWI-FRA" , "score": "2-5" ,"matchDate":"20-06-2014" } , {"matchLineUp": "GER-BRA" , "score": "1-7" ,"matchDate":"08-07-2014" } ] }
  • 15. 15 Check for a valid JSON document and/or path result • IS JSON can be used in the WHERE clause to filter on rows that contain a valid JSON document – It can be used in CHECK Constraints for that same reason • JSON_EXISTS is typically used in the WHERE clause to filter on rows whose JSON content satisfies some JSON path condition select * from customers where json_exists(doc, '$.addresses.privateAddress') select * from customers where doc IS JSON
  • 16. 16 JSON_VALUE to retrieve scalar value from JSON document • JSON_VALUE is a SQL Function used to retrieve a scalar value from a JSON document – JSON_VALUE can be used like any other SQL Function in queries and DML – in various clauses like SELECT, WHERE, GROUP BY, etc. select json_value ( '{"matches": [ {"matchLineUp": "NED-ESP" , "score": "5-2","matchDate":"13-06-2014"} , {"matchLineUp": "SWI-FRA" , "score": "2-5","matchDate":"20-06-2014"} , {"matchLineUp": "GER-BRA" , "score": "1-7","matchDate":"08-07-2014"} ] }' , '$.matches[1].score') as "2nd_match_score" from dual
  • 17. 17 JSON_QUERY to retrieve JSON- snippets from a JSON document select json_query ( '{"matches": [ {"matchLineUp": "NED-ESP" , "score": "5-2","matchDate":"13-06-2014"} , {"matchLineUp": "SWI-FRA" , "score": "2-5","matchDate":"20-06-2014"} , {"matchLineUp": "GER-BRA" , "score": "1-7","matchDate":"08-07-2014"} ] }' , $.matches[*].score' WITH WRAPPER) as scores from dual • JSON_QUERY is a SQL Function used to retrieve a JSON snippet from a JSON document - the result is a string that contains valid JSON – Use WRAPPER to wrap an Array result in an object to return a valid document
  • 18. 18 JSON_TABLE to expose records from a JSON document relationally with match_results as ( select '...' json_doc from dual) select lineUp, score , to_date(matchDate, 'DD-MM-YYYY') matchDate from match_results , json_table( json_doc, '$.matches[*]' COLUMNS ( lineUp varchar2(20) PATH '$.matchLineUp' , score varchar2(20) PATH '$.score' , matchDate varchar2(20) PATH '$.matchDate' ) ) • JSON_TABLE is used in the FROM clause of SQL statements to project data from a JSON document as a virtual relation view – JSON_TABLE is very similar to XML_TABLE
  • 19. 19 12.1.0.2 – JSON What it does not do? • Support for variable strings as JSON_PATH in JSON-functions • Deal with JSON in PL/SQL – JSON_VALUE and JSON_QUERY cannot be used directly from PL/SQL • Construct JSON documents – Not supported: conversion from ADT (to XMLType) to JSON type and vice versa – Not supported: a SQL/JSON syntax similar to SQL/XML for querying together a JSON document – Not supported: facilities that inject JSON into RESTful Services implemented through the PL/SQL Embedded Gateway Types OBJECTS, NESTED TABLE XMLType
  • 20. The PL/JSON library • This library has been around for several years – and is still pretty much relevant • Especially useful – For composing JSON documents – And for converting back and forth from and to JSON to XMLType and ADT/UDT
  • 22. In-line PL/SQL Functions and procedures • Procedures are also allowed in-line • In-Line Functions and Procedures can invoke each other WITH procedure increment( operand in out number , incsize in number) is begin operand:= operand + incsize; end; FUNCTION inc(value number) RETURN number IS l_value number(10):= value; BEGIN increment(l_value, 100); RETURN l_value; end; SELECT inc(sal) from emp
  • 23. In-line PL/SQL Functions and procedures • In-Line Functions and Procedures can invoke each other – And themselves (recursively) WITH FUNCTION inc(value number) RETURN number IS BEGIN if value < 6000 then return inc(value+100); else return value + 100; END if; end; SELECT inc(sal) from emp
  • 24. Dynamic (PL/)SQL is allowed inside inline functions • EXECUTE IMMEDIATE can be used inside an inline PL/SQL function to dynamically construct and execute SQL and PL/SQL WITH FUNCTION EMP_ENRICHER(operand varchar2) RETURN varchar2 IS sql_stmt varchar2(500); job varchar2(500); BEGIN sql_stmt := 'SELECT job FROM emp WHERE ename = :param'; EXECUTE IMMEDIATE sql_stmt INTO job USING operand; RETURN ' has job '||job; END; SELECT ename || EMP_ENRICHER(ename) from emp Note: do not try this at home! It is a horrible query! (looks too much like POST_QUERY for comfort) In-Line PL/SQL is not an excuse for lousy SQL
  • 25. Combining in-line Views and PL/SQL Functions & Procedures WITH procedure camel(p_string in out varchar2) is begin p_string:= initcap(p_string); end; function obfuscate(p_string in varchar2) return varchar2 is l_string varchar2(100); begin l_string:= translate(upper(p_string), 'AEUIO','OIEUA'); camel(l_string); return l_string; end; my_view as ( select obfuscate('Goedemorgen') from dual ) select * from my_view
  • 26. PL/SQL Functions That Run Faster in SQL • As of Oracle Database Release 12c, two kinds of PL/SQL functions might run faster in SQL: – PL/SQL functions that are defined in the WITH clauses of SQL SELECT statements, described in Oracle Database SQL Language Reference – PL/SQL functions that are defined with the "UDF Pragma" • Pragma UDF means: compile in the ‘SQL way’ as to eliminate SQL  PL/SQL context switch FUNCTION inc(string VARCHAR2) RETURN VARCHAR2 IS PRAGMA UDF; value number(10):= to_number(string); BEGIN if value < 6000 then return inc(value+100); else return to_char(value + 100); end if; end; SQL PLSQL SQL plsql plsql
  • 28. SQL Statement Preprocessor • A mechanism to allow the text of a SQL statement, submitted from a client program (e.g. via ODBC or JDBC), to be translated by user-supplied code before it is submitted to the Oracle Database SQL compiler. – Positioned to allow 3rd party apps to (better) run against Oracle Database – Additionally, any other use case where it is useful to intervene between the SQL statement that the client submits and what is actually executed – Some associations: VPD policies, Data Redaction, MV query rewrite, Advanced Query Rewrite, Temporal Validity (time slice) Application SQLPre proce ssor SQL engine SQL
  • 29. SQL Translation – set up AS SYS: grant create sql translation profile to oow; grant alter session to oow; AS Application Owner: -- Create a Translation Profile exec dbms_sql_translator.create_profile('HR_PROFILE'); BEGIN DBMS_SQL_TRANSLATOR.REGISTER_SQL_TRANSLATION( profile_name => 'HR_PROFILE', sql_text => 'select ename, job, hiredate from emp', translated_text => 'select initcap(ename) as ename , job, hiredate from emp where job<>''MANAGER'' ‘ ); END; select * FROM USER_SQL_TRANSLATION_PROFILES; select * from USER_SQL_TRANSLATIONS;
  • 30. SQL Translation – in action -- to enable the profile (usually in logon trigger) alter session set sql_translation_profile = HR_PROFILE -- to pretend we are a foreign application, subject to -- SQL Translation alter session set events = '10601 trace name context forever, level 32'; -- execute query that is to be translated select ename, job, hiredate from emp -- results are produced as if the translated text had been submitted SQLPre proce ssor SQL engine SQL
  • 31. 32 SQL Translation • Support for bind parameters • Support for rewriting PL/SQL calls • Translation of Error Messages (ORA-xxxx to SYB-yyyy or YOURAPP-zzz) • Out of the box translators for Sybase, SQL Server and some DB2 • Optionally: register a custom translator package – PROCEDURE TRANSLATE_SQL( sql_text IN CLOB, translated_text OUT CLOB);
  • 33. 35 • Maximum length for VARCHAR2 is now 32KB (up from 4KB) • Invisible Columns • One unified audit trail • PL/SQL DBMS_UTILITY.EXPAND_SQL_TEXT can be used to uncover the real SQL executed for a given query – Expressed only in the underlying base tables, including VPD policies • Export View as Table with Data Pump – fine grained projection of columns and rows that will be part of the Dump and subsequent Import • Creation of multiple indexes on same set of columns is allowed – Although only one can be live at any one time • Cross PDB queries
  • 34. API for inspecting the PL/SQL callstack • New PL/SQL Package UTL_CALL_STACK provides API for inspecting the PL/SQL Callstack – Complements the DBMS_ UTILITY.FORMAT_CALL_STACK that returns a pretty print human readable overview of the callstack procedure tell_on_call_stack is l_prg_uqn UTL_CALL_STACK.UNIT_QUALIFIED_NAME; begin dbms_output.put_line('==== TELL ON CALLSTACK ==== ' ||UTL_CALL_STACK.DYNAMIC_DEPTH ); for i in 1..UTL_CALL_STACK.DYNAMIC_DEPTH loop l_prg_uqn := UTL_CALL_STACK.SUBPROGRAM(i); dbms_output.put_line( l_prg_uqn(1) ||' line '||UTL_CALL_STACK.UNIT_LINE(i) ||' ' ||UTL_Call_Stack.Concatenate_Subprogram ( UTL_Call_Stack.Subprogram(i)) ); end loop; end tell_on_call_stack;
  • 35. API for inspecting the PL/SQL callstack create or replace package body callstack_demo as function b( p1 in number, p2 in number) return number is l number:=1; begin tell_on_call_stack; return l; end b; procedure a ( p1 in number, p2 out number) is begin tell_on_call_stack; for i in 1..p1 loop p2:= b(i, p1); end loop; end a; function c( p_a in number) return number is l number; begin tell_on_call_stack; a(p_a, l); return l; end c; end callstack_demo;
  • 36. UTL_CALL_STACK • Functions for retrieving – BACKTRACE: • DEPTH, LINE and UNIT – ERROR: • DEPTH, MSG and NUMBER – OWNER, SUBPROGRAM, UNIT_LINE – LEXICAL DEPTH (NESTING LEVEL)
  • 37. DEFAULT • Default applied (also) when NULL was explicitly specified • Default based on Sequence • Identity Column that is automatically assigned generated sequence number value • Meta Data Only Defaults – Data applies to potentially many records but hard takes up any space – only some meta-data are required to declaratively describe the data alter table emp modify (sal number(10,2) DEFAULT ON NULL 1000 ) alter table emp modify (empno number(5) NOT NULL DEFAULT ON NULL EMPNO_SEQ.NEXTVAL )
  • 38. The Top-3 Earning Employees • What can you say about the result of this query with respect to the question: "Who are our top three earning employees?" A. Correct Answer B. Sometimes correct C. Correct if there are never duplicate salaries D. Not Correct
  • 40. TOP-N Queries in 12c • Last part of a query to be evaluated – to fetch only selected rows from the result set: – To select the next set of rows (pagination): select * from emp order by sal desc FETCH FIRST 3 ROWS ONLY; select * from emp order by sal desc OFFSET 3 FETCH NEXT 4 ROWS ONLY;
  • 41. Pagination is just a convenient syntax… • OFFSET and FETCH NEXT are replaced by optimizer with Analytic Functions such as ROW_NUMBER() c##tkyte%CDB1> select /*+ first_rows(5) */ owner, object_name, object_id 2 from t 3 order by owner, object_name 4 OFFSET 5 ROWS FETCH NEXT 5 ROWS ONLY; … --------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | 1450 | 7 (0)| 00:00:01 | |* 1 | VIEW | | 5 | 1450 | 7 (0)| 00:00:01 | |* 2 | WINDOW NOSORT STOPKEY | | 5 | 180 | 7 (0)| 00:00:01 | | 3 | TABLE ACCESS BY INDEX ROWID| T | 87310 | 3069K| 7 (0)| 00:00:01 | | 4 | INDEX FULL SCAN | T_IDX | 5 | | 3 (0)| 00:00:01 | --------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("from$_subquery$_003"."rowlimit_$$_rownumber"<=CASE WHEN (5>=0) THEN 5 ELSE 0 END +5 AND "from$_subquery$_003"."rowlimit_$$_rownumber">5) 2 - filter(ROW_NUMBER() OVER ( ORDER BY "OWNER","OBJECT_NAME")<=CASE WHEN (5>=0) THEN 5 ELSE 0 END +5)
  • 42. BOTTOM-N QUERY in 12c • Return only the last three rows in the ordered result set (in the proper order) – or: select * from emp order by sal desc OFFSET ((select count(*) from emp)-3) ROWS FETCH NEXT 3 ROWS ONLY select * from ( select * from emp order by sal asc FETCH FIRST 3 ROWS ONLY ) order by sal desc;
  • 43. TOP-n% querying • To query for a percentage of the result set (rather than an absolute number of rows) • And the next batch select * from emp order by sal desc FETCH FIRST 30 PERCENT ROWS ONLY; select * from emp order by sal desc OFFSET (0.3*(select count(*) from emp)) ROWS FETCH NEXT (0.3*(select count(*) from emp)) ROWS ONLY;
  • 44. Apply for joining • APPLY is used to join with a Collection • The function employees_in_department returns a collection (TABLE OF VARCHAR2 in this case) • The function takes the DEPTNO value from the DEPT records as input • Only when the returned collection is not empty will the DEPT record be produced by this join • Use OUTER APPLY to get a result row even for an empty collection SELECT * FROM DEPT d CROSS APPLY employees_in_department(deptno) staff DDDD
  • 45. OUTER Apply for joining • APPLY is used to join with a Collection • With OUTER APPLY, each DEPT record is produced at least once – depending on the collection returned by the function for the DEPT record, multiple joins may be produced SELECT * FROM DEPT d OUTER APPLY employees_in_department(deptno) staff
  • 47. Data Redaction • At runtime, you can optionally have the query results modified to reset/scramble/randomize sensitive data – Through ‘data redaction’ policies associated with tables and view and applied at query time • Because the data is masked in real-time, Data Redaction is well suited to environments in which data is constantly changing. • You can create the Data Redaction policies in one central location and easily manage them from there. SQL engine SQL POLICY POLICY RESULTS
  • 48. My first Data redaction policy • Access to DBMS_REDACT package • Create Data Redaction Policy for SAL column in EMP table – hide salaries from view • Find that querying EMP has changed forever… – Note: the expression can be used to dynamically decide whether or not to apply the policy grant execute on dbms_redact to scott; BEGIN DBMS_REDACT.ADD_POLICY( object_schema => 'scott', object_name => 'emp', column_name => 'sal', policy_name => 'hide_salary', function_type => DBMS_REDACT.FULL, expression => '1=1' ); END;
  • 49. Querying EMP with DATA REDACTION in place • Note: drop Redaction Policy DBMS_REDACT.DROP_POLICY ( object_schema => 'scott' , object_name => 'emp' , policy_name => 'hide_salary' );
  • 50. Partial Column masking – mask Day and month from hiredate BEGIN DBMS_REDACT.ADD_POLICY( object_schema => 'scott', object_name => 'emp', column_name => 'hiredate', policy_name => 'partially mask hiredate', expression => 'SYS_CONTEXT(''USERENV'',''SESSION_USER'')!= ''GOD''' function_type => DBMS_REDACT.PARTIAL, function_parameters => 'm1d31YHMS', expression => '1=1' ); END;
  • 53. White List • A white list of allowed invokers can be defined for a PL/SQL unit – supports the robust implementation of a module, consisting of a main unit and helper units, by allowing the helper units to be inaccessible from anywhere except the unit they are intended to help.
  • 54. accessible by clause package Helper authid Definer accessible by (Good_Guy, Bad_Guy) is procedure p; end Helper; package body Good_Guy is procedure p is begin Helper.p(); ... end p; end Good_Guy; package body Bad_Guy is procedure p is begin Helper.p(); ... end p; end Bad_Guy; PLS-00904: insufficient privilege to access object HELPER _______
  • 55. View with invoker’s rights • As of Oracle Database Release 12c, a view can be either – BEQUEATH DEFINER (the default), which behaves like a Definer’s Rights unit (functions in the view are executed using the view owner’s rights) – or BEQUEATH CURRENT_USER, which behaves somewhat like an invoker’s rights unit (functions in the view are executed using the current user’s rights) create or replace view managers ( name, sal, deptno, experience) BEQUEATH CURRENT_USER as select ename, sal, deptno, some_function(hiredate) from emp where job = ‘MANAGER’
  • 56. 61 (More) Security related features • Attach database roles to the program units functions, procedures, packages, and types. – The role then becomes enabled during execution of the program unit (but not during compilation of the program unit). – This feature enables you to temporarily escalate privileges in the PL/SQL code without granting the role directly to the user. The benefit of this feature is that it increases security for applications and helps to enforce the principle of least privilege. • An Invoker's Rights Function Can Be Result-Cached • READ privilege to allow SELECT but no SELECT FOR UPDATE • A new built-in namespace, SYS_SESSION_ROLES, allows you to determine if a specified role is enabled for the querying user GRANT clerk_admin TO procedure scott.process_salaries;
  • 57. SYS_SESSION_ROLES • A new built-in namespace, SYS_SESSION_ROLES, allows you to determine if a specified role is enabled for the querying user. • The following example determines if the DBA role is enabled for user OE: CONNECT OE/password SELECT SYS_CONTEXT('SYS_SESSION_ROLES', 'DBA') FROM DUAL; SYS_CONTEXT('SYS_SESSION_ROLES','DBA') -------- FALSE
  • 58. Audit the real privilege requirements of an application • Objective: restrict privileges for a role to those that are really required for using an application • A privilege capture displays privilege usage for a database according to a specified condition – such as privileges to run an application module – or privileges used in a given user session. • When a user performs an action and you want to monitor the privileges that are used for this action, you can create a privilege capture to capture privilege usage. • Afterwards, you can view a report that describes the behavior the privilege capture defined. – The privilege capture includes both system privileges and object privileges. • Part of Database Vault option
  • 59. Inherit or not in Invoker rights program units • When a user runs an invoker's rights procedure (or program unit), it runs with the privileges of the invoking user. • As the procedure runs, the procedure’s owner temporarily has access to the invoking user's privileges. • [If the procedure owner has fewer privileges than an invoking user,] the procedure owner could use the invoking user’s privileges to perform operations procedure owner Invoker’s rights invoker procedure Special_ Table Tap_ Table
  • 60. 65 New privilege: INHERIT PRIVILEGES • To be used for owners of (schemas with) Invoker’s Rights PL/SQL program units • Invoker’s rights procedure executions only can run with the privileges of the invoker if the procedure’s owner has the INHERIT PRIVILEGES privilege on the invoker (do not stealthily use invoker’s privileges as owner) – or if the procedure’s owner has the INHERIT ANY PRIVILEGES privilege GRANT INHERIT PRIVILEGES ON USER invoking_user TO procedure_owner REVOKE INHERIT PRIVILEGES ON invoking_user FROM procedure_owner;
  • 62. 67 Raw Data Refinement based on pattern matching 14,0 16,1 14,1 16,1 16,0 13,1 14,0 16,0 13,1 13,0 14,1 16,0 14,1 13,0 14,1 16,0 13,1 14,0 Processing • Information • Conclusion • Alert • Recommendation • Action
  • 63. Who is afraid of Red, Yellow and blue • Table Events – Column Seq number(5) – Column Payload varchar2(200)
  • 64. Solution using Lead • With LEAD it is easy to compare a row with its successor(s) – As long as the pattern is fixed, LEAD will suffice with look_ahead_events as ( SELECT e.* , lead(payload) over (order by seq) next_color , lead(payload,2) over (order by seq) second_next_color FROM events e ) select seq from look_ahead_events where payload ='red' and next_color ='yellow' and second_next_color='blue'
  • 65. Find the pattern red, yellow and blue • Using the new 12c Match Recognize operator for finding patterns in relational data SELECT * FROM events MATCH_RECOGNIZE ( ORDER BY seq MEASURES RED.seq AS redseq , MATCH_NUMBER() AS match_num ALL ROWS PER MATCH PATTERN (RED YELLOW BLUE) DEFINE RED AS RED.payload ='red', YELLOW AS YELLOW.payload ='yellow', BLUE AS BLUE.payload ='blue' ) MR ORDER BY MR.redseq , MR.seq;
  • 66. Match_recognize for finding patterns in relational data • The expression MATCH_RECOGNIZE provides native SQL support to find patterns in sequences of rows • Match_recognize returns Measures for selected (pattern matched) rows – Similar to MODEL clause • Match Conditions are expressed in columns from the Table Source, aggregate functions and pattern functions FIRST, PREV, NEXT, LAST • Patterns are regular expressions using match conditions to express a special sequence of rows satisfying the conditions Table Source & Where Match_ Recognize Process and Filter Select & Order By
  • 67. Did we ever consecutively hire three employees in the same job? • Find a string of three subsequent hires where each hire has the same job • Order by hiredate, pattern is two records that each have the same job as their predecessor SELECT * FROM EMP MATCH_RECOGNIZE ( ORDER BY hiredate MEASURES SAME_JOB.hiredate AS hireday , MATCH_NUMBER() AS match_num ALL ROWS PER MATCH PATTERN (SAME_JOB{3}) DEFINE SAME_JOB AS SAME_JOB.job = FIRST(SAME_JOB.job) ) MR
  • 68. Pattern clause is a regular expression • Supported operators for the pattern clause include: – * for 0 or more iterations – + for 1 or more iterations – ? for 0 or 1 iterations – { n } for exactly n iterations (n > 0) – { n, } for n or more iterations (n >= 0) – { n, m } for between n and m (inclusive) iterations (0 <= n <= m, 0 < m) – { , m } for between 0 and m (inclusive) iterations (m > 0) – reluctant qualifiers - *?, +?, ??, {n}?, {n,}?, { n, m }?, {,m}? – | for alternation (OR) – grouping using () parentheses – exclusion using {- and -} – empty pattern using () – ^ and $ for start and end of a partition
  • 69. Two steps forward… and one step back • Common expression … common pattern as well? • Investigate salary evolution – using Flashback Query and Match_Recognize match_recognize ( partition by empno order by the_time MEASURES MATCH_NUMBER() AS match_num , classifier() as match_role ALL ROWS PER MATCH PATTERN (STRT UP UP DOWN ) DEFINE UP as UP.sal > PREV(UP.SAL) , DOWN as DOWN.SAL < PREV(DOWN.SAL) ) MR
  • 70. Two steps forward… and one step backwith sal_history as ( select empno , ename , sal , nvl(versions_starttime, versions_endtime) the_time from emp versions between timestamp minvalue and maxvalue ) select * from sal_history match_recognize ( partition by empno order by the_time MEASURES MATCH_NUMBER() AS match_num , classifier() as match_role ALL ROWS PER MATCH PATTERN (STRT UP UP DOWN ) DEFINE UP as UP.sal > PREV(UP.SAL) , DOWN as DOWN.SAL < PREV(DOWN.SAL) ) MR
  • 71. Find the longest sequence of related observations • Records are ordered • Each record is qualified: assigned to a certain category • Examples: – Voting records – Ball possession in football – Days with or without rain – Passing vehicles (make and model or category) – DNA records • The challenge: find the longest string of consecutive observations in the same category
  • 72. Find the longest sequence of related observations SELECT section_category , section_start FROM observations MATCH_RECOGNIZE ( ORDER BY seq MEASURES SAME_CATEGORY.category as section_category , FIRST(SAME_CATEGORY.seq) as section_start ONE ROW PER MATCH PATTERN (SAME_CATEGORY* DIFFERENT_CATEGORY) -- as many times as possible DEFINE SAME_CATEGORY AS SAME_CATEGORY.category = FIRST(SAME_CATEGORY.category) , DIFFERENT_CATEGORY AS DIFFERENT_CATEGORY.category != NEXT(DIFFERENT_CATEGORY.category) ) MR order by rows_in_section desc )
  • 73. Suppose we allow a single interruption of a sequence • One record with a different category will not end the sequence – it might after all be a fluke or an incident • Rewrite the pattern match to also accept one entry with a different category ONE ROW PER MATCH AFTER MATCH SKIP TO NEXT ROW -- a next row in the current match may be start of a next string PATTERN (SAME_CATEGORY* DIFFERENT_CATEGORY{0,1} SAME_CATEGORY* ) DEFINE SAME_CATEGORY AS SAME_CATEGORY.category = FIRST(SAME_CATEGORY.category) , DIFFERENT_CATEGORY AS DIFFERENT_CATEGORY.category != SAME_CATEGORY.category
  • 74. Find sequence (with one accepted interruption) from all records SELECT substr(section_category,1,1) cat , section_start , seq FROM observations MATCH_RECOGNIZE ( ORDER BY seq MEASURES SAME_CATEGORY.category as section_category , FIRST(SAME_CATEGORY.seq) as section_start , seq as seq ONE ROW PER MATCH AFTER MATCH SKIP TO NEXT ROW -- a next row in the current match may be -- start of a next string PATTERN (SAME_CATEGORY* DIFFERENT_CATEGORY{0,1} SAME_CATEGORY* ) DEFINE SAME_CATEGORY AS SAME_CATEGORY.category = FIRST(SAME_CATEGORY.category) , DIFFERENT_CATEGORY AS DIFFERENT_CATEGORY.category != SAME_CATEGORY.category ) MR order by rows_in_section desc
  • 75. 87 Summary Security Scripts can be downloaded from https://github.com/lucasjellema/OracleDatabase12c-development-demonstration Default
  • 76. 88
  • 77. 89