SlideShare a Scribd company logo
1
Patrick.Barel@AMIS.nl
technology.amis.nl
blog.bar-solutions.com
2
• Patrick Barel
• Working with Oracle since 1997
• Working with PL/SQL since 1999
• Playing with APEX since 2003 (mod_plsql)
• ACE since 2011
• OCA since December 20th 2012
• OCP since February 20th 2014
• Developer Choice Award 2015
About me…
3
Read me…
http://blog.bar-solutions.com
http://technology.amis.nl
http://allthingsoracle.com
http://www.otechmag.com
4
Download me…
Plugins for PL/SQL Developer
http://bar-solutions.com
Plugins for Apex
http://apex-plugin.com
5
Watch me…
6
@patch72
Patrick Barel
3029156
40338721Patrick.Barel@GMail.com
patrick@bar-solutions.com
Patrick.Barel@GMail.com
Patrick.Barel@AMIS.nl
Contact me…
7
Patrick Barel, AMIS June 2, 2016
Get Your Moneys Worth Out Of Your Database
8
It doesn’t matter how many resources you have.
If you don’t know how to use them,
it will never be enough
9
Database
10
Data integrity/quality
11
Data integrity/quality
create table demo.emp_unprotected
(
empno number(4) not null
, ename varchar2(10)
, sal number(7,2)
, deptno number(2)
)
12
Data integrity/quality
insert into demo.emp_unprotected values (7369, 'SMITH', 800, 20);
insert into demo.emp_unprotected values (7499, 'ALLEN', 1600, 30);
insert into demo.emp_unprotected values (7521, 'WARD', 1250, 30);
insert into demo.emp_unprotected values (7566, 'JONES', 2975, 20);
…
insert into demo.emp_unprotected values (7900, 'JAMES', 950, 30);
insert into demo.emp_unprotected values (7902, 'FORD', 3000, 20);
insert into demo.emp_unprotected values (7934, 'MILLER', 1300, 10);
13
Data integrity/quality
update demo.emp_unprotected e
set e.sal = 2 * e.sal
• Salary not over 7500
• No duplicate
employee numbers
• Existing department
update demo.emp_unprotected e
set e.deptno = 50
where e.ename = 'SCOTT'
insert into demo.emp_unprotected
(empno, ename, sal, deptno)
values (7900, 'BAREL', 1000, 10)
14
Data integrity/quality
update demo.emp_protected e
set e.sal = 2 * e.sal
• Salary not over 7500
• No duplicate
employee numbers
• Existing department
update demo.emp_protected e
set e.deptno = 50
where e.ename = 'SCOTT'
insert into demo.emp_protected
(empno, ename, sal, deptno)
values (7900, 'BAREL', 1000, 10)
alter table demo.emp_protected add constraint sal_under_7500 check ((sal < 7500))
alter table demo.emp_protected add constraint pk_emp_protected primary key (empno)
alter table demo.emp_protected add constraint fk_emp_protected_dept
foreign key (deptno) references demo.dept (deptno)
dataintegrity.sql
15
Flashback queries
16
Flashback queries
create table emp_fb
(
empno NUMBER(4) not null,
ename VARCHAR2(10),
sal NUMBER(7,2),
deptno NUMBER(2)
)
17
Flashback queries
…
insert into emp_fb values (7782, 'CLARK', 2450, 10);
insert into emp_fb values (7788, 'SCOTT', 3000, 20);
insert into emp_fb values (7839, 'KING', 5000, 10);
insert into emp_fb values (7844, 'TURNER', 1500, 30);
insert into emp_fb values (7876, 'ADAMS', 1100, 20);
insert into emp_fb values (7900, 'JAMES', 950, 30);
insert into emp_fb values (7902, 'FORD', 3000, 20);
insert into emp_fb values (7934, 'MILLER', 1300, 10);
18
Flashback queries
select e.empno, e.ename, e.sal
from emp_fb e
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2650.00
7839 KING 5200.00
7934 MILLER 1500.00
19
Flashback queries
select e.empno, e.ename, e.sal
from emp_fb e
where e.deptno = 10
select e.empno, e.ename, e.sal
from emp_fb e
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2650.00
7839 KING 5200.00
7934 MILLER 1500.00
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2650.00
7839 KING 5200.00
7934 MILLER 1500.00
update emp_fb e
set e.sal = e.sal + 200
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2850.00
7839 KING 5400.00
7934 MILLER 1700.00
20
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2850.00
7839 KING 5400.00
7934 MILLER 1700.00
Flashback queries
select e.empno, e.ename, e.sal
from emp_fb e
where e.deptno = 10
select e.empno, e.ename, e.sal
from emp_fb e
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2650.00
7839 KING 5200.00
7934 MILLER 1500.00
update emp_fb e
set e.sal = e.sal + 200
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2850.00
7839 KING 5400.00
7934 MILLER 1700.00
commit
21
Flashback queries
…
insert into emp_fb values (7782, 'CLARK', 2450, 10);
insert into emp_fb values (7788, 'SCOTT', 3000, 20);
insert into emp_fb values (7839, 'KING', 5000, 10);
insert into emp_fb values (7844, 'TURNER', 1500, 30);
insert into emp_fb values (7876, 'ADAMS', 1100, 20);
insert into emp_fb values (7900, 'JAMES', 950, 30);
insert into emp_fb values (7902, 'FORD', 3000, 20);
insert into emp_fb values (7934, 'MILLER', 1300, 10);
truncate table emp_fb
22
Flashback queries
select e.empno, e.ename, e.sal
from emp_fb e
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2650.00
7839 KING 5200.00
7934 MILLER 1500.00
23
Flashback queries
select e.empno, e.ename, e.sal
from emp_fb e
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2650.00
7839 KING 5200.00
7934 MILLER 1500.00
update emp_fb e
set e.sal = e.sal + 200
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2850.00
7839 KING 5400.00
7934 MILLER 1700.00
24
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2850.00
7839 KING 5400.00
7934 MILLER 1700.00
Flashback queries
select e.empno, e.ename, e.sal
from emp_fb e
where e.deptno = 10
update emp_fb e
set e.sal = e.sal + 200
where e.deptno = 10
commit
25
Flashback queries
select e.empno, e.ename, e.sal
from demo.emp_fb
as of timestamp to_timestamp(sysdate - 1/(24*60*60)) e
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2650.00
7839 KING 5200.00
7934 MILLER 1500.00
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2850.00
7839 KING 5400.00
7934 MILLER 1700.00
26
Flashback queries
select e.empno, e.ename, e.sal
from demo.emp_fb
as of timestamp to_timestamp(sysdate - 1/(24*60*60)) e
where e.deptno = 10
EMPNO ENAME SAL
----- ---------- ---------
7782 CLARK 2650.00
7839 KING 5200.00
7934 MILLER 1500.00
select e.empno, e.ename, e.sal
from demo.emp_fb
as of scn 23352983 e
where e.deptno = 10
flashback_fb1.sql
flashback_fb2.sql
flashback_fb3.sql
27
Temporal validity
28
Temporal validity
create table demo.customers
( id number
, name varchar2(30)
, address varchar2(30)
)
29
Temporal validity
insert into demo.customers (id, name, address) values
(1, 'Patrick', '1 Oxford Street')
insert into demo.customers (id, name, address) values
(2, 'Steven', '57 Chicago Boulevard')
select * from demo.customers c
order by c.id
ID NAME ADDRESS
--- ------------------------- -------------------------
1 Patrick 1 Oxford Street
2 Steven 57 Chicago Boulevard
30
Temporal validity
update demo.customers c
set c.address = '1 Oracle Lane'
where c.id = 1
select * from demo.customers c
order by c.id
ID NAME ADDRESS
--- ------------------------- -------------------------
1 Patrick 1 Oracle Lane
2 Steven 57 Chicago Boulevard
31
Temporal validity
truncate table demo.customers
insert into demo.customers (id, name, address) values
(1, 'Patrick', '1 Oxford Street')
insert into demo.customers (id, name, address) values
(2, 'Steven', '57 Chicago Boulevard')
select * from demo.customers c
order by c.id
ID NAME ADDRESS
--- ------------------------- -------------------------
1 Patrick 1 Oxford Street
2 Steven 57 Chicago Boulevard
alter table demo.customers add period for valid_time
32
Temporal validity
truncate table demo.customers
insert into demo.customers (id, name, address) values
(1, 'Patrick', '1 Oxford Street')
insert into demo.customers (id, name, address) values
(2, 'Steven', '57 Chicago Boulevard')
ID NAME ADDRESS
--- ------------------------- -------------------------
1 Patrick 1 Oxford Street
2 Steven 57 Chicago Boulevard
select * from demo.customers c
order by c.id
alter table demo.customers add period for valid_time
33
Temporal validity
select c.id
, c.name
, c.address
, to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from
, to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till
from demo.customers c
order by c.id
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oxford Street
2 Steven 57 Chicago Boulevard
34
Temporal validity
select c.id
, c.name
, c.address
, to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from
, to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till
from demo.customers c
order by c.id
update demo.customers c
set c.valid_time_end = to_date('06012016 235959'
,'MMDDYYYY HH24MISS')
where c.id = 1
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oxford Street
2 Steven 57 Chicago Boulevard
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oxford Street 06-01-2016
2 Steven 57 Chicago Boulevard
35
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oxford Street 06-01-2016
1 Patrick 1 Oracle Lane 06-02-2016
2 Steven 57 Chicago Boulevard
Temporal validity
select c.id
, c.name
, c.address
, to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from
, to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till
from demo.customers c
order by c.id
update demo.customers c
set c.valid_time_end = to_date('06012016 235959'
,'MMDDYYYY HH24MISS')
where c.id = 1
insert into demo.customers(id, name, address, valid_time_start)
values (1,'Patrick','1 Oracle Lane',to_date('06022016','MMDDYYYY'))
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oxford Street 06-01-2016
2 Steven 57 Chicago Boulevard
36
Temporal validity
select c.id
, c.name
, c.address
, to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from
, to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till
from demo.customers c
order by c.id
exec dbms_flashback_archive.enable_at_valid_time('CURRENT')
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oracle Lane 06-02-2016
2 Steven 57 Chicago Boulevard
37
Temporal validity
select c.id
, c.name
, c.address
, to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from
, to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till
from demo.customers c
order by c.id
exec dbms_flashback_archive.enable_at_valid_time('CURRENT')
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oracle Lane 06-02-2016
2 Steven 57 Chicago Boulevard
exec dbms_flashback_archive.enable_at_valid_time('ASOF'
, to_date('06012016','MMDDYYYY'))
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oxford Street 06-01-2016
2 Steven 57 Chicago Boulevard
38
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oracle Lane 06-02-2016
2 Steven 57 Chicago Boulevard
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oxford Street 06-01-2016
2 Steven 57 Chicago Boulevard
Temporal validity
select c.id
, c.name
, c.address
, to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from
, to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till
from demo.customers c
order by c.id
exec dbms_flashback_archive.enable_at_valid_time('CURRENT')
exec dbms_flashback_archive.enable_at_valid_time('ASOF'
, to_date('06012016','MMDDYYYY'))
exec dbms_flashback_archive.enable_at_valid_time('ASOF'
, to_date('06022016','MMDDYYYY'))
39
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oxford Street 06-01-2016
1 Patrick 1 Oracle Lane 06-02-2016
2 Steven 57 Chicago Boulevard
ID NAME ADDRESS VALID_FROM VALID_TILL
--- ------------------------- ------------------------- ---------- ----------
1 Patrick 1 Oracle Lane 06-02-2016
2 Steven 57 Chicago Boulevard
Temporal validity
select c.id
, c.name
, c.address
, to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from
, to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till
from demo.customers c
order by c.id
exec dbms_flashback_archive.enable_at_valid_time('CURRENT')
exec dbms_flashback_archive.enable_at_valid_time('ASOF'
, to_date('06012016','MMDDYYYY'))
exec dbms_flashback_archive.enable_at_valid_time('ASOF'
, to_date('06022016','MMDDYYYY'))
exec dbms_flashback_archive.enable_at_valid_time('ALL')
temporal_validity.sql
40
Data security
41
Data redaction
SensitiveData
5555-5555-5555-4444
5105-1051-0510-5100
5111-1111-1111-1118
SensitiveData (Clear)
5555-5555-5555-4444
5105-1051-0510-5100
5111-1111-1111-1118
SensitiveData (Redacted)
XXXX-XXXX-XXXX-4444
XXXX-XXXX-XXXX-5100
XXXX-XXXX-XXXX-1118
42
Data redaction
create table SensitiveData (contract varchar2(23))
insert into SensitiveData(contract) values ('5555-5555-5555-4444');
insert into SensitiveData(contract) values ('5105-1051-0510-5100');
insert into SensitiveData(contract) values ('5111-1111-1111-1118');
43
Data redaction
begin
dbms_redact.add_policy(
object_schema => 'DEMO'
,object_name => 'SENSITIVEDATA'
,policy_name => 'PARTIALMASKDEMO'
,column_name => 'CONTACT'
,function_type => DBMS_REDACT.PARTIAL
,function_parameters =>
'VVVVFVVVVFVVVVFVVVV,VVVV-VVVV-VVVV-VVVV,X,1,12'
,expression =>
q'[SYS_CONTEXT ('USERENV', 'SESSION_USER') <> 'BU']');
end;
44
Data redaction
select * from demo.SensitiveData select * from demo.SensitiveData
CONTRACT
-----------------------
5555-5555-5555-4444
5105-1051-0510-5100
5111-1111-1111-1118
CONTRACT
-----------------------
XXXX-XXXX-XXXX-4444
XXXX-XXXX-XXXX-5100
XXXX-XXXX-XXXX-1118
redaction.sql
45
Virtual private database
46
Virtual private database
47
Virtual private database
create or replace function vpdfunc
(schemaname_in in varchar2
,tablename_in in varchar2) return varchar2
is
l_returnvalue varchar2(2000);
begin
case user
when 'BU' then l_returnvalue := 'DEPTNO in (10,30)';
when 'MP' then l_returnvalue := 'DEPTNO in (20,40)';
else l_returnvalue := '1=1';
end case;
return l_returnvalue;
end;
48
Virtual private database
begin
dbms_rls.add_policy(object_schema => 'DEMO'
,object_name => 'EMP_VPD'
,policy_name => 'VPDDEMO'
,function_schema => 'DEMO'
,policy_function => 'VPDFUNC');
end;
49
Virtual private database
begin
dbms_rls.add_policy(object_schema => 'DEMO'
,object_name => 'EMP_VPD'
,policy_name => 'VPDDEMO'
,function_schema => 'DEMO'
,policy_function => 'VPDFUNC');
end;
select empno, ename, deptno from demo.emp_vpd
EMPNO ENAME DEPTNO
----- ---------- ------
7499 ALLEN 30
…
7934 MILLER 10
9 rows selected
EMPNO ENAME DEPTNO
----- ---------- ------
7369 SMITH 20
…
7902 FORD 20
5 rows selected
VirtualPrivateDatabase.sql
50
Unified and
Conditional
Auditing
51
Performance increase
52
Query result cache
create table QueryResultCacheTable
( id number
)
53
Query result cache
insert into QueryResultCacheTable(id) values (1);
insert into QueryResultCacheTable(id) values (2);
insert into QueryResultCacheTable(id) values (3);
insert into QueryResultCacheTable(id) values (4);
insert into QueryResultCacheTable(id) values (5);
create or replace function veryslowfunction(id_in in
queryresultcachetable.id%type)
return queryresultcachetable.id%type as
begin
dbms_lock.sleep(1);
return id_in;
end;
set timing on
54
Query result cache
select VerySlowFunction(qrct.id)
from QueryResultCacheTable qrct
select /*+ result_cache */
veryslowfunction(qrct.id)
from queryresultcachetable qrct
select /*+ result_cache */
veryslowfunction(qrct.id)
from queryresultcachetable qrct
Executed in 5.88 seconds
Executed in 11.664 seconds
Executed in 0.035 seconds
55
Query result cache
create or replace function veryslowfunction(id_in in
queryresultcachetable.id%type)
return queryresultcachetable.id%type deterministic as
begin
dbms_lock.sleep(1);
return id_in;
end;
56
Query result cache
select /*+ result_cache */
veryslowfunction(qrct.id)
from queryresultcachetable qrct
select /*+ result_cache */
veryslowfunction(qrct.id)
from queryresultcachetable qrct
Executed in 5.507 seconds
Executed in 0.038 seconds
57
Query result cache
create table FunctionResultCacheTable
( id number
)
58
Query result cache
insert into FunctionResultCacheTable(id) values (1);
insert into FunctionResultCacheTable(id) values (2);
insert into FunctionResultCacheTable(id) values (3);
insert into FunctionResultCacheTable(id) values (1);
insert into FunctionResultCacheTable(id) values (2);
insert into FunctionResultCacheTable(id) values (3);
insert into FunctionResultCacheTable(id) values (1);
insert into FunctionResultCacheTable(id) values (2);
insert into FunctionResultCacheTable(id) values (3);
insert into FunctionResultCacheTable(id) values (1);
59
Query result cache
select veryslowfunction(frct.id)
from FunctionResultCacheTable frct
Elapsed: 00:00:10.18
create or replace function veryslowfunction(id_in in
FunctionResultCacheTable.id%type)
return FunctionResultCacheTable.id%type as
begin
dbms_lock.sleep(1);
return id_in;
end;
Elapsed: 00:00:10.28
60
create or replace function veryslowfunction(id_in in
FunctionResultCacheTable.id%type)
return FunctionResultCacheTable.id%type deterministic as
begin
dbms_lock.sleep(1);
return id_in;
end;
Query result cache
select veryslowfunction(frct.id)
from FunctionResultCacheTable frct
Elapsed: 00:00:10.18Elapsed: 00:00:10.28
Elapsed: 00:00:04.16Elapsed: 00:00:04.09
61
create or replace function veryslowfunction(id_in in
FunctionResultCacheTable.id%type)
return FunctionResultCacheTable.id%type result_cache as
begin
dbms_lock.sleep(1);
return id_in;
end;
Query result cache
select veryslowfunction(frct.id)
from FunctionResultCacheTable frct
Elapsed: 00:00:10.18Elapsed: 00:00:10.28
Elapsed: 00:00:04.16Elapsed: 00:00:04.09
Elapsed: 00:00:00.00Elapsed: 00:00:03.15
Elapsed: 00:00:00.00
VirtualPrivateDatabase.sql
62
63
Application Upgrade
64
Application Upgrade
65
Application Upgrade
66
Application Upgrade
67
Application Upgrade
68
Application Upgrade
Creation of new objects
Changing existing objects
Drop redundant objects
Convert / Migrate
Resume normal operation
69
70
(Non)Editionable Objects
Editionable Non-Editionable
Packages Tables
Procedures Materialized views
Functions DB Links
Triggers
Views
Types
Synonyms
71
Special SQL features
72
Retrieve the top-3 earning employees
Special SQL features
select e.empno
,e.ename
,e.sal
from demo.emp e
where rownum < 4
order by e.sal desc
EMPNO ENAME SAL
----- ---------- ---------
7499 ALLEN 1600.00
7521 WARD 1250.00
7369 SMITH 800.00
73
Retrieve the top-3 earning employees
Special SQL features
select e.empno
,e.ename
,e.sal
from (select e2.empno
,e2.ename
,e2.sal
from demo.emp e2
order by e2.sal desc) e
where rownum < 4
EMPNO ENAME SAL
----- ---------- ---------
7839 KING 5000.00
7788 SCOTT 3000.00
7902 FORD 3000.00
select e.empno
,e.ename
,e.sal
from demo.emp e
where rownum < 4
order by e.sal desc
EMPNO ENAME SAL
----- ---------- ---------
7499 ALLEN 1600.00
7521 WARD 1250.00
7369 SMITH 800.00
74
Retrieve the top-3 earning employees
Special SQL features
with orderedbysal as
(select e.empno
,e.ename
,e.sal
from demo.emp e
order by e.sal desc)
select obs.empno
,obs.ename
,obs.sal
from orderedbysal obs
where rownum < 4
select e.empno
,e.ename
,e.sal
from demo.emp e
order by e.sal desc
fetch first 3 rows only
EMPNO ENAME SAL
----- ---------- ---------
7839 KING 5000.00
7788 SCOTT 3000.00
7902 FORD 3000.00
EMPNO ENAME SAL
----- ---------- ---------
7839 KING 5000.00
7788 SCOTT 3000.00
7902 FORD 3000.00
select e.empno
,e.ename
,e.sal
from (select e2.empno
,e2.ename
,e2.sal
from demo.emp e2
order by e2.sal desc) e
where rownum < 4
Syntax Candy
this
is rewritten as
75
Retrieve the next 3 topearning employees
Special SQL features
with orderedbysal as
(select e.empno
,e.ename
,e.sal
,rownum rn
from demo.emp e
order by e.sal desc)
select obs.empno
,obs.ename
,obs.sal
from orderedbysal obs
where obs.rn between 4 and 6
order by obs.rn
EMPNO ENAME SAL
----- ---------- ---------
7566 JONES 2975.00
7654 MARTIN 1250.00
7698 BLAKE 2850.00
76
Retrieve the next 3 topearning employees
Special SQL features
with orderedbysal as
(select e.empno
,e.ename
,e.sal
from demo.emp e
order by e.sal desc)
, orderedwithrownum as
(select obs.empno
, obs.ename
, obs.sal
, rownum rn
from orderedbysal obs)
select obr.empno
,obr.ename
,obr.sal
from orderedwithrownum obr
where obr.rn between 4 and 6
order by obr.rn
select e.empno
,e.ename
,e.sal
from demo.emp e
order by e.sal desc
offset 3 rows
fetch next 3 rows only
EMPNO ENAME SAL
----- ---------- ---------
7566 JONES 2975.00
7698 BLAKE 2850.00
7782 CLARK 2450.00
EMPNO ENAME SAL
----- ---------- ---------
7566 JONES 2975.00
7698 BLAKE 2850.00
7782 CLARK 2450.00
with orderedbysal as
(select e.empno
,e.ename
,e.sal
,rownum rn
from demo.emp e
order by e.sal desc)
select obs.empno
,obs.ename
,obs.sal
from orderedbysal obs
where obs.rn between 4 and 6
order by obs.rn
EMPNO ENAME SAL
----- ---------- ---------
7566 JONES 2975.00
7654 MARTIN 1250.00
7698 BLAKE 2850.00
paginating.sql
77
Build PL/SQL in SQL
Special SQL features
create or replace function wavey(string_in in varchar2)
return varchar2
is
l_returnvalue varchar2(30);
begin
for indx in 1 .. length(string_in) loop
l_returnvalue := l_returnvalue ||
case mod(indx, 2)
when 0 then upper(substr(string_in, indx, 1))
else lower(substr(string_in, indx, 1))
end;
end loop;
return l_returnvalue;
end;
Function created
78
Build PL/SQL in SQL
Special SQL features
select e.empno, e.ename, wavey(e.ename) wavey_ename, e.sal
from demo.emp e
EMPNO ENAME WAVEY_ENAME SAL
----- ---------- ------------ ---------
7369 SMITH sMiTh 800.00
7499 ALLEN aLlEn 1600.00
7521 WARD wArD 1250.00
7566 JONES jOnEs 2975.00
7654 MARTIN mArTiN 1250.00
7698 BLAKE bLaKe 2850.00
7782 CLARK cLaRk 2450.00
7788 SCOTT sCoTt 3000.00
7839 KING kInG 5000.00
7844 TURNER tUrNeR 1500.00
7876 ADAMS aDaMs 1100.00
7900 JAMES jAmEs 950.00
7902 FORD fOrD 3000.00
7934 MILLER mIlLeR 1300.00
14 rows selected
79
Special SQL features
with function wavey(string_in in varchar2) return varchar2
is
l_returnvalue varchar2(30);
begin
for indx in 1 .. length(string_in) loop
l_returnvalue := l_returnvalue ||
case mod(indx, 2)
when 1 then upper(substr(string_in, indx, 1))
else lower(substr(string_in, indx, 1))
end;
end loop;
return l_returnvalue;
end;
select e.empno, e.ename, wavey(e.ename) wavey_ename, e.sal
from demo.emp e
EMPNO ENAME WAVEY_ENAME SAL
----- ---------- ------------ ---------
7369 SMITH SmItH 800.00
7499 ALLEN AlLeN 1600.00
…
7934 MILLER MiLlEr 1300.00
14 rows selected
plsql_in_with.sql
80
81
Virtual Columns
82
Virtual Columns
create table demo.emp_income
(
empno number(4) not null
, ename varchar2(10)
, sal number(7,2)
, comm number(7,2)
, deptno number(2)
, income number(7,2)
generated always as
(demo.emp_income.sal +
coalesce(demo.emp_income.comm,0)) virtual
)
83
Virtual Columns
insert into demo.emp_income(empno, ename, sal, deptno, comm)
values (7499, 'ALLEN', 1600, 30, 300);
insert into demo.emp_income(empno, ename, sal, deptno, comm)
values (7521, 'WARD', 1250, 30, 500);
insert into demo.emp_income(empno, ename, sal, deptno, comm)
values (7654, 'MARTIN', 1250, 30, 1400);
insert into demo.emp_income(empno, ename, sal, deptno, comm)
values (7698, 'BLAKE', 2850, 30, null);
insert into demo.emp_income(empno, ename, sal, deptno, comm)
values (7844, 'TURNER', 1500, 30, 0);
insert into demo.emp_income(empno, ename, sal, deptno, comm)
values (7900, 'JAMES', 950, 30, null);
84
Virtual Columns
EMPNO ENAME SAL COMM DEPTNO INCOME
------ ---------- --------- --------- ------- ---------
7499 ALLEN 1600.00 300.00 30 1900.00
7521 WARD 1250.00 500.00 30 1750.00
7654 MARTIN 1250.00 1400.00 30 2650.00
7698 BLAKE 2850.00 30 2850.00
7844 TURNER 1500.00 .00 30 1500.00
7900 JAMES 950.00 30 950.00
6 rows selected.
select *
from demo.emp_income e
VirtualColumnIncome.sql
85
Virtual Columns
create table demo.emp_nuke
(
empno number(4) not null
, ename varchar2(10)
, sal number(7,2)
, deptno number(2)
, blowitup number generated always as (1/0) virtual
)
86
Virtual Columns
insert into demo.emp_nuke(empno, ename, sal, deptno)
values (7499, 'ALLEN', 1600, 30);
insert into demo.emp_nuke(empno, ename, sal, deptno)
values (7521, 'WARD', 1250, 30);
insert into demo.emp_nuke(empno, ename, sal, deptno)
values (7654, 'MARTIN', 1250, 30);
insert into demo.emp_nuke(empno, ename, sal, deptno)
values (7698, 'BLAKE', 2850, 30);
insert into demo.emp_nuke(empno, ename, sal, deptno)
values (7844, 'TURNER', 1500, 30);
insert into demo.emp_nuke(empno, ename, sal, deptno)
values (7900, 'JAMES', 950, 30);
87
Virtual Columns
select *
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
select *
from demo.emp_nuke e
88
Virtual Columns
EMPNO ENAME SAL DEPTNO
------ ---------- --------- -------
7499 ALLEN 1600.00 30
7521 WARD 1250.00 30
7654 MARTIN 1250.00 30
7698 BLAKE 2850.00 30
7844 TURNER 1500.00 30
7900 JAMES 950.00 30
6 rows selected.
select e.empno, e.ename, e.sal, e.deptno
from demo.emp_nuke e
VirtualColumnPreventSelectStar.sql
90
Identity columns (12c)
91
Identity columns (12c)
create table tablewithuniquecolumn
( theuniquecolumn number(10) not null
, foo varchar2(30)
, bar varchar2(30)
)
92
Identity columns (12c)
create sequence sequenceforuniquecolumn start with 1 nocache
93
Identity columns (12c)
create or replace trigger makesureitsfilled
before insert or update on tablewithuniquecolumn
for each row
begin
if :new.theuniquecolumn is null then
select sequenceforuniquecolumn.nextval
into :new.theuniquecolumn
from dual;
end if;
end;
94
Identity columns (12c)
create or replace trigger makesureitsfilled
before insert or update on tablewithuniquecolumn
for each row
begin
if :new.theuniquecolumn is null then
:new.theuniquecolumn := sequenceforuniquecolumn.nextval;
end if;
end;
95
Identity columns (12c)
create table tablewithidentitycolumn
( theidentitycolumn number(10) generated always as identity
, foo varchar2(30)
, bar varchar2(30)
)
identity_columns.sql
96
Identity columns (12c)
97
Invisible columns (12c)
98
Invisible columns (12c)
create table Show
( I varchar2(30)
, am varchar2(30)
, the varchar2(30)
, invisible varchar2(30)
, man varchar2(30)
)
99
Invisible columns (12c)
select * from show
I AM THE INVISIBLE MAN
- -- --- --------- ---
I am the invisible man
100
Invisible columns (12c)
select * from show
I AM THE INVISIBLE MAN
- -- --- --------- ---
I am the invisible man
alter table show modify invisible invisible
101
Invisible columns (12c)
select * from show
I AM THE INVISIBLE MAN
- -- --- --------- ---
I am the invisible man
alter table show modify invisible invisible
I AM THE MAN
- -- --- ---
I am the man
102
Invisible columns (12c)
select * from show
I AM THE INVISIBLE MAN
- -- --- --------- ---
I am the invisible man
alter table show modify invisible invisible
I AM THE MAN
- -- --- ---
I am the man
select I, am, the, invisible, man
from show
IAmTheInvisibleColumn.sql
103
Whitelisting PL/SQL program units
104
Whitelisting PL/SQL program units
105
Whitelisting PL/SQL program units
create or replace procedure onlywhitelisted
accessible by (normalprocedure)
is
begin
dbms_output.put_line('You are allowed');
end;
106
Whitelisting PL/SQL program units
create or replace procedure onlywhitelisted
accessible by (normalprocedure)
is
begin
dbms_output.put_line('You are allowed');
end;
create or replace procedure
normalprocedure
is
begin
dbms_output.put_line
('normalprocedure calls
onlywhitelisted');
onlywhitelisted;
end;
107
Whitelisting PL/SQL program units
create or replace procedure onlywhitelisted
accessible by (normalprocedure)
is
begin
dbms_output.put_line('You are allowed');
end;
create or replace procedure
normalprocedure
is
begin
dbms_output.put_line
('normalprocedure calls
onlywhitelisted');
onlywhitelisted;
end;
create or replace procedure
evilprocedure
is
begin
dbms_output.put_line
('evilprocedure calls
onlywhitelisted');
onlywhitelisted;
end;
108
Whitelisting PL/SQL program units
create or replace procedure onlywhitelisted
accessible by (normalprocedure)
is
begin
dbms_output.put_line('You are allowed');
end;
create or replace procedure
normalprocedure
is
begin
dbms_output.put_line
('normalprocedure calls
onlywhitelisted');
onlywhitelisted;
end;
create or replace procedure
evilprocedure
is
begin
dbms_output.put_line
('evilprocedure calls
onlywhitelisted');
onlywhitelisted;
end;
create or replace procedure
evilprocedure
is
begin
dbms_output.put_line
('evilprocedure calls
normalprocedure');
normalprocedure;
end;
whitelisting_12c.sql
109
110
111
• Data integrity/quality
• http://www.riparteilfuturo.it/assets/articles/images/429e6a
270817213e33647f1344cb121f.jpeg
• No Matter How Much
– https://pbs.twimg.com/profile_images/4392957816027340
80/WwHn8tUM.jpeg
Credits
• Database
– https://www.oracle.com/engineered-
systems/products.html
112
• Flashback queries
– https://insiderhema.files.wordpress.com/2015/07/the-
time-desktop-background-496046.jpg
Credits
• Data security
– http://tr1.cbsistatic.com/hub/i/2016/02/25/f1cab87f-0b42-
4700-945e-
898a5f90898b/32c0dc0f18610d2a9eddc85b19bdce81/hack
er6.jpg
• Temporal validity
– http://blogs.discovermagazine.com/crux/files/2014/01/tim
e-travel.jpg
113
• Performance increase
– http://www.adelhi.com/wp-
content/uploads/2015/10/result.adelhi.jpg
Credits
• Edition Based Redefinition
– http://www.psychedelictribe.com/wp-
content/uploads/parallel-universe-image.jpg
• Why Downtime matters?
– http://image.slidesharecdn.com/wed1240yahooshahegashi
ra-150424124356-conversion-gate01/95/oozie-towards-
zero-downtime-12-638.jpg?cb=1429897523
114
• Special SQL features
– https://geofrikphotos.files.wordpress.com/2012/12/paisaje
-marte.jpg
Credits
• Virtual Columns
– http://wallpaper.zone/img/1667098.jpg
• Pros Cons
– https://secure.surveymonkey.com/wp-
content/uploads/2014/10/Pros_Cons_NPS.jpg
115
• Identity columns (12c)
– http://www.cambridgedove.com/Pages/images/020/020titl
e2.gif
Credits
• Whitelisting PL/SQL program units
– http://www.pinpointe.com/blog/wp-
content/uploads/what-is-whitelisting-780x421.png
• Invisible columns (12c)
– https://hollywoodhatesme.files.wordpress.com/2012/07/in
visible-man.jpg
116
• Whitelisting PL/SQL program units
– http://www.ccs-
inc.com/images/uploads/Yes_No_Shutterstock_83547358.j
pg
Credits

More Related Content

What's hot

Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
Connor McDonald
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
Connor McDonald
 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
NETsolutions Asia: NSA – Thailand, Sripatum University: SPU
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
COIS 420 - Practice04
COIS 420 - Practice04COIS 420 - Practice04
COIS 420 - Practice04
Angel G Diaz
 
The Five Best Things To Happen To SQL
The Five Best Things To Happen To SQLThe Five Best Things To Happen To SQL
The Five Best Things To Happen To SQL
Connor McDonald
 
Comparative Genomics with GMOD and BioPerl
Comparative Genomics with GMOD and BioPerlComparative Genomics with GMOD and BioPerl
Comparative Genomics with GMOD and BioPerl
Jason Stajich
 
Les05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group FunctionLes05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group Function
NETsolutions Asia: NSA – Thailand, Sripatum University: SPU
 
Sangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLSangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQL
Connor McDonald
 
Redo logfile addition in oracle rac 12c
Redo logfile addition in oracle rac 12cRedo logfile addition in oracle rac 12c
Redo logfile addition in oracle rac 12c
Debasish Nayak
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
Connor McDonald
 
Les00 Intoduction
Les00 IntoductionLes00 Intoduction
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
Saurabh K. Gupta
 
Les12 creating views
Les12 creating viewsLes12 creating views
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
Connor McDonald
 
Les06 Subqueries
Les06 SubqueriesLes06 Subqueries
MH prediction modeling and validation in r (1) regression 190709
MH prediction modeling and validation in r (1) regression 190709MH prediction modeling and validation in r (1) regression 190709
MH prediction modeling and validation in r (1) regression 190709
Min-hyung Kim
 
Les02
Les02Les02

What's hot (20)

Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
Les02 Restricting And Sorting Data
 
COIS 420 - Practice04
COIS 420 - Practice04COIS 420 - Practice04
COIS 420 - Practice04
 
The Five Best Things To Happen To SQL
The Five Best Things To Happen To SQLThe Five Best Things To Happen To SQL
The Five Best Things To Happen To SQL
 
Comparative Genomics with GMOD and BioPerl
Comparative Genomics with GMOD and BioPerlComparative Genomics with GMOD and BioPerl
Comparative Genomics with GMOD and BioPerl
 
Les05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group FunctionLes05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group Function
 
Sangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLSangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQL
 
Redo logfile addition in oracle rac 12c
Redo logfile addition in oracle rac 12cRedo logfile addition in oracle rac 12c
Redo logfile addition in oracle rac 12c
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
Les00 Intoduction
Les00 IntoductionLes00 Intoduction
Les00 Intoduction
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
 
Les12 creating views
Les12 creating viewsLes12 creating views
Les12 creating views
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
Les06 Subqueries
Les06 SubqueriesLes06 Subqueries
Les06 Subqueries
 
MH prediction modeling and validation in r (1) regression 190709
MH prediction modeling and validation in r (1) regression 190709MH prediction modeling and validation in r (1) regression 190709
MH prediction modeling and validation in r (1) regression 190709
 
Les02
Les02Les02
Les02
 

Viewers also liked

Open source w admnistracji publicznej
Open source w admnistracji publicznejOpen source w admnistracji publicznej
Open source w admnistracji publicznej
Squiz Poland
 
161013 presentatie democratic challenge
161013 presentatie democratic challenge161013 presentatie democratic challenge
161013 presentatie democratic challenge
Tim Aarts
 
Kickstarter and Games - December 2012
Kickstarter and Games - December 2012Kickstarter and Games - December 2012
Kickstarter and Games - December 2012
ICO Partners
 
Future of Moodle
Future of MoodleFuture of Moodle
Future of Moodle
ITisART.Ltd
 
Review Paper: Developing 2D and 3D Cadastral Registration System based on LAD...
Review Paper: Developing 2D and 3D Cadastral Registration System based on LAD...Review Paper: Developing 2D and 3D Cadastral Registration System based on LAD...
Review Paper: Developing 2D and 3D Cadastral Registration System based on LAD...
National Cheng Kung University
 
Intermountain Healthcare Speech
Intermountain Healthcare SpeechIntermountain Healthcare Speech
Intermountain Healthcare Speech
Vicki Whiting
 
Business models trends - Game Connection America 2012
Business models trends - Game Connection America 2012Business models trends - Game Connection America 2012
Business models trends - Game Connection America 2012
ICO Partners
 
ICO Media - Media relations solution
ICO Media - Media relations solutionICO Media - Media relations solution
ICO Media - Media relations solution
ICO Partners
 
Manfaat dan pentingnya cuci tangan pakai sabun di
Manfaat dan pentingnya cuci tangan pakai sabun diManfaat dan pentingnya cuci tangan pakai sabun di
Manfaat dan pentingnya cuci tangan pakai sabun di
juniar44
 
Presentation2 cba case domino pizza
Presentation2 cba case domino pizzaPresentation2 cba case domino pizza
Presentation2 cba case domino pizza
Derarika Jesse
 
Producing for indies
Producing for indiesProducing for indies
Producing for indies
DevGAMM Conference
 
Accelerating Our Path to Multi Platform Benefits
Accelerating Our Path to Multi Platform BenefitsAccelerating Our Path to Multi Platform Benefits
Accelerating Our Path to Multi Platform Benefits
IT@Intel
 
Stop Crying Start Trying
Stop Crying Start Trying Stop Crying Start Trying
Stop Crying Start Trying
Bharat Vaghela
 
ABCDE
ABCDEABCDE
Jurupa talent mapping overview
Jurupa talent mapping overviewJurupa talent mapping overview
Jurupa talent mapping overview
Aaron Davies
 
Kebijakan penurunan aki akb dinas kesehatan provinsi sulawesi barat 27 11_2016
Kebijakan penurunan aki akb dinas kesehatan provinsi sulawesi barat 27 11_2016Kebijakan penurunan aki akb dinas kesehatan provinsi sulawesi barat 27 11_2016
Kebijakan penurunan aki akb dinas kesehatan provinsi sulawesi barat 27 11_2016
Muh Saleh
 
ИБ АСУ ТП NON-STOP. Серия 1. Архитектура и основные компоненты АСУ ТП с точки...
ИБ АСУ ТП NON-STOP. Серия 1. Архитектура и основные компоненты АСУ ТП с точки...ИБ АСУ ТП NON-STOP. Серия 1. Архитектура и основные компоненты АСУ ТП с точки...
ИБ АСУ ТП NON-STOP. Серия 1. Архитектура и основные компоненты АСУ ТП с точки...
Компания УЦСБ
 
STUDI TENTANG PENGUKURAN DAN PEMETAAN KADASTRAL PADA PELAKSANAAN PRONA TAHUN ...
STUDI TENTANG PENGUKURAN DAN PEMETAAN KADASTRAL PADA PELAKSANAAN PRONA TAHUN ...STUDI TENTANG PENGUKURAN DAN PEMETAAN KADASTRAL PADA PELAKSANAAN PRONA TAHUN ...
STUDI TENTANG PENGUKURAN DAN PEMETAAN KADASTRAL PADA PELAKSANAAN PRONA TAHUN ...
National Cheng Kung University
 
Sistem pelayanan publik
Sistem pelayanan publikSistem pelayanan publik
Sistem pelayanan publikAria Suyudi
 

Viewers also liked (20)

Open source w admnistracji publicznej
Open source w admnistracji publicznejOpen source w admnistracji publicznej
Open source w admnistracji publicznej
 
161013 presentatie democratic challenge
161013 presentatie democratic challenge161013 presentatie democratic challenge
161013 presentatie democratic challenge
 
Kickstarter and Games - December 2012
Kickstarter and Games - December 2012Kickstarter and Games - December 2012
Kickstarter and Games - December 2012
 
Future of Moodle
Future of MoodleFuture of Moodle
Future of Moodle
 
Review Paper: Developing 2D and 3D Cadastral Registration System based on LAD...
Review Paper: Developing 2D and 3D Cadastral Registration System based on LAD...Review Paper: Developing 2D and 3D Cadastral Registration System based on LAD...
Review Paper: Developing 2D and 3D Cadastral Registration System based on LAD...
 
Intermountain Healthcare Speech
Intermountain Healthcare SpeechIntermountain Healthcare Speech
Intermountain Healthcare Speech
 
Business models trends - Game Connection America 2012
Business models trends - Game Connection America 2012Business models trends - Game Connection America 2012
Business models trends - Game Connection America 2012
 
ICO Media - Media relations solution
ICO Media - Media relations solutionICO Media - Media relations solution
ICO Media - Media relations solution
 
Manfaat dan pentingnya cuci tangan pakai sabun di
Manfaat dan pentingnya cuci tangan pakai sabun diManfaat dan pentingnya cuci tangan pakai sabun di
Manfaat dan pentingnya cuci tangan pakai sabun di
 
Presentation2 cba case domino pizza
Presentation2 cba case domino pizzaPresentation2 cba case domino pizza
Presentation2 cba case domino pizza
 
Producing for indies
Producing for indiesProducing for indies
Producing for indies
 
Accelerating Our Path to Multi Platform Benefits
Accelerating Our Path to Multi Platform BenefitsAccelerating Our Path to Multi Platform Benefits
Accelerating Our Path to Multi Platform Benefits
 
Stop Crying Start Trying
Stop Crying Start Trying Stop Crying Start Trying
Stop Crying Start Trying
 
ABCDE
ABCDEABCDE
ABCDE
 
Jurupa talent mapping overview
Jurupa talent mapping overviewJurupa talent mapping overview
Jurupa talent mapping overview
 
Kebijakan penurunan aki akb dinas kesehatan provinsi sulawesi barat 27 11_2016
Kebijakan penurunan aki akb dinas kesehatan provinsi sulawesi barat 27 11_2016Kebijakan penurunan aki akb dinas kesehatan provinsi sulawesi barat 27 11_2016
Kebijakan penurunan aki akb dinas kesehatan provinsi sulawesi barat 27 11_2016
 
ИБ АСУ ТП NON-STOP. Серия 1. Архитектура и основные компоненты АСУ ТП с точки...
ИБ АСУ ТП NON-STOP. Серия 1. Архитектура и основные компоненты АСУ ТП с точки...ИБ АСУ ТП NON-STOP. Серия 1. Архитектура и основные компоненты АСУ ТП с точки...
ИБ АСУ ТП NON-STOP. Серия 1. Архитектура и основные компоненты АСУ ТП с точки...
 
Profil puskesmas 2015
Profil puskesmas 2015Profil puskesmas 2015
Profil puskesmas 2015
 
STUDI TENTANG PENGUKURAN DAN PEMETAAN KADASTRAL PADA PELAKSANAAN PRONA TAHUN ...
STUDI TENTANG PENGUKURAN DAN PEMETAAN KADASTRAL PADA PELAKSANAAN PRONA TAHUN ...STUDI TENTANG PENGUKURAN DAN PEMETAAN KADASTRAL PADA PELAKSANAAN PRONA TAHUN ...
STUDI TENTANG PENGUKURAN DAN PEMETAAN KADASTRAL PADA PELAKSANAAN PRONA TAHUN ...
 
Sistem pelayanan publik
Sistem pelayanan publikSistem pelayanan publik
Sistem pelayanan publik
 

Similar to Get your moneys worth out of your database

Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013
Connor McDonald
 
Sql2
Sql2Sql2
Les02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting DataLes02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting Data
siavosh kaviani
 
Les02.pptx
Les02.pptxLes02.pptx
Les02.pptx
NishaTariq1
 
Les02
Les02Les02
Les02
jsgcruz
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2
Umair Amjad
 
Using SQL to process hierarchies
Using SQL to process hierarchiesUsing SQL to process hierarchies
Using SQL to process hierarchies
Connor McDonald
 
Lecture03.._Joining_Spring2023-2024.pptx
Lecture03.._Joining_Spring2023-2024.pptxLecture03.._Joining_Spring2023-2024.pptx
Lecture03.._Joining_Spring2023-2024.pptx
mehediratul111
 
chap2 (3).ppt
chap2 (3).pptchap2 (3).ppt
chap2 (3).ppt
eemantariq2
 
Analytic functions in Oracle SQL - BIWA 2017
Analytic functions in Oracle SQL - BIWA 2017Analytic functions in Oracle SQL - BIWA 2017
Analytic functions in Oracle SQL - BIWA 2017
Connor McDonald
 
Sql2
Sql2Sql2
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
Connor McDonald
 
SQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX DevelopersSQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX Developers
Connor McDonald
 
ILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for DevelopersILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for Developers
Connor McDonald
 
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
Mohamed Moustafa
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
Connor McDonald
 
SQL for Data Professionals (Beginner)
SQL for Data Professionals (Beginner)SQL for Data Professionals (Beginner)
SQL for Data Professionals (Beginner)
Ankit Rathi
 
Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sql
Sushil Mishra
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
Connor McDonald
 
Les12[1]Creating Views
Les12[1]Creating ViewsLes12[1]Creating Views
Les12[1]Creating Views
siavosh kaviani
 

Similar to Get your moneys worth out of your database (20)

Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013
 
Sql2
Sql2Sql2
Sql2
 
Les02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting DataLes02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting Data
 
Les02.pptx
Les02.pptxLes02.pptx
Les02.pptx
 
Les02
Les02Les02
Les02
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2
 
Using SQL to process hierarchies
Using SQL to process hierarchiesUsing SQL to process hierarchies
Using SQL to process hierarchies
 
Lecture03.._Joining_Spring2023-2024.pptx
Lecture03.._Joining_Spring2023-2024.pptxLecture03.._Joining_Spring2023-2024.pptx
Lecture03.._Joining_Spring2023-2024.pptx
 
chap2 (3).ppt
chap2 (3).pptchap2 (3).ppt
chap2 (3).ppt
 
Analytic functions in Oracle SQL - BIWA 2017
Analytic functions in Oracle SQL - BIWA 2017Analytic functions in Oracle SQL - BIWA 2017
Analytic functions in Oracle SQL - BIWA 2017
 
Sql2
Sql2Sql2
Sql2
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
 
SQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX DevelopersSQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX Developers
 
ILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for DevelopersILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for Developers
 
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
 
SQL for Data Professionals (Beginner)
SQL for Data Professionals (Beginner)SQL for Data Professionals (Beginner)
SQL for Data Professionals (Beginner)
 
Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sql
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
Les12[1]Creating Views
Les12[1]Creating ViewsLes12[1]Creating Views
Les12[1]Creating Views
 

Recently uploaded

Proposal: The Ark Project and The BEEP Inc
Proposal: The Ark Project and The BEEP IncProposal: The Ark Project and The BEEP Inc
Proposal: The Ark Project and The BEEP Inc
Raheem Muhammad
 
2 December UAE National Day - United Arab Emirates
2 December UAE National Day - United Arab Emirates2 December UAE National Day - United Arab Emirates
2 December UAE National Day - United Arab Emirates
UAE Ppt
 
SASi-SPi Science Policy Lab Pre-engagement
SASi-SPi Science Policy Lab Pre-engagementSASi-SPi Science Policy Lab Pre-engagement
SASi-SPi Science Policy Lab Pre-engagement
Francois Stepman
 
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
OECD Directorate for Financial and Enterprise Affairs
 
Data Processing in PHP - PHPers 2024 Poznań
Data Processing in PHP - PHPers 2024 PoznańData Processing in PHP - PHPers 2024 Poznań
Data Processing in PHP - PHPers 2024 Poznań
Norbert Orzechowicz
 
IEEE CIS Webinar Sustainable futures.pdf
IEEE CIS Webinar Sustainable futures.pdfIEEE CIS Webinar Sustainable futures.pdf
IEEE CIS Webinar Sustainable futures.pdf
Claudio Gallicchio
 
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
OECD Directorate for Financial and Enterprise Affairs
 
Gamify it until you make it Improving Agile Development and Operations with ...
Gamify it until you make it  Improving Agile Development and Operations with ...Gamify it until you make it  Improving Agile Development and Operations with ...
Gamify it until you make it Improving Agile Development and Operations with ...
Ben Linders
 
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
OECD Directorate for Financial and Enterprise Affairs
 
Bridging the visual gap between cultural heritage and digital scholarship
Bridging the visual gap between cultural heritage and digital scholarshipBridging the visual gap between cultural heritage and digital scholarship
Bridging the visual gap between cultural heritage and digital scholarship
Inesm9
 
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
SkillCertProExams
 
Legislation And Regulations For Import, Manufacture,.pptx
Legislation And Regulations For Import, Manufacture,.pptxLegislation And Regulations For Import, Manufacture,.pptx
Legislation And Regulations For Import, Manufacture,.pptx
Charmi13
 
Prsentation for VIVA Welike project 1semester.pptx
Prsentation for VIVA Welike project 1semester.pptxPrsentation for VIVA Welike project 1semester.pptx
Prsentation for VIVA Welike project 1semester.pptx
prafulpawar29
 
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
gfysze
 
2023 Ukraine Crisis Media Center Financial Report
2023 Ukraine Crisis Media Center Financial Report2023 Ukraine Crisis Media Center Financial Report
2023 Ukraine Crisis Media Center Financial Report
UkraineCrisisMediaCenter
 
2023 Ukraine Crisis Media Center Finance Balance
2023 Ukraine Crisis Media Center Finance Balance2023 Ukraine Crisis Media Center Finance Balance
2023 Ukraine Crisis Media Center Finance Balance
UkraineCrisisMediaCenter
 
Genesis chapter 3 Isaiah Scudder.pptx
Genesis    chapter 3 Isaiah Scudder.pptxGenesis    chapter 3 Isaiah Scudder.pptx
Genesis chapter 3 Isaiah Scudder.pptx
FamilyWorshipCenterD
 
AWS User Group Torino 2024 #3 - 18/06/2024
AWS User Group Torino 2024 #3 - 18/06/2024AWS User Group Torino 2024 #3 - 18/06/2024
AWS User Group Torino 2024 #3 - 18/06/2024
Guido Maria Nebiolo
 
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPEACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
Charmi13
 
2023 Ukraine Crisis Media Center Annual Report
2023 Ukraine Crisis Media Center Annual Report2023 Ukraine Crisis Media Center Annual Report
2023 Ukraine Crisis Media Center Annual Report
UkraineCrisisMediaCenter
 

Recently uploaded (20)

Proposal: The Ark Project and The BEEP Inc
Proposal: The Ark Project and The BEEP IncProposal: The Ark Project and The BEEP Inc
Proposal: The Ark Project and The BEEP Inc
 
2 December UAE National Day - United Arab Emirates
2 December UAE National Day - United Arab Emirates2 December UAE National Day - United Arab Emirates
2 December UAE National Day - United Arab Emirates
 
SASi-SPi Science Policy Lab Pre-engagement
SASi-SPi Science Policy Lab Pre-engagementSASi-SPi Science Policy Lab Pre-engagement
SASi-SPi Science Policy Lab Pre-engagement
 
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
 
Data Processing in PHP - PHPers 2024 Poznań
Data Processing in PHP - PHPers 2024 PoznańData Processing in PHP - PHPers 2024 Poznań
Data Processing in PHP - PHPers 2024 Poznań
 
IEEE CIS Webinar Sustainable futures.pdf
IEEE CIS Webinar Sustainable futures.pdfIEEE CIS Webinar Sustainable futures.pdf
IEEE CIS Webinar Sustainable futures.pdf
 
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
 
Gamify it until you make it Improving Agile Development and Operations with ...
Gamify it until you make it  Improving Agile Development and Operations with ...Gamify it until you make it  Improving Agile Development and Operations with ...
Gamify it until you make it Improving Agile Development and Operations with ...
 
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
 
Bridging the visual gap between cultural heritage and digital scholarship
Bridging the visual gap between cultural heritage and digital scholarshipBridging the visual gap between cultural heritage and digital scholarship
Bridging the visual gap between cultural heritage and digital scholarship
 
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
 
Legislation And Regulations For Import, Manufacture,.pptx
Legislation And Regulations For Import, Manufacture,.pptxLegislation And Regulations For Import, Manufacture,.pptx
Legislation And Regulations For Import, Manufacture,.pptx
 
Prsentation for VIVA Welike project 1semester.pptx
Prsentation for VIVA Welike project 1semester.pptxPrsentation for VIVA Welike project 1semester.pptx
Prsentation for VIVA Welike project 1semester.pptx
 
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
 
2023 Ukraine Crisis Media Center Financial Report
2023 Ukraine Crisis Media Center Financial Report2023 Ukraine Crisis Media Center Financial Report
2023 Ukraine Crisis Media Center Financial Report
 
2023 Ukraine Crisis Media Center Finance Balance
2023 Ukraine Crisis Media Center Finance Balance2023 Ukraine Crisis Media Center Finance Balance
2023 Ukraine Crisis Media Center Finance Balance
 
Genesis chapter 3 Isaiah Scudder.pptx
Genesis    chapter 3 Isaiah Scudder.pptxGenesis    chapter 3 Isaiah Scudder.pptx
Genesis chapter 3 Isaiah Scudder.pptx
 
AWS User Group Torino 2024 #3 - 18/06/2024
AWS User Group Torino 2024 #3 - 18/06/2024AWS User Group Torino 2024 #3 - 18/06/2024
AWS User Group Torino 2024 #3 - 18/06/2024
 
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPEACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
 
2023 Ukraine Crisis Media Center Annual Report
2023 Ukraine Crisis Media Center Annual Report2023 Ukraine Crisis Media Center Annual Report
2023 Ukraine Crisis Media Center Annual Report
 

Get your moneys worth out of your database

  • 2. 2 • Patrick Barel • Working with Oracle since 1997 • Working with PL/SQL since 1999 • Playing with APEX since 2003 (mod_plsql) • ACE since 2011 • OCA since December 20th 2012 • OCP since February 20th 2014 • Developer Choice Award 2015 About me…
  • 4. 4 Download me… Plugins for PL/SQL Developer http://bar-solutions.com Plugins for Apex http://apex-plugin.com
  • 7. 7 Patrick Barel, AMIS June 2, 2016 Get Your Moneys Worth Out Of Your Database
  • 8. 8 It doesn’t matter how many resources you have. If you don’t know how to use them, it will never be enough
  • 11. 11 Data integrity/quality create table demo.emp_unprotected ( empno number(4) not null , ename varchar2(10) , sal number(7,2) , deptno number(2) )
  • 12. 12 Data integrity/quality insert into demo.emp_unprotected values (7369, 'SMITH', 800, 20); insert into demo.emp_unprotected values (7499, 'ALLEN', 1600, 30); insert into demo.emp_unprotected values (7521, 'WARD', 1250, 30); insert into demo.emp_unprotected values (7566, 'JONES', 2975, 20); … insert into demo.emp_unprotected values (7900, 'JAMES', 950, 30); insert into demo.emp_unprotected values (7902, 'FORD', 3000, 20); insert into demo.emp_unprotected values (7934, 'MILLER', 1300, 10);
  • 13. 13 Data integrity/quality update demo.emp_unprotected e set e.sal = 2 * e.sal • Salary not over 7500 • No duplicate employee numbers • Existing department update demo.emp_unprotected e set e.deptno = 50 where e.ename = 'SCOTT' insert into demo.emp_unprotected (empno, ename, sal, deptno) values (7900, 'BAREL', 1000, 10)
  • 14. 14 Data integrity/quality update demo.emp_protected e set e.sal = 2 * e.sal • Salary not over 7500 • No duplicate employee numbers • Existing department update demo.emp_protected e set e.deptno = 50 where e.ename = 'SCOTT' insert into demo.emp_protected (empno, ename, sal, deptno) values (7900, 'BAREL', 1000, 10) alter table demo.emp_protected add constraint sal_under_7500 check ((sal < 7500)) alter table demo.emp_protected add constraint pk_emp_protected primary key (empno) alter table demo.emp_protected add constraint fk_emp_protected_dept foreign key (deptno) references demo.dept (deptno) dataintegrity.sql
  • 16. 16 Flashback queries create table emp_fb ( empno NUMBER(4) not null, ename VARCHAR2(10), sal NUMBER(7,2), deptno NUMBER(2) )
  • 17. 17 Flashback queries … insert into emp_fb values (7782, 'CLARK', 2450, 10); insert into emp_fb values (7788, 'SCOTT', 3000, 20); insert into emp_fb values (7839, 'KING', 5000, 10); insert into emp_fb values (7844, 'TURNER', 1500, 30); insert into emp_fb values (7876, 'ADAMS', 1100, 20); insert into emp_fb values (7900, 'JAMES', 950, 30); insert into emp_fb values (7902, 'FORD', 3000, 20); insert into emp_fb values (7934, 'MILLER', 1300, 10);
  • 18. 18 Flashback queries select e.empno, e.ename, e.sal from emp_fb e where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2650.00 7839 KING 5200.00 7934 MILLER 1500.00
  • 19. 19 Flashback queries select e.empno, e.ename, e.sal from emp_fb e where e.deptno = 10 select e.empno, e.ename, e.sal from emp_fb e where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2650.00 7839 KING 5200.00 7934 MILLER 1500.00 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2650.00 7839 KING 5200.00 7934 MILLER 1500.00 update emp_fb e set e.sal = e.sal + 200 where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2850.00 7839 KING 5400.00 7934 MILLER 1700.00
  • 20. 20 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2850.00 7839 KING 5400.00 7934 MILLER 1700.00 Flashback queries select e.empno, e.ename, e.sal from emp_fb e where e.deptno = 10 select e.empno, e.ename, e.sal from emp_fb e where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2650.00 7839 KING 5200.00 7934 MILLER 1500.00 update emp_fb e set e.sal = e.sal + 200 where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2850.00 7839 KING 5400.00 7934 MILLER 1700.00 commit
  • 21. 21 Flashback queries … insert into emp_fb values (7782, 'CLARK', 2450, 10); insert into emp_fb values (7788, 'SCOTT', 3000, 20); insert into emp_fb values (7839, 'KING', 5000, 10); insert into emp_fb values (7844, 'TURNER', 1500, 30); insert into emp_fb values (7876, 'ADAMS', 1100, 20); insert into emp_fb values (7900, 'JAMES', 950, 30); insert into emp_fb values (7902, 'FORD', 3000, 20); insert into emp_fb values (7934, 'MILLER', 1300, 10); truncate table emp_fb
  • 22. 22 Flashback queries select e.empno, e.ename, e.sal from emp_fb e where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2650.00 7839 KING 5200.00 7934 MILLER 1500.00
  • 23. 23 Flashback queries select e.empno, e.ename, e.sal from emp_fb e where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2650.00 7839 KING 5200.00 7934 MILLER 1500.00 update emp_fb e set e.sal = e.sal + 200 where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2850.00 7839 KING 5400.00 7934 MILLER 1700.00
  • 24. 24 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2850.00 7839 KING 5400.00 7934 MILLER 1700.00 Flashback queries select e.empno, e.ename, e.sal from emp_fb e where e.deptno = 10 update emp_fb e set e.sal = e.sal + 200 where e.deptno = 10 commit
  • 25. 25 Flashback queries select e.empno, e.ename, e.sal from demo.emp_fb as of timestamp to_timestamp(sysdate - 1/(24*60*60)) e where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2650.00 7839 KING 5200.00 7934 MILLER 1500.00 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2850.00 7839 KING 5400.00 7934 MILLER 1700.00
  • 26. 26 Flashback queries select e.empno, e.ename, e.sal from demo.emp_fb as of timestamp to_timestamp(sysdate - 1/(24*60*60)) e where e.deptno = 10 EMPNO ENAME SAL ----- ---------- --------- 7782 CLARK 2650.00 7839 KING 5200.00 7934 MILLER 1500.00 select e.empno, e.ename, e.sal from demo.emp_fb as of scn 23352983 e where e.deptno = 10 flashback_fb1.sql flashback_fb2.sql flashback_fb3.sql
  • 28. 28 Temporal validity create table demo.customers ( id number , name varchar2(30) , address varchar2(30) )
  • 29. 29 Temporal validity insert into demo.customers (id, name, address) values (1, 'Patrick', '1 Oxford Street') insert into demo.customers (id, name, address) values (2, 'Steven', '57 Chicago Boulevard') select * from demo.customers c order by c.id ID NAME ADDRESS --- ------------------------- ------------------------- 1 Patrick 1 Oxford Street 2 Steven 57 Chicago Boulevard
  • 30. 30 Temporal validity update demo.customers c set c.address = '1 Oracle Lane' where c.id = 1 select * from demo.customers c order by c.id ID NAME ADDRESS --- ------------------------- ------------------------- 1 Patrick 1 Oracle Lane 2 Steven 57 Chicago Boulevard
  • 31. 31 Temporal validity truncate table demo.customers insert into demo.customers (id, name, address) values (1, 'Patrick', '1 Oxford Street') insert into demo.customers (id, name, address) values (2, 'Steven', '57 Chicago Boulevard') select * from demo.customers c order by c.id ID NAME ADDRESS --- ------------------------- ------------------------- 1 Patrick 1 Oxford Street 2 Steven 57 Chicago Boulevard alter table demo.customers add period for valid_time
  • 32. 32 Temporal validity truncate table demo.customers insert into demo.customers (id, name, address) values (1, 'Patrick', '1 Oxford Street') insert into demo.customers (id, name, address) values (2, 'Steven', '57 Chicago Boulevard') ID NAME ADDRESS --- ------------------------- ------------------------- 1 Patrick 1 Oxford Street 2 Steven 57 Chicago Boulevard select * from demo.customers c order by c.id alter table demo.customers add period for valid_time
  • 33. 33 Temporal validity select c.id , c.name , c.address , to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from , to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till from demo.customers c order by c.id ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oxford Street 2 Steven 57 Chicago Boulevard
  • 34. 34 Temporal validity select c.id , c.name , c.address , to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from , to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till from demo.customers c order by c.id update demo.customers c set c.valid_time_end = to_date('06012016 235959' ,'MMDDYYYY HH24MISS') where c.id = 1 ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oxford Street 2 Steven 57 Chicago Boulevard ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oxford Street 06-01-2016 2 Steven 57 Chicago Boulevard
  • 35. 35 ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oxford Street 06-01-2016 1 Patrick 1 Oracle Lane 06-02-2016 2 Steven 57 Chicago Boulevard Temporal validity select c.id , c.name , c.address , to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from , to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till from demo.customers c order by c.id update demo.customers c set c.valid_time_end = to_date('06012016 235959' ,'MMDDYYYY HH24MISS') where c.id = 1 insert into demo.customers(id, name, address, valid_time_start) values (1,'Patrick','1 Oracle Lane',to_date('06022016','MMDDYYYY')) ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oxford Street 06-01-2016 2 Steven 57 Chicago Boulevard
  • 36. 36 Temporal validity select c.id , c.name , c.address , to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from , to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till from demo.customers c order by c.id exec dbms_flashback_archive.enable_at_valid_time('CURRENT') ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oracle Lane 06-02-2016 2 Steven 57 Chicago Boulevard
  • 37. 37 Temporal validity select c.id , c.name , c.address , to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from , to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till from demo.customers c order by c.id exec dbms_flashback_archive.enable_at_valid_time('CURRENT') ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oracle Lane 06-02-2016 2 Steven 57 Chicago Boulevard exec dbms_flashback_archive.enable_at_valid_time('ASOF' , to_date('06012016','MMDDYYYY')) ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oxford Street 06-01-2016 2 Steven 57 Chicago Boulevard
  • 38. 38 ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oracle Lane 06-02-2016 2 Steven 57 Chicago Boulevard ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oxford Street 06-01-2016 2 Steven 57 Chicago Boulevard Temporal validity select c.id , c.name , c.address , to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from , to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till from demo.customers c order by c.id exec dbms_flashback_archive.enable_at_valid_time('CURRENT') exec dbms_flashback_archive.enable_at_valid_time('ASOF' , to_date('06012016','MMDDYYYY')) exec dbms_flashback_archive.enable_at_valid_time('ASOF' , to_date('06022016','MMDDYYYY'))
  • 39. 39 ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oxford Street 06-01-2016 1 Patrick 1 Oracle Lane 06-02-2016 2 Steven 57 Chicago Boulevard ID NAME ADDRESS VALID_FROM VALID_TILL --- ------------------------- ------------------------- ---------- ---------- 1 Patrick 1 Oracle Lane 06-02-2016 2 Steven 57 Chicago Boulevard Temporal validity select c.id , c.name , c.address , to_char(c.valid_time_start, 'MM-DD-YYYY') valid_from , to_char(c.valid_time_end, 'MM-DD-YYYY') valid_till from demo.customers c order by c.id exec dbms_flashback_archive.enable_at_valid_time('CURRENT') exec dbms_flashback_archive.enable_at_valid_time('ASOF' , to_date('06012016','MMDDYYYY')) exec dbms_flashback_archive.enable_at_valid_time('ASOF' , to_date('06022016','MMDDYYYY')) exec dbms_flashback_archive.enable_at_valid_time('ALL') temporal_validity.sql
  • 42. 42 Data redaction create table SensitiveData (contract varchar2(23)) insert into SensitiveData(contract) values ('5555-5555-5555-4444'); insert into SensitiveData(contract) values ('5105-1051-0510-5100'); insert into SensitiveData(contract) values ('5111-1111-1111-1118');
  • 43. 43 Data redaction begin dbms_redact.add_policy( object_schema => 'DEMO' ,object_name => 'SENSITIVEDATA' ,policy_name => 'PARTIALMASKDEMO' ,column_name => 'CONTACT' ,function_type => DBMS_REDACT.PARTIAL ,function_parameters => 'VVVVFVVVVFVVVVFVVVV,VVVV-VVVV-VVVV-VVVV,X,1,12' ,expression => q'[SYS_CONTEXT ('USERENV', 'SESSION_USER') <> 'BU']'); end;
  • 44. 44 Data redaction select * from demo.SensitiveData select * from demo.SensitiveData CONTRACT ----------------------- 5555-5555-5555-4444 5105-1051-0510-5100 5111-1111-1111-1118 CONTRACT ----------------------- XXXX-XXXX-XXXX-4444 XXXX-XXXX-XXXX-5100 XXXX-XXXX-XXXX-1118 redaction.sql
  • 47. 47 Virtual private database create or replace function vpdfunc (schemaname_in in varchar2 ,tablename_in in varchar2) return varchar2 is l_returnvalue varchar2(2000); begin case user when 'BU' then l_returnvalue := 'DEPTNO in (10,30)'; when 'MP' then l_returnvalue := 'DEPTNO in (20,40)'; else l_returnvalue := '1=1'; end case; return l_returnvalue; end;
  • 48. 48 Virtual private database begin dbms_rls.add_policy(object_schema => 'DEMO' ,object_name => 'EMP_VPD' ,policy_name => 'VPDDEMO' ,function_schema => 'DEMO' ,policy_function => 'VPDFUNC'); end;
  • 49. 49 Virtual private database begin dbms_rls.add_policy(object_schema => 'DEMO' ,object_name => 'EMP_VPD' ,policy_name => 'VPDDEMO' ,function_schema => 'DEMO' ,policy_function => 'VPDFUNC'); end; select empno, ename, deptno from demo.emp_vpd EMPNO ENAME DEPTNO ----- ---------- ------ 7499 ALLEN 30 … 7934 MILLER 10 9 rows selected EMPNO ENAME DEPTNO ----- ---------- ------ 7369 SMITH 20 … 7902 FORD 20 5 rows selected VirtualPrivateDatabase.sql
  • 52. 52 Query result cache create table QueryResultCacheTable ( id number )
  • 53. 53 Query result cache insert into QueryResultCacheTable(id) values (1); insert into QueryResultCacheTable(id) values (2); insert into QueryResultCacheTable(id) values (3); insert into QueryResultCacheTable(id) values (4); insert into QueryResultCacheTable(id) values (5); create or replace function veryslowfunction(id_in in queryresultcachetable.id%type) return queryresultcachetable.id%type as begin dbms_lock.sleep(1); return id_in; end; set timing on
  • 54. 54 Query result cache select VerySlowFunction(qrct.id) from QueryResultCacheTable qrct select /*+ result_cache */ veryslowfunction(qrct.id) from queryresultcachetable qrct select /*+ result_cache */ veryslowfunction(qrct.id) from queryresultcachetable qrct Executed in 5.88 seconds Executed in 11.664 seconds Executed in 0.035 seconds
  • 55. 55 Query result cache create or replace function veryslowfunction(id_in in queryresultcachetable.id%type) return queryresultcachetable.id%type deterministic as begin dbms_lock.sleep(1); return id_in; end;
  • 56. 56 Query result cache select /*+ result_cache */ veryslowfunction(qrct.id) from queryresultcachetable qrct select /*+ result_cache */ veryslowfunction(qrct.id) from queryresultcachetable qrct Executed in 5.507 seconds Executed in 0.038 seconds
  • 57. 57 Query result cache create table FunctionResultCacheTable ( id number )
  • 58. 58 Query result cache insert into FunctionResultCacheTable(id) values (1); insert into FunctionResultCacheTable(id) values (2); insert into FunctionResultCacheTable(id) values (3); insert into FunctionResultCacheTable(id) values (1); insert into FunctionResultCacheTable(id) values (2); insert into FunctionResultCacheTable(id) values (3); insert into FunctionResultCacheTable(id) values (1); insert into FunctionResultCacheTable(id) values (2); insert into FunctionResultCacheTable(id) values (3); insert into FunctionResultCacheTable(id) values (1);
  • 59. 59 Query result cache select veryslowfunction(frct.id) from FunctionResultCacheTable frct Elapsed: 00:00:10.18 create or replace function veryslowfunction(id_in in FunctionResultCacheTable.id%type) return FunctionResultCacheTable.id%type as begin dbms_lock.sleep(1); return id_in; end; Elapsed: 00:00:10.28
  • 60. 60 create or replace function veryslowfunction(id_in in FunctionResultCacheTable.id%type) return FunctionResultCacheTable.id%type deterministic as begin dbms_lock.sleep(1); return id_in; end; Query result cache select veryslowfunction(frct.id) from FunctionResultCacheTable frct Elapsed: 00:00:10.18Elapsed: 00:00:10.28 Elapsed: 00:00:04.16Elapsed: 00:00:04.09
  • 61. 61 create or replace function veryslowfunction(id_in in FunctionResultCacheTable.id%type) return FunctionResultCacheTable.id%type result_cache as begin dbms_lock.sleep(1); return id_in; end; Query result cache select veryslowfunction(frct.id) from FunctionResultCacheTable frct Elapsed: 00:00:10.18Elapsed: 00:00:10.28 Elapsed: 00:00:04.16Elapsed: 00:00:04.09 Elapsed: 00:00:00.00Elapsed: 00:00:03.15 Elapsed: 00:00:00.00 VirtualPrivateDatabase.sql
  • 62. 62
  • 68. 68 Application Upgrade Creation of new objects Changing existing objects Drop redundant objects Convert / Migrate Resume normal operation
  • 69. 69
  • 70. 70 (Non)Editionable Objects Editionable Non-Editionable Packages Tables Procedures Materialized views Functions DB Links Triggers Views Types Synonyms
  • 72. 72 Retrieve the top-3 earning employees Special SQL features select e.empno ,e.ename ,e.sal from demo.emp e where rownum < 4 order by e.sal desc EMPNO ENAME SAL ----- ---------- --------- 7499 ALLEN 1600.00 7521 WARD 1250.00 7369 SMITH 800.00
  • 73. 73 Retrieve the top-3 earning employees Special SQL features select e.empno ,e.ename ,e.sal from (select e2.empno ,e2.ename ,e2.sal from demo.emp e2 order by e2.sal desc) e where rownum < 4 EMPNO ENAME SAL ----- ---------- --------- 7839 KING 5000.00 7788 SCOTT 3000.00 7902 FORD 3000.00 select e.empno ,e.ename ,e.sal from demo.emp e where rownum < 4 order by e.sal desc EMPNO ENAME SAL ----- ---------- --------- 7499 ALLEN 1600.00 7521 WARD 1250.00 7369 SMITH 800.00
  • 74. 74 Retrieve the top-3 earning employees Special SQL features with orderedbysal as (select e.empno ,e.ename ,e.sal from demo.emp e order by e.sal desc) select obs.empno ,obs.ename ,obs.sal from orderedbysal obs where rownum < 4 select e.empno ,e.ename ,e.sal from demo.emp e order by e.sal desc fetch first 3 rows only EMPNO ENAME SAL ----- ---------- --------- 7839 KING 5000.00 7788 SCOTT 3000.00 7902 FORD 3000.00 EMPNO ENAME SAL ----- ---------- --------- 7839 KING 5000.00 7788 SCOTT 3000.00 7902 FORD 3000.00 select e.empno ,e.ename ,e.sal from (select e2.empno ,e2.ename ,e2.sal from demo.emp e2 order by e2.sal desc) e where rownum < 4 Syntax Candy this is rewritten as
  • 75. 75 Retrieve the next 3 topearning employees Special SQL features with orderedbysal as (select e.empno ,e.ename ,e.sal ,rownum rn from demo.emp e order by e.sal desc) select obs.empno ,obs.ename ,obs.sal from orderedbysal obs where obs.rn between 4 and 6 order by obs.rn EMPNO ENAME SAL ----- ---------- --------- 7566 JONES 2975.00 7654 MARTIN 1250.00 7698 BLAKE 2850.00
  • 76. 76 Retrieve the next 3 topearning employees Special SQL features with orderedbysal as (select e.empno ,e.ename ,e.sal from demo.emp e order by e.sal desc) , orderedwithrownum as (select obs.empno , obs.ename , obs.sal , rownum rn from orderedbysal obs) select obr.empno ,obr.ename ,obr.sal from orderedwithrownum obr where obr.rn between 4 and 6 order by obr.rn select e.empno ,e.ename ,e.sal from demo.emp e order by e.sal desc offset 3 rows fetch next 3 rows only EMPNO ENAME SAL ----- ---------- --------- 7566 JONES 2975.00 7698 BLAKE 2850.00 7782 CLARK 2450.00 EMPNO ENAME SAL ----- ---------- --------- 7566 JONES 2975.00 7698 BLAKE 2850.00 7782 CLARK 2450.00 with orderedbysal as (select e.empno ,e.ename ,e.sal ,rownum rn from demo.emp e order by e.sal desc) select obs.empno ,obs.ename ,obs.sal from orderedbysal obs where obs.rn between 4 and 6 order by obs.rn EMPNO ENAME SAL ----- ---------- --------- 7566 JONES 2975.00 7654 MARTIN 1250.00 7698 BLAKE 2850.00 paginating.sql
  • 77. 77 Build PL/SQL in SQL Special SQL features create or replace function wavey(string_in in varchar2) return varchar2 is l_returnvalue varchar2(30); begin for indx in 1 .. length(string_in) loop l_returnvalue := l_returnvalue || case mod(indx, 2) when 0 then upper(substr(string_in, indx, 1)) else lower(substr(string_in, indx, 1)) end; end loop; return l_returnvalue; end; Function created
  • 78. 78 Build PL/SQL in SQL Special SQL features select e.empno, e.ename, wavey(e.ename) wavey_ename, e.sal from demo.emp e EMPNO ENAME WAVEY_ENAME SAL ----- ---------- ------------ --------- 7369 SMITH sMiTh 800.00 7499 ALLEN aLlEn 1600.00 7521 WARD wArD 1250.00 7566 JONES jOnEs 2975.00 7654 MARTIN mArTiN 1250.00 7698 BLAKE bLaKe 2850.00 7782 CLARK cLaRk 2450.00 7788 SCOTT sCoTt 3000.00 7839 KING kInG 5000.00 7844 TURNER tUrNeR 1500.00 7876 ADAMS aDaMs 1100.00 7900 JAMES jAmEs 950.00 7902 FORD fOrD 3000.00 7934 MILLER mIlLeR 1300.00 14 rows selected
  • 79. 79 Special SQL features with function wavey(string_in in varchar2) return varchar2 is l_returnvalue varchar2(30); begin for indx in 1 .. length(string_in) loop l_returnvalue := l_returnvalue || case mod(indx, 2) when 1 then upper(substr(string_in, indx, 1)) else lower(substr(string_in, indx, 1)) end; end loop; return l_returnvalue; end; select e.empno, e.ename, wavey(e.ename) wavey_ename, e.sal from demo.emp e EMPNO ENAME WAVEY_ENAME SAL ----- ---------- ------------ --------- 7369 SMITH SmItH 800.00 7499 ALLEN AlLeN 1600.00 … 7934 MILLER MiLlEr 1300.00 14 rows selected plsql_in_with.sql
  • 80. 80
  • 82. 82 Virtual Columns create table demo.emp_income ( empno number(4) not null , ename varchar2(10) , sal number(7,2) , comm number(7,2) , deptno number(2) , income number(7,2) generated always as (demo.emp_income.sal + coalesce(demo.emp_income.comm,0)) virtual )
  • 83. 83 Virtual Columns insert into demo.emp_income(empno, ename, sal, deptno, comm) values (7499, 'ALLEN', 1600, 30, 300); insert into demo.emp_income(empno, ename, sal, deptno, comm) values (7521, 'WARD', 1250, 30, 500); insert into demo.emp_income(empno, ename, sal, deptno, comm) values (7654, 'MARTIN', 1250, 30, 1400); insert into demo.emp_income(empno, ename, sal, deptno, comm) values (7698, 'BLAKE', 2850, 30, null); insert into demo.emp_income(empno, ename, sal, deptno, comm) values (7844, 'TURNER', 1500, 30, 0); insert into demo.emp_income(empno, ename, sal, deptno, comm) values (7900, 'JAMES', 950, 30, null);
  • 84. 84 Virtual Columns EMPNO ENAME SAL COMM DEPTNO INCOME ------ ---------- --------- --------- ------- --------- 7499 ALLEN 1600.00 300.00 30 1900.00 7521 WARD 1250.00 500.00 30 1750.00 7654 MARTIN 1250.00 1400.00 30 2650.00 7698 BLAKE 2850.00 30 2850.00 7844 TURNER 1500.00 .00 30 1500.00 7900 JAMES 950.00 30 950.00 6 rows selected. select * from demo.emp_income e VirtualColumnIncome.sql
  • 85. 85 Virtual Columns create table demo.emp_nuke ( empno number(4) not null , ename varchar2(10) , sal number(7,2) , deptno number(2) , blowitup number generated always as (1/0) virtual )
  • 86. 86 Virtual Columns insert into demo.emp_nuke(empno, ename, sal, deptno) values (7499, 'ALLEN', 1600, 30); insert into demo.emp_nuke(empno, ename, sal, deptno) values (7521, 'WARD', 1250, 30); insert into demo.emp_nuke(empno, ename, sal, deptno) values (7654, 'MARTIN', 1250, 30); insert into demo.emp_nuke(empno, ename, sal, deptno) values (7698, 'BLAKE', 2850, 30); insert into demo.emp_nuke(empno, ename, sal, deptno) values (7844, 'TURNER', 1500, 30); insert into demo.emp_nuke(empno, ename, sal, deptno) values (7900, 'JAMES', 950, 30);
  • 87. 87 Virtual Columns select * * ERROR at line 1: ORA-01476: divisor is equal to zero select * from demo.emp_nuke e
  • 88. 88 Virtual Columns EMPNO ENAME SAL DEPTNO ------ ---------- --------- ------- 7499 ALLEN 1600.00 30 7521 WARD 1250.00 30 7654 MARTIN 1250.00 30 7698 BLAKE 2850.00 30 7844 TURNER 1500.00 30 7900 JAMES 950.00 30 6 rows selected. select e.empno, e.ename, e.sal, e.deptno from demo.emp_nuke e VirtualColumnPreventSelectStar.sql
  • 90. 91 Identity columns (12c) create table tablewithuniquecolumn ( theuniquecolumn number(10) not null , foo varchar2(30) , bar varchar2(30) )
  • 91. 92 Identity columns (12c) create sequence sequenceforuniquecolumn start with 1 nocache
  • 92. 93 Identity columns (12c) create or replace trigger makesureitsfilled before insert or update on tablewithuniquecolumn for each row begin if :new.theuniquecolumn is null then select sequenceforuniquecolumn.nextval into :new.theuniquecolumn from dual; end if; end;
  • 93. 94 Identity columns (12c) create or replace trigger makesureitsfilled before insert or update on tablewithuniquecolumn for each row begin if :new.theuniquecolumn is null then :new.theuniquecolumn := sequenceforuniquecolumn.nextval; end if; end;
  • 94. 95 Identity columns (12c) create table tablewithidentitycolumn ( theidentitycolumn number(10) generated always as identity , foo varchar2(30) , bar varchar2(30) ) identity_columns.sql
  • 97. 98 Invisible columns (12c) create table Show ( I varchar2(30) , am varchar2(30) , the varchar2(30) , invisible varchar2(30) , man varchar2(30) )
  • 98. 99 Invisible columns (12c) select * from show I AM THE INVISIBLE MAN - -- --- --------- --- I am the invisible man
  • 99. 100 Invisible columns (12c) select * from show I AM THE INVISIBLE MAN - -- --- --------- --- I am the invisible man alter table show modify invisible invisible
  • 100. 101 Invisible columns (12c) select * from show I AM THE INVISIBLE MAN - -- --- --------- --- I am the invisible man alter table show modify invisible invisible I AM THE MAN - -- --- --- I am the man
  • 101. 102 Invisible columns (12c) select * from show I AM THE INVISIBLE MAN - -- --- --------- --- I am the invisible man alter table show modify invisible invisible I AM THE MAN - -- --- --- I am the man select I, am, the, invisible, man from show IAmTheInvisibleColumn.sql
  • 104. 105 Whitelisting PL/SQL program units create or replace procedure onlywhitelisted accessible by (normalprocedure) is begin dbms_output.put_line('You are allowed'); end;
  • 105. 106 Whitelisting PL/SQL program units create or replace procedure onlywhitelisted accessible by (normalprocedure) is begin dbms_output.put_line('You are allowed'); end; create or replace procedure normalprocedure is begin dbms_output.put_line ('normalprocedure calls onlywhitelisted'); onlywhitelisted; end;
  • 106. 107 Whitelisting PL/SQL program units create or replace procedure onlywhitelisted accessible by (normalprocedure) is begin dbms_output.put_line('You are allowed'); end; create or replace procedure normalprocedure is begin dbms_output.put_line ('normalprocedure calls onlywhitelisted'); onlywhitelisted; end; create or replace procedure evilprocedure is begin dbms_output.put_line ('evilprocedure calls onlywhitelisted'); onlywhitelisted; end;
  • 107. 108 Whitelisting PL/SQL program units create or replace procedure onlywhitelisted accessible by (normalprocedure) is begin dbms_output.put_line('You are allowed'); end; create or replace procedure normalprocedure is begin dbms_output.put_line ('normalprocedure calls onlywhitelisted'); onlywhitelisted; end; create or replace procedure evilprocedure is begin dbms_output.put_line ('evilprocedure calls onlywhitelisted'); onlywhitelisted; end; create or replace procedure evilprocedure is begin dbms_output.put_line ('evilprocedure calls normalprocedure'); normalprocedure; end; whitelisting_12c.sql
  • 108. 109
  • 109. 110
  • 110. 111 • Data integrity/quality • http://www.riparteilfuturo.it/assets/articles/images/429e6a 270817213e33647f1344cb121f.jpeg • No Matter How Much – https://pbs.twimg.com/profile_images/4392957816027340 80/WwHn8tUM.jpeg Credits • Database – https://www.oracle.com/engineered- systems/products.html
  • 111. 112 • Flashback queries – https://insiderhema.files.wordpress.com/2015/07/the- time-desktop-background-496046.jpg Credits • Data security – http://tr1.cbsistatic.com/hub/i/2016/02/25/f1cab87f-0b42- 4700-945e- 898a5f90898b/32c0dc0f18610d2a9eddc85b19bdce81/hack er6.jpg • Temporal validity – http://blogs.discovermagazine.com/crux/files/2014/01/tim e-travel.jpg
  • 112. 113 • Performance increase – http://www.adelhi.com/wp- content/uploads/2015/10/result.adelhi.jpg Credits • Edition Based Redefinition – http://www.psychedelictribe.com/wp- content/uploads/parallel-universe-image.jpg • Why Downtime matters? – http://image.slidesharecdn.com/wed1240yahooshahegashi ra-150424124356-conversion-gate01/95/oozie-towards- zero-downtime-12-638.jpg?cb=1429897523
  • 113. 114 • Special SQL features – https://geofrikphotos.files.wordpress.com/2012/12/paisaje -marte.jpg Credits • Virtual Columns – http://wallpaper.zone/img/1667098.jpg • Pros Cons – https://secure.surveymonkey.com/wp- content/uploads/2014/10/Pros_Cons_NPS.jpg
  • 114. 115 • Identity columns (12c) – http://www.cambridgedove.com/Pages/images/020/020titl e2.gif Credits • Whitelisting PL/SQL program units – http://www.pinpointe.com/blog/wp- content/uploads/what-is-whitelisting-780x421.png • Invisible columns (12c) – https://hollywoodhatesme.files.wordpress.com/2012/07/in visible-man.jpg
  • 115. 116 • Whitelisting PL/SQL program units – http://www.ccs- inc.com/images/uploads/Yes_No_Shutterstock_83547358.j pg Credits

Editor's Notes

  1. Not just a piece of iron Has more features than you probably ever will use. I will show you just a subset of the, sometimes newest, features in an overview.
  2. Single Point Of Data Integrity
  3. If you create a simple table
  4. And add some data to it
  5. If you create your business rules in you front end application, there will always be someone who will bypass your application and use something like SQL*Plus to access your database.
  6. Let’s say you create a new application and add the protection to the table. alter table demo.emp_protected add constraint sal_under_7500 check ((sal < 7500)) alter table demo.emp_protected add constraint pk_emp_protected primary key (empno) alter table demo.emp_protected add constraint fk_emp_protected_dept foreign key (deptno) references demo.dept (deptno)
  7. What did my data look like at a certain moment in time. No more need for journaling tables. Every query already was a flashback query due to read-consistency. Based on the SCN value at the time of execution
  8. What did my data look like at a certain moment in time. No more need for journaling tables. Every query already was a flashback query due to read-consistency. Based on the SCN value at the time of execution
  9. Now I move house. Easy as doing an update to the row. But this has to be done exactly on the day I move... I would like to be able to put in the new data and have Oracle serve me the right rows Let’s reset our situation…
  10. Let's reset Then we add a column to hold the validity of the record
  11. Let's reset Then we add a column to hold the validity of the record
  12. Now we can update the ending validity for the record And then we can add the new address with a starting date
  13. Now we can update the ending validity for the record And then we can add the new address with a starting date
  14. Now we can update the ending validity for the record And then we can add the new address with a starting date
  15. Enable temporal validity
  16. Enable temporal validity
  17. Enable temporal validity
  18. Enable temporal validity
  19. only read and write data you are authorized for
  20. only read and write data you are authorized for There are two users. The business user and a maintenance person. We have a database with a table containing sensitive data. The business user is allowed to see all the data But the maintenance person is only allowed to see the last four digits of the number (contract, credit card or what have you).
  21. near zero downtime application upgrades or support for parallel database worlds Every database needs upgrading due to new demands, new features, bugfixes etc.
  22. If you want to do an application upgrade…
  23. Adding new objects is no problem…
  24. Dropping columns from tables is a problem. Pre 11G databases also cause a problem when adding columns to a table. In 11G the database now uses Fine Grained Dependency Tracking which means dependencies are now tracked at column level instead of object level.
  25. Changing code is a problem. If you change the implementation of a program in a package (the package body), this should normally not cause any problems, but if you change the signature of a program (the package specification) then you cause invalidation of dependent objects.
  26. Dropping tables is a problem. Chances are, near 100%, that this table is used by other objects, causing invalidation of those objects.
  27. Application upgrade normally follows these steps: Creation of new objects – No problems here It becomes interesting when you start changing existing objects, drop redundant objects or convert/migrate existing objects.
  28. You would want to have a parallel universe in which you can perform the upgrade without affecting the users and then, when you’re done, have the users us the new version.
  29. If tables are not editionable, how do we cope with data? To handle issues with the table changes there are cross-edition-triggers. These are built to make sure data entered in one edition is presented correctly in the other edition.
  30. Create Top-N queries
  31. Create Top-N queries
  32. Or paginate your result
  33. Pros: Faster especially on large datasets Logic closer to it’s use Cons: No reuse of the logic
  34. First you create the table. Note the last column. This is the virtual column which is calculated based on the values of other fields in the record.
  35. First you create the table. Note the last column. This is the virtual column which is calculated based on the values of other fields in the record. You can’t insert values for the virtual column
  36. But when you select the values from the table, the column is calculated for you. You can of course achieve the same effect using a view, but that requires an extra object.
  37. If you create a table with a virtual column with an invalid calculation.
  38. And add some data
  39. If you try to execute a select * from the table you’ll get an error
  40. If, however, you select all the individual columns except the virtual one your ok. The column value is only calculated when it is requested.
  41. Remember the good old days? When you wanted a column to hold a unique value and always be filled?
  42. First you created the table.
  43. Then you created a sequence to be used for the unique column
  44. Then you would create a trigger on the table…
  45. Or if you are using a more recent version of the database it would look like this. The trigger retrieves a value from the sequence and uses that to populate the unique column
  46. Now we create a table with an identity column No more need for a sequence No more need for a trigger
  47. Don’t know about you, but I think doing less work is better.
  48. Hidden from select *
  49. Only visible when explicitly selected