SlideShare a Scribd company logo
The Features That
maybe
You Didn’t Know About
Oren Nakdimon
www.db-oriented.com
 oren@db-oriented.com
 +972-54-4393763
@DBoriented
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
WHO AM I?
A CHRONOLOGY BY “ORACLE YEARS”
Where: IAF
When: Oracle 6/7 [1991-1997]
What: Developer
Where: Golden Screens
When: Oracle 8 [1997-1998]
What: Server Group Manager
Where: TELEknowledge
When: Oracle 8i/9i [1998-2003]
What: DBA Group Manager
Where: Olista
When: Oracle 10g/11g [2004-2011]
What: VP R&D + Israel Site Manager
Where:
When: Oracle 11g/12c [2011-]
What: Freelance Consultant
Where:
When: 2012-
What: Database
Architect / Developer / DBA
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
@DBORIENTED
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
HTTP://DB-ORIENTED.COM
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
 Join ilOUG meetup group
 Download presentations
 Give us your feedback
 About this meeting
 What do you want to hear and see next?
 Initiate and participate in discussions
 Propose your presentation for upcoming
meetings
http://www.meetup.com/ilOUG-Oracle-Technologies-Meetup/
iloug16@gmail.com
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
SQL
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Aggregate
Functions
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
select department_id,
MIN(salary)
from employees
group by department_id;
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 117Sigal Tobias 2800.00
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
90 102Lex De Haan 17000.00
90 101Neena Kochhar 17000.00
30 115Alexander Khoo 3100.00
60 104Bruce Ernst 6000.00
30 116Shelli Baida 2900.00
60 106Valli Pataballa 4800.00
30 114Den Raphaely 11000.00
90 100Steven King 24000.00
60 103Alexander Hunold 9000.00
60 105David Austin 4800.00
60 107Diana Lorentz 4200.00
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
select department_id,
MIN(salary)
from employees
group by department_id;
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
30 117Sigal Tobias 2800.00
30 116Shelli Baida 2900.00
30 115Alexander Khoo 3100.00
30 114Den Raphaely 11000.00
60 107Diana Lorentz 4200.00
60 106Valli Pataballa 4800.00
60 105David Austin 4800.00
60 104Bruce Ernst 6000.00
60 103Alexander Hunold 9000.00
90 101Neena Kochhar 17000.00
90 102Lex De Haan 17000.00
90 100Steven King 24000.00
DEPARTMENT_ID MIN(SALARY)
30 2500.00
60 4200.00
90 17000.00
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
30 117Sigal Tobias 2800.00
30 116Shelli Baida 2900.00
30 115Alexander Khoo 3100.00
30 114Den Raphaely 11000.00
60 107Diana Lorentz 4200.00
60 106Valli Pataballa 4800.00
60 105David Austin 4800.00
60 104Bruce Ernst 6000.00
60 103Alexander Hunold 9000.00
90 101Neena Kochhar 17000.00
90 102Lex De Haan 17000.00
90 100Steven King 24000.00
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Aggregate
Functions
FIRST
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
THE FIRST FUNCTION
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
30 117Sigal Tobias 2800.00
30 116Shelli Baida 2900.00
30 115Alexander Khoo 3100.00
30 114Den Raphaely 11000.00
60 107Diana Lorentz 4200.00
60 106Valli Pataballa 4800.00
60 105David Austin 4800.00
60 104Bruce Ernst 6000.00
60 103Alexander Hunold 9000.00
90 101Neena Kochhar 17000.00
90 102Lex De Haan 17000.00
90 100Steven King 24000.00
select
department_id,
min(first_name) keep(dense_rank FIRST order by salary)
from employees
group by department_id;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
THE FIRST FUNCTION
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
30 117Sigal Tobias 2800.00
30 116Shelli Baida 2900.00
30 115Alexander Khoo 3100.00
30 114Den Raphaely 11000.00
60 107Diana Lorentz 4200.00
60 106Valli Pataballa 4800.00
60 105David Austin 4800.00
60 104Bruce Ernst 6000.00
60 103Alexander Hunold 9000.00
90 101Neena Kochhar 17000.00
90 102Lex De Haan 17000.00
90 100Steven King 24000.00
select
department_id,
min(first_name) keep(dense_rank FIRST order by salary)
from employees
group by department_id;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
THE FIRST FUNCTION
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
30 117Sigal Tobias 2800.00
30 116Shelli Baida 2900.00
30 115Alexander Khoo 3100.00
30 114Den Raphaely 11000.00
60 107Diana Lorentz 4200.00
60 106Valli Pataballa 4800.00
60 105David Austin 4800.00
60 104Bruce Ernst 6000.00
60 103Alexander Hunold 9000.00
90 101Neena Kochhar 17000.00
90 102Lex De Haan 17000.00
90 100Steven King 24000.00
select
department_id,
min(first_name) keep(dense_rank FIRST order by salary)
from employees
group by department_id;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
THE FIRST FUNCTION
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
30 117Sigal Tobias 2800.00
30 116Shelli Baida 2900.00
30 115Alexander Khoo 3100.00
30 114Den Raphaely 11000.00
60 107Diana Lorentz 4200.00
60 106Valli Pataballa 4800.00
60 105David Austin 4800.00
60 104Bruce Ernst 6000.00
60 103Alexander Hunold 9000.00
90 101Neena Kochhar 17000.00
90 102Lex De Haan 17000.00
90 100Steven King 24000.00
select
department_id,
min(first_name) keep(dense_rank FIRST order by salary)
from employees
group by department_id;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
THE FIRST FUNCTION
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
30 117Sigal Tobias 2800.00
30 116Shelli Baida 2900.00
30 115Alexander Khoo 3100.00
30 114Den Raphaely 11000.00
60 107Diana Lorentz 4200.00
60 106Valli Pataballa 4800.00
60 105David Austin 4800.00
60 104Bruce Ernst 6000.00
60 103Alexander Hunold 9000.00
90 101Neena Kochhar 17000.00
90 102Lex De Haan 17000.00
90 100Steven King 24000.00
select
department_id,
min(first_name) keep(dense_rank FIRST order by salary)
from employees
group by department_id;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
THE FIRST FUNCTION
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
30 117Sigal Tobias 2800.00
30 116Shelli Baida 2900.00
30 115Alexander Khoo 3100.00
30 114Den Raphaely 11000.00
60 107Diana Lorentz 4200.00
60 106Valli Pataballa 4800.00
60 105David Austin 4800.00
60 104Bruce Ernst 6000.00
60 103Alexander Hunold 9000.00
90 101Neena Kochhar 17000.00
90 102Lex De Haan 17000.00
90 100Steven King 24000.00
select
department_id,
min(first_name) keep(dense_rank FIRST order by salary)
from employees
group by department_id;
DEPARTMENT_ID MIN(FIRST_NAME)…
30Karen
60Diana
90Lex
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Aggregate
Functions
LAST
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
THE LAST FUNCTION
DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY
30 119Karen Colmenares 2500.00
30 118Guy Himuro 2600.00
30 117Sigal Tobias 2800.00
30 116Shelli Baida 2900.00
30 115Alexander Khoo 3100.00
30 114Den Raphaely 11000.00
60 107Diana Lorentz 4200.00
60 106Valli Pataballa 4800.00
60 105David Austin 4800.00
60 104Bruce Ernst 6000.00
60 103Alexander Hunold 9000.00
90 101Neena Kochhar 17000.00
90 102Lex De Haan 17000.00
90 100Steven King 24000.00
select
department_id,
min(first_name) keep(dense_rank LAST order by salary)
from employees
group by department_id;
DEPARTMENT_ID MIN(FIRST_NAME)…
30Den
60Alexander
90Steven
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
WHAT IS THE MOST COMMON JOB IN EACH DEPARTMENT?
select department_id,
min(job_id) keep(dense_rank last order by cnt)
from (select department_id,
job_id,
count(*) cnt
from employees
group by department_id,
job_id)
group by department_id;
DEPARTMENT_ID JOB_ID CNT
------------- ---------------------------- ----------
90 AD_VP 2
30 PU_CLERK 5
60 IT_PROG 5
90 AD_PRES 1
30 PU_MAN 1
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
WHAT IS THE MOST COMMON JOB IN EACH DEPARTMENT?
select department_id,
min(job_id) keep(dense_rank last order by cnt)
from (select department_id,
job_id,
count(*) cnt
from employees
group by department_id,
job_id)
group by department_id;
DEPARTMENT_ID MIN(JOB_ID)KEEP(DENSE_RANKLAST
------------- ------------------------------
30 PU_CLERK
60 IT_PROG
90 AD_VP
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Aggregate
Functions
STATS_MODE
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
WHAT IS THE MOST COMMON JOB IN EACH DEPARTMENT?
select department_id,
stats_mode(job_id)
from employees
group by department_id;
DEPARTMENT_ID MIN(JOB_ID)KEEP(DENSE_RANKLAST
------------- ------------------------------
30 PU_CLERK
60 IT_PROG
90 AD_VP
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Collections
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE
I have this table:
select * from country_test;
c1 c2 c3 c4
————— ————— ————— ——————
india us china uk
india india china uk
india china china uk
us us us uk
I need the distinct count of countries across the c1,c2,c3,c4 columns
of the table, so the output has to be
c1 c2 c3 c4 cnt
————— ————— ————— ——— ————
india us china uk 4
india india china uk 3
india china china uk 3
us us us uk 2
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:8749607800346631637
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE
ops$tkyte%ORA11GR2> with data(r)
2 as
3 (select 1 r from dual
4 union all
5 select r+1 from data where r < 4
6 )
7 select c1, c2, c3, c4, count(distinct c) cnt
8 from (
9 select rowid rid,
10 c1, c2, c3, c4,
11 decode(r,1,c1,2,c2,3,c3,4,c4) c
12 from data, country_test
13 )
14 group by rid, c1, c2, c3, c4
15 /
C1 C2 C3 C4 CNT
---------- ---------- ---------- ---------- ----------
india us china uk 4
us us us uk 2
india india china uk 3
india china china uk 3
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:8749607800346631637
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE
with data as (select rownum r,c1,c2,c3,c4
from ctest)
select listagg(rpad(val,21),'') within
group (order by column_list) orig
,count(distinct val) countries
from
(
select * from data
unpivot (val for column_list in
(c1,c2,c3,c4))
)
group by r
order by r;
select * from country_test,
lateral(
select count(distinct c) cnt from (
select c1 c from dual union all
select c2 from dual union all
select c3 from dual union all
select c4 from dual
)
);
select country_test.*, cnt_tab.cnt
from country_test,
(
select count(1) cnt, rid
from (
select rowid rid, c1 c from country_test
union select rowid, c2 from country_test
union select rowid, c3 from country_test
union select rowid, c4 from country_test
)
group by rid
) cnt_tab
where country_test.rowid = cnt_tab.rid
select * from country_test,
lateral(
select count(distinct val) cnt from (
select c1,c2,c3,c4 from dual
) unpivot(val for col in (c1,c2,c3,c4))
);
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE
create type string_ntt as
table of varchar2(4000)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Collections
Default
Constructor
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE
create type string_ntt as
table of varchar2(4000)
select
string_ntt('John','Paul','George','Ringo') beatles
from dual;
BEATLES
----------------------------------------------
STRING_NTT('John', 'Paul', 'George', 'Ringo')
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE
create type string_ntt as
table of varchar2(4000)
select
c.*,
cardinality(set(string_ntt(c1,c2,c3,c4)))
from country_test c;
C1 C2 C3 C4 STRING_NTT(C1,C2,C3,C4)
----- ----- ----- ----- --------------------------------------------------
india us china uk STRING_NTT('india', 'us', 'china', 'uk')
india india china uk STRING_NTT('india', 'india', 'china', 'uk')
india china china uk STRING_NTT('india', 'china', 'china', 'uk')
us us us uk STRING_NTT('us', 'us', 'us', 'uk')
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Collections
SET
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE
select
c.*,
cardinality(set(string_ntt(c1,c2,c3,c4)))
from country_test c;
C1 C2 C3 C4 SET(STRING_NTT(C1,C2,C3,C4))
----- ----- ----- ----- ----------------------------------------
india us china uk STRING_NTT('india', 'us', 'china', 'uk')
india india china uk STRING_NTT('india', 'china', 'uk')
india china china uk STRING_NTT('india', 'china', 'uk')
us us us uk STRING_NTT('us', 'uk')
C1 C2 C3 C4 STRING_NTT(C1,C2,C3,C4)
----- ----- ----- ----- --------------------------------------------------
india us china uk STRING_NTT('india', 'us', 'china', 'uk')
india india china uk STRING_NTT('india', 'india', 'china', 'uk')
india china china uk STRING_NTT('india', 'china', 'china', 'uk')
us us us uk STRING_NTT('us', 'us', 'us', 'uk')
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Collections
CARDINALITY
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE
select
c.*,
cardinality(set(string_ntt(c1,c2,c3,c4)))
from country_test c;
C1 C2 C3 C4 CARDINALITY(SET(STRING_NTT(C1,C2,C3,C4)))
----- ----- ----- ----- -----------------------------------------
india us china uk 4
india india china uk 3
india china china uk 3
us us us uk 2
C1 C2 C3 C4 SET(STRING_NTT(C1,C2,C3,C4))
----- ----- ----- ----- ----------------------------------------
india us china uk STRING_NTT('india', 'us', 'china', 'uk')
india india china uk STRING_NTT('india', 'china', 'uk')
india china china uk STRING_NTT('india', 'china', 'uk')
us us us uk STRING_NTT('us', 'uk')
C1 C2 C3 C4 STRING_NTT(C1,C2,C3,C4)
----- ----- ----- ----- --------------------------------------------------
india us china uk STRING_NTT('india', 'us', 'china', 'uk')
india india china uk STRING_NTT('india', 'india', 'china', 'uk')
india china china uk STRING_NTT('india', 'china', 'china', 'uk')
us us us uk STRING_NTT('us', 'us', 'us', 'uk')
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Collections
Unnesting
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
COLLECTION UNNESTING
select *
from
table(string_ntt('John','Paul','George','Ringo'));
COLUMN_VALUE
---------------------
John
Paul
George
Ringo
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
KAKURO
 Digits 1-9
 Sum = associated
clue
 No duplications
6 = 1+2+3
12 = 1+2+3+6
12 = 1+2+4+5
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
> select *
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)));
COLUMN_VALUE
-------------------------
create type integer_ntt as table of integer
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Collections
POWERMULTISET
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
> select *
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)));
COLUMN_VALUE
-------------------------
INTEGER_NTT(1)
INTEGER_NTT(2)
INTEGER_NTT(1, 2)
INTEGER_NTT(3)
INTEGER_NTT(1, 3)
INTEGER_NTT(2, 3)
INTEGER_NTT(1, 2, 3)
INTEGER_NTT(4)
INTEGER_NTT(1, 4)
INTEGER_NTT(2, 4)
INTEGER_NTT(1, 2, 4)
INTEGER_NTT(3, 4)
INTEGER_NTT(1, 3, 4)
INTEGER_NTT(2, 3, 4)
INTEGER_NTT(1, 2, 3, 4)
INTEGER_NTT(5)
...
INTEGER_NTT(1, 3, 4, 5, 6, 7, 8, 9)
INTEGER_NTT(2, 3, 4, 5, 6, 7, 8, 9)
INTEGER_NTT(1, 2, 3, 4, 5, 6, 7, 8, 9)
511 rows selected.
create type integer_ntt as table of integer
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
> select *
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)));
COLUMN_VALUE
-------------------------
INTEGER_NTT(1)
INTEGER_NTT(2)
INTEGER_NTT(1, 2)
INTEGER_NTT(3)
INTEGER_NTT(1, 3)
INTEGER_NTT(2, 3)
INTEGER_NTT(1, 2, 3)
INTEGER_NTT(4)
INTEGER_NTT(1, 4)
INTEGER_NTT(2, 4)
INTEGER_NTT(1, 2, 4)
INTEGER_NTT(3, 4)
INTEGER_NTT(1, 3, 4)
INTEGER_NTT(2, 3, 4)
INTEGER_NTT(1, 2, 3, 4)
INTEGER_NTT(5)
...
INTEGER_NTT(1, 3, 4, 5, 6, 7, 8, 9)
INTEGER_NTT(2, 3, 4, 5, 6, 7, 8, 9)
INTEGER_NTT(1, 2, 3, 4, 5, 6, 7, 8, 9)
511 rows selected.
create type integer_ntt as table of integer
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
break on x on num_of_elements skip 1
select sum(b.column_value) x,
a.num_of_elements,
listagg(b.column_value,'+') within group(order by b.column_value) expr
from (select rownum id ,
cardinality(column_value) num_of_elements,
column_value combination
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a,
table(a.combination) b
where a.num_of_elements > 1
group by a.id,a.num_of_elements
order by x,num_of_elements,expr;
ID NUM_OF_ELEMENTS COMBINATION
---------- --------------- --------------------------------------------------------------
1 1 INTEGER_NTT(1)
2 1 INTEGER_NTT(2)
3 2 INTEGER_NTT(1, 2)
4 1 INTEGER_NTT(3)
5 2 INTEGER_NTT(1, 3)
6 2 INTEGER_NTT(2, 3)
7 3 INTEGER_NTT(1, 2, 3)
...
508 7 INTEGER_NTT(3, 4, 5, 6, 7, 8, 9)
509 8 INTEGER_NTT(1, 3, 4, 5, 6, 7, 8, 9)
510 8 INTEGER_NTT(2, 3, 4, 5, 6, 7, 8, 9)
511 9 INTEGER_NTT(1, 2, 3, 4, 5, 6, 7, 8, 9)
511 rows selected.
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
break on x on num_of_elements skip 1
select sum(b.column_value) x,
a.num_of_elements,
select a.*,b.column_value
from (select rownum id ,
cardinality(column_value) num_of_elements,
column_value combination
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a,
table(a.combination) b
where a.num_of_elements > 1
group by a.id,a.num_of_elements
order by x,num_of_elements,expr;
ID NUM_OF_ELEMENTS COMBINATION COLUMN_VALUE
---------- --------------- -------------------- ------------
1 1 INTEGER_NTT(1) 1
2 1 INTEGER_NTT(2) 2
3 2 INTEGER_NTT(1, 2) 1
3 2 INTEGER_NTT(1, 2) 2
4 1 INTEGER_NTT(3) 3
5 2 INTEGER_NTT(1, 3) 1
5 2 INTEGER_NTT(1, 3) 3
6 2 INTEGER_NTT(2, 3) 2
6 2 INTEGER_NTT(2, 3) 3
7 3 INTEGER_NTT(1, 2, 3) 1
7 3 INTEGER_NTT(1, 2, 3) 2
7 3 INTEGER_NTT(1, 2, 3) 3
...
2304 rows selected.
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
1+2+3=6
1+2=3
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
break on x on num_of_elements skip 1
select sum(b.column_value) x,
a.num_of_elements,
listagg(b.column_value,'+') within group(order by b.column_value) expr
from (select rownum id ,
cardinality(column_value) num_of_elements,
column_value combination
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a,
table(a.combination) b
where a.num_of_elements > 1
group by a.id,a.num_of_elements
order by x,num_of_elements,expr;
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
X NUM_OF_ELEMENTS EXPR
---------- --------------- ----------
3 2 1+2
4 2 1+3
5 2 1+4
2+3
6 2 1+5
2+4
3 1+2+3
7 2 1+6
2+5
3+4
3 1+2+4
X NUM_OF_ELEMENTS EXPR
---------- --------------- --------------------
41 7 2+4+5+6+7+8+9
8 1+2+3+5+6+7+8+9
42 7 3+4+5+6+7+8+9
8 1+2+4+5+6+7+8+9
43 8 1+3+4+5+6+7+8+9
44 8 2+3+4+5+6+7+8+9
45 9 1+2+3+4+5+6+7+8+9
502 rows selected.
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
break on x on num_of_elements skip 1
select sum(b.column_value) x,
a.num_of_elements,
listagg(b.column_value,'+') within group(order by b.column_value) expr
from (select rownum id ,
cardinality(column_value) num_of_elements,
column_value combination
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a,
table(a.combination) b
where a.num_of_elements > 1
group by a.id,a.num_of_elements
order by x,num_of_elements,expr;
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
X NUM_OF_ELEMENTS EXPR
---------- --------------- ----------
3 2 1+2
4 2 1+3
5 2 1+4
2+3
6 2 1+5
2+4
3 1+2+3
7 2 1+6
2+5
3+4
3 1+2+4
X NUM_OF_ELEMENTS EXPR
---------- --------------- --------------------
41 7 2+4+5+6+7+8+9
8 1+2+3+5+6+7+8+9
42 7 3+4+5+6+7+8+9
8 1+2+4+5+6+7+8+9
43 8 1+3+4+5+6+7+8+9
44 8 2+3+4+5+6+7+8+9
45 9 1+2+3+4+5+6+7+8+9
502 rows selected.
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
break on x on num_of_elements skip 1
select sum(b.column_value) x,
a.num_of_elements,
listagg(b.column_value,'+') within group(order by b.column_value) expr
from (select rownum id ,
cardinality(column_value) num_of_elements,
column_value combination
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a,
table(a.combination) b
where a.num_of_elements > 1
group by a.id,a.num_of_elements
order by x,num_of_elements,expr;
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
X NUM_OF_ELEMENTS EXPR
---------- --------------- ----------
3 2 1+2
4 2 1+3
5 2 1+4
2+3
6 2 1+5
2+4
3 1+2+3
7 2 1+6
2+5
3+4
3 1+2+4
X NUM_OF_ELEMENTS EXPR
---------- --------------- --------------------
41 7 2+4+5+6+7+8+9
8 1+2+3+5+6+7+8+9
42 7 3+4+5+6+7+8+9
8 1+2+4+5+6+7+8+9
43 8 1+3+4+5+6+7+8+9
44 8 2+3+4+5+6+7+8+9
45 9 1+2+3+4+5+6+7+8+9
502 rows selected.
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
break on x on num_of_elements skip 1
select sum(b.column_value) x,
a.num_of_elements,
listagg(b.column_value,'+') within group(order by b.column_value) expr
from (select rownum id ,
cardinality(column_value) num_of_elements,
column_value combination
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a,
table(a.combination) b
where a.num_of_elements > 1
group by a.id,a.num_of_elements
order by x,num_of_elements,expr;
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
X NUM_OF_ELEMENTS EXPR
---------- --------------- ----------
3 2 1+2
4 2 1+3
5 2 1+4
2+3
6 2 1+5
2+4
3 1+2+3
7 2 1+6
2+5
3+4
3 1+2+4
X NUM_OF_ELEMENTS EXPR
---------- --------------- --------------------
41 7 2+4+5+6+7+8+9
8 1+2+3+5+6+7+8+9
42 7 3+4+5+6+7+8+9
8 1+2+4+5+6+7+8+9
43 8 1+3+4+5+6+7+8+9
44 8 2+3+4+5+6+7+8+9
45 9 1+2+3+4+5+6+7+8+9
502 rows selected.
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
break on x on num_of_elements skip 1
select sum(b.column_value) x,
a.num_of_elements,
listagg(b.column_value,'+') within group(order by b.column_value) expr
from (select rownum id ,
cardinality(column_value) num_of_elements,
column_value combination
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a,
table(a.combination) b
where a.num_of_elements > 1
group by a.id,a.num_of_elements
order by x,num_of_elements,expr;
X NUM_OF_ELEMENTS EXPR
---------- --------------- ----------
3 2 1+2
4 2 1+3
5 2 1+4
2+3
6 2 1+5
2+4
3 1+2+3
7 2 1+6
2+5
3+4
3 1+2+4
X NUM_OF_ELEMENTS EXPR
---------- --------------- --------------------
41 7 2+4+5+6+7+8+9
8 1+2+3+5+6+7+8+9
42 7 3+4+5+6+7+8+9
8 1+2+4+5+6+7+8+9
43 8 1+3+4+5+6+7+8+9
44 8 2+3+4+5+6+7+8+9
45 9 1+2+3+4+5+6+7+8+9
502 rows selected.
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PIVOT
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
break on x skip 1
select * from (
select sum(b.column_value) x,
a.num_of_elements,
listagg(b.column_value,'+') within group(order by b.column_value) expr
from (select rownum id ,
cardinality(column_value) num_of_elements,
column_value combination
from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a,
table(a.combination) b
where a.num_of_elements > 1
group by a.id,a.num_of_elements
)
pivot (listagg(expr, chr(10)) within group (order by expr)
for num_of_elements in(2,3,4,5,6,7,8,9));
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
X 2 3 4 5 6 7 8 9
-- ---- ------ -------- ---------- ------------ -------------- ---------------- ---------
3 1+2
4 1+3
5 1+4
2+3
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
pivot (listagg(expr, chr(10)) within group (order by expr)
for num_of_elements in(2,3,4,5,6,7,8,9));
http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
X 2 3 4 5 6 7 8 9
-- ---- ------ -------- ---------- ------------ -------------- ---------------- ---------
3 1+2
4 1+3
5 1+4
2+3
6 1+5 1+2+3
2+4
21 4+8+9 1+3+8+9 1+2+3+6+9 1+2+3+4+5+6
5+7+9 1+4+7+9 1+2+3+7+8
6+7+8 1+5+6+9 1+2+4+5+9
1+5+7+8 1+2+4+6+8
2+3+7+9 1+2+5+6+7
2+4+6+9 1+3+4+5+8
2+4+7+8 1+3+4+6+7
2+5+6+8 2+3+4+5+7
3+4+5+9
3+4+6+8
3+5+6+7
44 2+3+4+5+6+7+8+9
45 1+2+3+4+…
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Recursive
Subquery
Factoring
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
RECURSIVE SUBQUERY FACTORING
with fib(x,f) as (
select 1 as x, 1 as f from dual
union all
select f, x+f from fib where x+f <= &n
)
select f
from fib;
anchor member
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
RECURSIVE SUBQUERY FACTORING
with fib(x,f) as (
select 1 as x, 1 as f from dual
union all
select f, x+f from fib where x+f <= &n
)
select f
from fib;
anchor member
recursive member
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
RECURSIVE SUBQUERY FACTORING
with fib(x,f) as (
select 1 as x, 1 as f from dual
union all
select f, x+f from fib where x+f <= &n
)
select f
from fib;
Enter value for n: 121
F
----------
1
2
3
5
8
13
21
34
55
89
10 rows selected.
anchor member
recursive member
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Pattern
Matching
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
THE MOST BASIC SQL
 Row-level visibility
 Maximum one output row per input row
 WHERE clause
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
AGGREGATE FUNCTIONS
 Group-level visibility
 Strict definition of “group”
 Each input row belongs to exactly one group
 Maximum one output row per group
 GROUP BY clause
 HAVING clause
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
 Window-level visibility
 Strict definition of “window”
 Each input row has its own window
 Window-level aggregates are added to input
rows
 OVER
 PARTITION BY
 ORDER BY
ANALYTIC (WINDOW) FUNCTIONS
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
 Window-level visibility
 Strict definition of “window”
 Each input row has its own window
 Window-level aggregates are added to input
rows
 OVER
 PARTITION BY
 ORDER BY
ANALYTIC (WINDOW) FUNCTIONS
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
ANALYTIC (WINDOW) FUNCTIONS
 Window-level visibility
 Strict definition of “window”
 Each input row has its own window
 Window-level aggregates are added to input
rows
 OVER
 PARTITION BY
 ORDER BY
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PATTERN MATCHING
 Enhanced analysis of row sequences
 Match-based output
 One row per match (similar to the “group by” concept)
or
 All the match’s input rows (similar to the “window” concept)
 Each input row may belong to 0, 1 or more
matches
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PATTERN MATCHING
Zeckendorf's theorem
Every positive integer can be represented uniquely as the sum of distinct
non-consecutive Fibonacci numbers, and this representation can be found by
using a greedy algorithm, choosing the largest possible Fibonacci number at
each stage.
6 = 5 + 1 122 = 89 + 21 + 8 + 3 + 117 = 13 + 3 + 1 34 = 34
http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PATTERN MATCHING
http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/
with fib(x,f) as (
select 1 as x, 1 as f from dual
union all
select f, x+f from fib where x+f <= &n
)
select f
from fib
match_recognize(
order by f desc
all rows per match
pattern ((A|{-B-})+)
define A as sum(A.f) <= &n
)
F
1
2
3
5
8
13
21
34
55
89
n = 121
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PATTERN MATCHING
http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/
with fib(x,f) as (
select 1 as x, 1 as f from dual
union all
select f, x+f from fib where x+f <= &n
)
select f
from fib
match_recognize(
order by f desc
all rows per match
pattern ((A|{-B-})+)
define A as sum(A.f) <= &n
)
F
89
55
34
21
13
8
5
3
2
1
n = 121
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PATTERN MATCHING
http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/
with fib(x,f) as (
select 1 as x, 1 as f from dual
union all
select f, x+f from fib where x+f <= &n
)
select f
from fib
match_recognize(
order by f desc
all rows per match
pattern ((A|{-B-})+)
define A as sum(A.f) <= &n
)
F
89
55
34
21
13
8
5
3
2
1
A




n = 121
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PATTERN MATCHING
http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/
with fib(x,f) as (
select 1 as x, 1 as f from dual
union all
select f, x+f from fib where x+f <= &n
)
select f
from fib
match_recognize(
order by f desc
all rows per match
pattern ((A|{-B-})+)
define A as sum(A.f) <= &n
)
F
89
55
34
21
13
8
5
3
2
1
A




n = 121
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PATTERN MATCHING
http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/
with fib(x,f) as (
select 1 as x, 1 as f from dual
union all
select f, x+f from fib where x+f <= &n
)
select f
from fib
match_recognize(
order by f desc
all rows per match
pattern ((A|{-B-})+)
define A as sum(A.f) <= &n
)
F
89
55
34
21
13
8
5
3
2
1
A




n = 121
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PATTERN MATCHING
http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/
with fib(x,f) as (
select 1 as x, 1 as f from dual
union all
select f, x+f from fib where x+f <= &n
)
select f
from fib
match_recognize(
order by f desc
all rows per match
pattern ((A|{-B-})+)
define A as sum(A.f) <= &n
)
F
89
21
8
3
A




n = 121
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Oracle
Locator
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
create table stops (
stop_id varchar2(20) constraint stops_pk primary key,
stop_code varchar2(20),
stop_name varchar2(100),
stop_location mdsys.sdo_geometry
);
stops.txt
insert into user_sdo_geom_metadata
(table_name,column_name,diminfo,srid)
values ('STOPS',
'STOP_LOCATION',
mdsys.sdo_dim_array(
mdsys.sdo_dim_element('LONG', -180.0, 180.0, 0.05),
mdsys.sdo_dim_element('LAT', -90.0, 90.0, 0.05)),
8307);
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
CREATE TABLE STOPS_EXT (stop_id varchar2(20),
stop_code varchar2(20),
stop_name varchar2(100),
stop_desc varchar2(100),
stop_lat number,
stop_lon number,
location_type number(1),
parent_location varchar2(20),
zone_id number)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY EXT_TABLES_DIR
ACCESS PARAMETERS (
records delimited by 0x'0d0a'
characterset UTF8
skip 1
logfile EXT_TABLES_DIR:'stops_%p_%a.log'
badfile EXT_TABLES_DIR:'stops_%p_%a.txt'
fields terminated by ',' optionally enclosed by '"'
missing field values are null
reject rows with all null fields
)
LOCATION ('stops.txt')
)
REJECT LIMIT UNLIMITED;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
insert /*+ append */ into stops (
stop_id,
stop_code,
stop_name,
stop_location)
select stop_id,
stop_code,
stop_name,
mdsys.sdo_geometry(2001, -- 2 dimensional point
8307, -- lat/long coordinate system
mdsys.sdo_point_type(stop_lon,
stop_lat,
null),
null, -- n/a for point type
null) -- n/a for point type
from stops_ext;
commit;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
External
Tables
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
insert /*+ append */ into stops (
stop_id,
stop_code,
stop_name,
stop_location)
select stop_id,
stop_code,
stop_name,
mdsys.sdo_geometry(2001, -- 2 dimensional point
8307, -- lat/long coordinate system
mdsys.sdo_point_type(stop_lon,
stop_lat,
null),
null, -- n/a for point type
null) -- n/a for point type
from stops_ext;
commit;
create index stops_location_idx
on stops (stop_location)
indextype is mdsys.spatial_index
parameters ('layer_gtype=POINT');
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
(34.863356, 32.101307)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
STOP_CODE STOP_NAME LONGITUDE LATITUDE
---------- -------------------------------- --------- ---------
33080 ‫השפלה‬/‫אימבר‬ 34.860736 32.097785
30990 ‫המושבות‬ ‫אם‬ ‫דרך‬/‫השפלה‬ 34.858287 32.101256
35378 ‫אריה‬ ‫קרית‬ ‫רכבת‬ ‫תחנת‬ 34.86375 32.104148
31424 ‫אריה‬ ‫קריית‬ ‫רכבת‬/‫וסע‬ ‫חנה‬ 34.863596 32.105353
38334 ‫המושבות‬ ‫אם‬ ‫דרך‬/‫המר‬ ‫זבולון‬ ‫דרך‬ 34.867824 32.10336
38143 ‫גיסין‬ ‫אבשלום‬/‫דיין‬ ‫משה‬ 34.86262 32.096893
32172 ‫גיסין‬ ‫אבשלום‬/‫בזל‬ 34.864442 32.097726
32231 ‫גיסין‬ ‫אבשלום‬/‫בזל‬ 34.866672 32.098263
8 rows selected.
Elapsed: 00:00:00.13
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 275 | 16775 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | STOPS | 275 | 16775 | 3 (0)| 00:00:01 |
|* 2 | DOMAIN INDEX (SEL: 0.100000 %)| STOPS_LOCATION_IDX | | | 3 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------
SELECT s.stop_code,
s.stop_name,
s.stop_location.sdo_point.x longitude,
s.stop_location.sdo_point.y latitude
FROM stops s
WHERE sdo_within_distance(
s.stop_location,
sdo_geometry(2001,8307,
sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL),
'distance=500 unit=meter') = 'TRUE';
All the stops
within 500
meters
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
GEOMETRY AGGREGATION
SELECT sdo_util.to_wktgeometry(
sdo_aggr_union(sdoaggrtype(s.stop_location,0.05)))
FROM stops s
WHERE sdo_within_distance(
s.stop_location,
sdo_geometry(2001,8307,
sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL),
'distance=500 unit=meter') = 'TRUE';
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
GEOMETRY AGGREGATION
SELECT sdo_util.to_wktgeometry(
sdo_aggr_union(sdoaggrtype(s.stop_location,0.05)))
FROM stops s
WHERE sdo_within_distance(
s.stop_location,
sdo_geometry(2001,8307,
sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL),
'distance=500 unit=meter') = 'TRUE';
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
GEOMETRY AGGREGATION
SELECT sdo_util.to_wktgeometry(
sdo_aggr_union(sdoaggrtype(s.stop_location,0.05)))
FROM stops s
WHERE sdo_within_distance(
s.stop_location,
sdo_geometry(2001,8307,
sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL),
'distance=500 unit=meter') = 'TRUE';
MULTIPOINT ((34.866672 32.098263), (34.864442 32.097726), (34.86262
32.096893), (34.867824 32.10336), (34.863596 32.105353), (34.86375
32.104148), (34.858287 32.101256), (34.860736 32.097785))
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
MULTIPOINT ((34.866672 32.098263), (34.864442 32.097726), (34.86262
32.096893), (34.867824 32.10336), (34.863596 32.105353), (34.86375
32.104148), (34.858287 32.101256), (34.860736 32.097785))
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
SELECT s.stop_code,
s.stop_name,
s.stop_location.sdo_point.x longitude,
s.stop_location.sdo_point.y latitude
FROM stops s
WHERE sdo_nn(
s.stop_location,
sdo_geometry(2001,8307,
sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL),
'sdo_num_res=3') = 'TRUE';
STOP_CODE STOP_NAME LONGITUDE LATITUDE
---------- ----------------------- --------- ----------
35378 ‫אריה‬ ‫קרית‬ ‫רכבת‬ ‫תחנת‬ 34.86375 32.104148
32172 ‫גיסין‬ ‫אבשלום‬/‫בזל‬ 34.864442 32.097726
31424 ‫אריה‬ ‫קריית‬ ‫רכבת‬/‫וסע‬ ‫חנה‬ 34.863596 32.105353
3 rows selected.
Elapsed: 00:00:00.21
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 28 | 1708 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | STOPS | 28 | 1708 | 3 (0)| 00:00:01 |
|* 2 | DOMAIN INDEX (SEL: 0.100000 %)| STOPS_LOCATION_IDX | | | 3 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------
3 nearest
stops
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
SELECT round(sdo_nn_distance(1)) dist_meters,
s.stop_code,
s.stop_name
FROM stops s
WHERE sdo_nn(
s.stop_location,
sdo_geometry(2001,8307,
sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL),
'sdo_num_res=3',1) = 'TRUE'
order by dist_meters;
DIST_METERS STOP_CODE STOP_NAME
----------- ---------- ---------------------------------------------------------------------------
317 35378 ‫אריה‬ ‫קרית‬ ‫רכבת‬ ‫תחנת‬
410 32172 ‫גיסין‬ ‫אבשלום‬/‫בזל‬
449 31424 ‫אריה‬ ‫קריית‬ ‫רכבת‬/‫וסע‬ ‫חנה‬
3 rows selected.
Elapsed: 00:00:00.06
3 nearest
stops + their
distance
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
COUNTRIES AND POLYGONS
> desc countries
Name Null? Type
----------------------------- -------- --------------------
COUNTRY_ID NUMBER
COUNTRY_NAME VARCHAR2(100)
POLYGON MDSYS.SDO_GEOMETRY
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
WHICH COUNTRY CONTAINS OUR POINT?
COUNTRY_NAME
----------------------------
Israel
1 row selected.
Elapsed: 00:00:00.03
---------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 48 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | COUNTRIES | 2 | 48 | 2 (0)| 00:00:01 |
|* 2 | DOMAIN INDEX (SEL: 0.100000 %)| COUNTRIES_POLYGON_IDX | | | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------
select c.country_name
from countries c
where sdo_relate(
c.polygon,
sdo_geometry(2001,8307,
sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL),
'mask=contains') = 'TRUE';
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Online
Operations
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
ONLINE DDL OPERATIONS
Offline Operations Online Operations
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
ONLINE DDL OPERATIONS
Offline Operations Online Operations
Get ORA-54 due to active
transactions
Wait for active transactions to
end
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
ONLINE DDL OPERATIONS
Offline Operations Online Operations
Get ORA-54 due to active
transactions
Wait for active transactions to
end
Block new DML statements Do not block new DML
statements
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
THE KEYWORD ONLINE
 11g
 CREATE INDEX … [ONLINE]
 ALTER INDEX … REBUILD [ONLINE]
 12c
 ALTER TABLE … DROP CONSTRAINT … [ONLINE]
 ALTER TABLE … SET UNUSED … [ONLINE]
 DROP INDEX … [ONLINE]
 ALTER INDEX … UNUSABLE [ONLINE]
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
ONLINE OPERATIONS
 12c
 ALTER INDEX … INVISIBLE
 ALTER INDEX … VISIBLE
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Invisible
Indexes
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
INVISIBLE INDEXES
 Maintained by DML
 Invisible to the optimizer
 Unless optimizer_use_invisible_indexes is true
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
ONLINE OPERATIONS
 Adding a new column to a non-empty table
 An optional column with no default
 As of 11g, adding a mandatory column with default is
a meta-data only operation:
 Fast
 No space
 No redo
 No undo
 Online
 As of 12c, the same is true also for optional columns
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
“ALMOST ONLINE” OPERATIONS
> drop index t_idx;
drop index t_idx
*
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified
or timeout expired
Elapsed: 00:00:00.00
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
DDL_LOCK_TIMEOUT
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
“ALMOST ONLINE” OPERATIONS
> alter session set ddl_lock_timeout=2;
Session altered.
> drop index t_idx;
drop index t_idx
*
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified
or timeout expired
Elapsed: 00:00:02.02
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
“ALMOST ONLINE” OPERATIONS
> alter session set ddl_lock_timeout=2;
Session altered.
> drop index t_idx;
Index dropped.
Elapsed: 00:00:00.95
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
“ALMOST ONLINE” OPERATIONS
ALTER TABLE ADD CONSTRAINT
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Online
Operations
ENABLE
NOVALIDATE
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
“ALMOST ONLINE” OPERATIONS
ALTER TABLE ADD CONSTRAINT
ALTER TABLE ADD CONSTRAINT ENABLE NOVALIDATE
ALTER TABLE ENABLE VALIDATE CONSTRAINT
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
INDEX REBUILD?
index on T(CREATION_TIME)
select … from T where CREATION_TIME between …
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Index
Coalesce
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
INDEX REBUILD?
index on T(CREATION_TIME)
select … from T where CREATION_TIME between …
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
INDEX REBUILD?
index on T(CREATION_TIME)
select … from T where CREATION_TIME between …
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Edition
Based
Redefinition
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Procedure P
Procedure P
My Schema
Edition1
Edition2
procedure p is
begin
-- do something
end p;
create or replace
procedure p as
begin
-- do something else
end p;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Procedure
P
My Schema
Edition1
Edition2
Function
F
Procedure
P
View
V
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Procedure
P
My Schema
Edition1
Edition2
Function
F
Procedure
P
View
V
Edition3
Function
F
Package
PKG
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Procedure
P
My Schema
Edition1
procedure p is
...
select name
into ...
from people
...
Table
PEOPLE
- id
- name
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Procedure
P
My Schema
Edition1
Edition2
Edition3
Procedure
P
procedure p is
...
select name
into ...
from people
...
Table
PEOPLE
- id
- name
- first_name
- last_nameprocedure p is
...
select
first_name,
last_name
into ...
from people
...
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Procedure
P
My Schema
Edition1
Edition2
Edition3
Procedure
P
Editioning
View
PEOPLE
Editioning
View
PEOPLE
Table
PEOPLE$T
- id
- name
- first_name
- last_name
create editioning view people
as select id, name
from people$t
create editioning view people
as select id, first_name, last_name
from people$t
select name
into ...
from people
select
first_name, last_name
into ...
from people
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
I LOVE EBR BECAUSE…
 It enables to apply any change in an online
fashion
 The upgrade is performed in the privacy of a
new unexposed edition
 The upgrade can be done at any time
 Supported everywhere (since Oracle 11.2),
including standard edition
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
Partition
Views
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PARTITION VIEWS
T1
T2
T3
T4alter table add partition create table
create or replace view
drop tablealter table drop partition
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PARTITION VIEWS
> desc events_01
Name Null? Type
--------------------------- -------- ----------------------------
EVENT_ID NOT NULL NUMBER
EVENT_TIME NOT NULL DATE
EVENT_TYPE_ID NOT NULL NUMBER
DETAILS VARCHAR2(100)
create or replace view events as
select * from events_01
where event_time >= date'2016-01-01'
and event_time < date'2016-02-01'
union all
select * from events_02
where event_time >= date'2016-02-01'
and event_time < date'2016-03-01'
union all
select * from events_03
where event_time >= date'2016-03-01'
and event_time < date'2016-04-01'
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PARTITION VIEWS
select event_type_id,count(*)
from events
where event_time between date'2016-02-20' and date'2016-02-22'
group by event_Type_id;
-------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 21 | 19 (6)| 00:00:01 |
| 1 | HASH GROUP BY | | 7 | 21 | 19 (6)| 00:00:01 |
| 2 | VIEW | EVENTS | 2884 | 8652 | 18 (0)| 00:00:01 |
| 3 | UNION-ALL | | | | | |
|* 4 | FILTER | | | | | |
| 5 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_01 | 1 | 11 | 3 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | EVENT_01_TIME_IDX | 1 | | 2 (0)| 00:00:01 |
| 7 | TABLE ACCESS BY INDEX ROWID BATCHED | EVENTS_02 | 2882 | 31702 | 18 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | EVENT_02_TIME_IDX | 2882 | | 9 (0)| 00:00:01 |
|* 9 | FILTER | | | | | |
| 10 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_03 | 1 | 11 | 3 (0)| 00:00:01 |
|* 11 | INDEX RANGE SCAN | EVENT_03_TIME_IDX | 1 | | 2 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter(NULL IS NOT NULL)
6 - access("EVENT_TIME">=TO_DATE(' 2016-02-20 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME“ <TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
8 - access("EVENT_TIME">=TO_DATE(' 2016-02-20 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
9 - filter(NULL IS NOT NULL)
11 - access("EVENT_TIME">=TO_DATE(' 2016-03-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PARTITION VIEWS
select count(details)
from events
where event_time between date'2016-01-10' and date'2016-02-22'
and event_type_id = 1;
-------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 74 | 79 (2)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 74 | | |
| 2 | VIEW | EVENTS | 12366 | 893K| 79 (2)| 00:00:01 |
| 3 | UNION-ALL | | | | | |
|* 4 | TABLE ACCESS FULL | EVENTS_01 | 6367 | 99K| 40 (0)| 00:00:01 |
|* 5 | TABLE ACCESS FULL | EVENTS_02 | 5998 | 95968 | 38 (0)| 00:00:01 |
|* 6 | FILTER | | | | | |
|* 7 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_03 | 1 | 16 | 3 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | EVENT_03_TIME_IDX | 1 | | 2 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("EVENT_TYPE_ID"=1 AND
"EVENT_TIME">=TO_DATE(' 2016-01-10 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME"< TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
5 - filter("EVENT_TYPE_ID"=1 AND
"EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME">=TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
6 - filter(NULL IS NOT NULL)
7 - filter("EVENT_TYPE_ID"=1)
8 - access("EVENT_TIME">=TO_DATE(' 2016-03-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PARTITION VIEWS
select count(details)
from events
where event_time between date'2016-01-10' and date'2016-02-22'
and event_type_id = 1;
-------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 74 | 79 (2)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 74 | | |
| 2 | VIEW | EVENTS | 12366 | 893K| 79 (2)| 00:00:01 |
| 3 | UNION-ALL | | | | | |
|* 4 | TABLE ACCESS FULL | EVENTS_01 | 6367 | 99K| 40 (0)| 00:00:01 |
|* 5 | TABLE ACCESS FULL | EVENTS_02 | 5998 | 95968 | 38 (0)| 00:00:01 |
|* 6 | FILTER | | | | | |
|* 7 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_03 | 1 | 16 | 3 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | EVENT_03_TIME_IDX | 1 | | 2 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("EVENT_TYPE_ID"=1 AND
"EVENT_TIME">=TO_DATE(' 2016-01-10 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME"< TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
5 - filter("EVENT_TYPE_ID"=1 AND
"EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME">=TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
6 - filter(NULL IS NOT NULL)
7 - filter("EVENT_TYPE_ID"=1)
8 - access("EVENT_TIME">=TO_DATE(' 2016-03-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PARTITION VIEWS
select count(details)
from events
where event_time between date'2016-01-10' and date'2016-02-22'
and event_type_id = 6;
-------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 74 | 42 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 74 | | |
| 2 | VIEW | EVENTS | 2418 | 174K| 42 (0)| 00:00:01 |
| 3 | UNION-ALL | | | | | |
|* 4 | TABLE ACCESS FULL | EVENTS_01 | 2388 | 38208 | 40 (0)| 00:00:01 |
|* 5 | TABLE ACCESS BY INDEX ROWID BATCHED | EVENTS_02 | 29 | 464 | 2 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | EVENT_02_TYPE_IDX | 41 | | 1 (0)| 00:00:01 |
|* 7 | FILTER | | | | | |
|* 8 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_03 | 1 | 16 | 2 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | EVENT_03_TYPE_IDX | 1 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("EVENT_TYPE_ID"=6 AND
"EVENT_TIME">=TO_DATE(' 2016-01-10 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME“ <TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
5 - filter("EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME">=TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
6 - access("EVENT_TYPE_ID"=6)
7 - filter(NULL IS NOT NULL)
8 - filter("EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"EVENT_TIME">=TO_DATE(' 2016-03-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
9 - access("EVENT_TYPE_ID"=6)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon
PARTITION VIEWS
 It’s our responsibility to insert into the right
partition
 EXCHANGE PARTITION is supported
 Indexing
 Local indexes are supported by definition
 Global indexes are not (easily) supported
 Partial indexes are supported by definition
THANK YOU
Oren Nakdimon
www.db-oriented.com
 oren@db-oriented.com
 +972-54-4393763
@DBoriented

More Related Content

What's hot

Database Management System
Database Management SystemDatabase Management System
Database Management System
Hitesh Mohapatra
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
Saurabh K. Gupta
 
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
InSync2011
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
Connor McDonald
 
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
Oren Nakdimon
 
Meg bernal insight2014 4219
Meg bernal insight2014 4219Meg bernal insight2014 4219
Meg bernal insight2014 4219
Peter Schouboe
 
Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oracle
suman1248
 

What's hot (7)

Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
 
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
 
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
 
Meg bernal insight2014 4219
Meg bernal insight2014 4219Meg bernal insight2014 4219
Meg bernal insight2014 4219
 
Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oracle
 

Viewers also liked

Indexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cIndexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12c
Oren Nakdimon
 
How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...
Oren Nakdimon
 
Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)
Oren Nakdimon
 
Adaptive Query Optimization
Adaptive Query OptimizationAdaptive Query Optimization
Adaptive Query Optimization
Christian Antognini
 
Oracle ACFS High Availability NFS Services (HANFS)
Oracle ACFS High Availability NFS Services (HANFS)Oracle ACFS High Availability NFS Services (HANFS)
Oracle ACFS High Availability NFS Services (HANFS)
Anju Garg
 
Policy based cluster management in oracle 12c
Policy based cluster management in oracle 12c Policy based cluster management in oracle 12c
Policy based cluster management in oracle 12c
Anju Garg
 
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
Lukas Eder
 

Viewers also liked (7)

Indexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cIndexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12c
 
How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...
 
Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)
 
Adaptive Query Optimization
Adaptive Query OptimizationAdaptive Query Optimization
Adaptive Query Optimization
 
Oracle ACFS High Availability NFS Services (HANFS)
Oracle ACFS High Availability NFS Services (HANFS)Oracle ACFS High Availability NFS Services (HANFS)
Oracle ACFS High Availability NFS Services (HANFS)
 
Policy based cluster management in oracle 12c
Policy based cluster management in oracle 12c Policy based cluster management in oracle 12c
Policy based cluster management in oracle 12c
 
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
 

More from Oren Nakdimon

Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]
Oren Nakdimon
 
Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]
Oren Nakdimon
 
Oren nakdimon - Write Less With More - UKOUGtogether21
Oren nakdimon - Write Less With More - UKOUGtogether21Oren nakdimon - Write Less With More - UKOUGtogether21
Oren nakdimon - Write Less With More - UKOUGtogether21
Oren Nakdimon
 
Oren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made EasyOren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon
 
Oracle Inter-Session Communication
Oracle Inter-Session CommunicationOracle Inter-Session Communication
Oracle Inter-Session Communication
Oren Nakdimon
 
Edition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren NakdimonEdition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren Nakdimon
Oren Nakdimon
 
Oren nakdimon - Oracle 12c SQL Pattern Matching Made Easy
Oren nakdimon - Oracle 12c SQL Pattern Matching Made EasyOren nakdimon - Oracle 12c SQL Pattern Matching Made Easy
Oren nakdimon - Oracle 12c SQL Pattern Matching Made Easy
Oren Nakdimon
 

More from Oren Nakdimon (7)

Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]
 
Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]
 
Oren nakdimon - Write Less With More - UKOUGtogether21
Oren nakdimon - Write Less With More - UKOUGtogether21Oren nakdimon - Write Less With More - UKOUGtogether21
Oren nakdimon - Write Less With More - UKOUGtogether21
 
Oren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made EasyOren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made Easy
 
Oracle Inter-Session Communication
Oracle Inter-Session CommunicationOracle Inter-Session Communication
Oracle Inter-Session Communication
 
Edition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren NakdimonEdition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren Nakdimon
 
Oren nakdimon - Oracle 12c SQL Pattern Matching Made Easy
Oren nakdimon - Oracle 12c SQL Pattern Matching Made EasyOren nakdimon - Oracle 12c SQL Pattern Matching Made Easy
Oren nakdimon - Oracle 12c SQL Pattern Matching Made Easy
 

Recently uploaded

“Deploying Large Language Models on a Raspberry Pi,” a Presentation from Usef...
“Deploying Large Language Models on a Raspberry Pi,” a Presentation from Usef...“Deploying Large Language Models on a Raspberry Pi,” a Presentation from Usef...
“Deploying Large Language Models on a Raspberry Pi,” a Presentation from Usef...
Edge AI and Vision Alliance
 
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite SolutionIPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Networks
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
KAMAL CHOUDHARY
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
SynapseIndia
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
rajancomputerfbd
 
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
BrainSell Technologies
 
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and OllamaTirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Zilliz
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
Neo4j
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
The Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF GuideThe Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF Guide
Shiv Technolabs
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
RaminGhanbari2
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
aslasdfmkhan4750
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
alexjohnson7307
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
CEPTES Software Inc
 
CiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.pptCiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.ppt
moinahousna
 
Types of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technologyTypes of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technology
ldtexsolbl
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
Google Developer Group - Harare
 
Opencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of MünsterOpencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of Münster
Matthias Neugebauer
 

Recently uploaded (20)

“Deploying Large Language Models on a Raspberry Pi,” a Presentation from Usef...
“Deploying Large Language Models on a Raspberry Pi,” a Presentation from Usef...“Deploying Large Language Models on a Raspberry Pi,” a Presentation from Usef...
“Deploying Large Language Models on a Raspberry Pi,” a Presentation from Usef...
 
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite SolutionIPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite Solution
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
 
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
 
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and OllamaTirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
The Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF GuideThe Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF Guide
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
 
CiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.pptCiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.ppt
 
Types of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technologyTypes of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technology
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
 
Opencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of MünsterOpencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of Münster
 

The Features That (maybe) You Didn't Know About

  • 1. The Features That maybe You Didn’t Know About Oren Nakdimon www.db-oriented.com  oren@db-oriented.com  +972-54-4393763 @DBoriented
  • 2. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon WHO AM I? A CHRONOLOGY BY “ORACLE YEARS” Where: IAF When: Oracle 6/7 [1991-1997] What: Developer Where: Golden Screens When: Oracle 8 [1997-1998] What: Server Group Manager Where: TELEknowledge When: Oracle 8i/9i [1998-2003] What: DBA Group Manager Where: Olista When: Oracle 10g/11g [2004-2011] What: VP R&D + Israel Site Manager Where: When: Oracle 11g/12c [2011-] What: Freelance Consultant Where: When: 2012- What: Database Architect / Developer / DBA
  • 3. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon @DBORIENTED
  • 4. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon HTTP://DB-ORIENTED.COM
  • 5. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon  Join ilOUG meetup group  Download presentations  Give us your feedback  About this meeting  What do you want to hear and see next?  Initiate and participate in discussions  Propose your presentation for upcoming meetings http://www.meetup.com/ilOUG-Oracle-Technologies-Meetup/ iloug16@gmail.com
  • 6. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon SQL
  • 7. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Aggregate Functions
  • 8. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon select department_id, MIN(salary) from employees group by department_id; DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 117Sigal Tobias 2800.00 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 90 102Lex De Haan 17000.00 90 101Neena Kochhar 17000.00 30 115Alexander Khoo 3100.00 60 104Bruce Ernst 6000.00 30 116Shelli Baida 2900.00 60 106Valli Pataballa 4800.00 30 114Den Raphaely 11000.00 90 100Steven King 24000.00 60 103Alexander Hunold 9000.00 60 105David Austin 4800.00 60 107Diana Lorentz 4200.00
  • 9. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon select department_id, MIN(salary) from employees group by department_id; DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 30 117Sigal Tobias 2800.00 30 116Shelli Baida 2900.00 30 115Alexander Khoo 3100.00 30 114Den Raphaely 11000.00 60 107Diana Lorentz 4200.00 60 106Valli Pataballa 4800.00 60 105David Austin 4800.00 60 104Bruce Ernst 6000.00 60 103Alexander Hunold 9000.00 90 101Neena Kochhar 17000.00 90 102Lex De Haan 17000.00 90 100Steven King 24000.00 DEPARTMENT_ID MIN(SALARY) 30 2500.00 60 4200.00 90 17000.00
  • 10. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 30 117Sigal Tobias 2800.00 30 116Shelli Baida 2900.00 30 115Alexander Khoo 3100.00 30 114Den Raphaely 11000.00 60 107Diana Lorentz 4200.00 60 106Valli Pataballa 4800.00 60 105David Austin 4800.00 60 104Bruce Ernst 6000.00 60 103Alexander Hunold 9000.00 90 101Neena Kochhar 17000.00 90 102Lex De Haan 17000.00 90 100Steven King 24000.00
  • 11. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Aggregate Functions FIRST
  • 12. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon THE FIRST FUNCTION DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 30 117Sigal Tobias 2800.00 30 116Shelli Baida 2900.00 30 115Alexander Khoo 3100.00 30 114Den Raphaely 11000.00 60 107Diana Lorentz 4200.00 60 106Valli Pataballa 4800.00 60 105David Austin 4800.00 60 104Bruce Ernst 6000.00 60 103Alexander Hunold 9000.00 90 101Neena Kochhar 17000.00 90 102Lex De Haan 17000.00 90 100Steven King 24000.00 select department_id, min(first_name) keep(dense_rank FIRST order by salary) from employees group by department_id;
  • 13. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon THE FIRST FUNCTION DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 30 117Sigal Tobias 2800.00 30 116Shelli Baida 2900.00 30 115Alexander Khoo 3100.00 30 114Den Raphaely 11000.00 60 107Diana Lorentz 4200.00 60 106Valli Pataballa 4800.00 60 105David Austin 4800.00 60 104Bruce Ernst 6000.00 60 103Alexander Hunold 9000.00 90 101Neena Kochhar 17000.00 90 102Lex De Haan 17000.00 90 100Steven King 24000.00 select department_id, min(first_name) keep(dense_rank FIRST order by salary) from employees group by department_id;
  • 14. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon THE FIRST FUNCTION DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 30 117Sigal Tobias 2800.00 30 116Shelli Baida 2900.00 30 115Alexander Khoo 3100.00 30 114Den Raphaely 11000.00 60 107Diana Lorentz 4200.00 60 106Valli Pataballa 4800.00 60 105David Austin 4800.00 60 104Bruce Ernst 6000.00 60 103Alexander Hunold 9000.00 90 101Neena Kochhar 17000.00 90 102Lex De Haan 17000.00 90 100Steven King 24000.00 select department_id, min(first_name) keep(dense_rank FIRST order by salary) from employees group by department_id;
  • 15. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon THE FIRST FUNCTION DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 30 117Sigal Tobias 2800.00 30 116Shelli Baida 2900.00 30 115Alexander Khoo 3100.00 30 114Den Raphaely 11000.00 60 107Diana Lorentz 4200.00 60 106Valli Pataballa 4800.00 60 105David Austin 4800.00 60 104Bruce Ernst 6000.00 60 103Alexander Hunold 9000.00 90 101Neena Kochhar 17000.00 90 102Lex De Haan 17000.00 90 100Steven King 24000.00 select department_id, min(first_name) keep(dense_rank FIRST order by salary) from employees group by department_id;
  • 16. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon THE FIRST FUNCTION DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 30 117Sigal Tobias 2800.00 30 116Shelli Baida 2900.00 30 115Alexander Khoo 3100.00 30 114Den Raphaely 11000.00 60 107Diana Lorentz 4200.00 60 106Valli Pataballa 4800.00 60 105David Austin 4800.00 60 104Bruce Ernst 6000.00 60 103Alexander Hunold 9000.00 90 101Neena Kochhar 17000.00 90 102Lex De Haan 17000.00 90 100Steven King 24000.00 select department_id, min(first_name) keep(dense_rank FIRST order by salary) from employees group by department_id;
  • 17. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon THE FIRST FUNCTION DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 30 117Sigal Tobias 2800.00 30 116Shelli Baida 2900.00 30 115Alexander Khoo 3100.00 30 114Den Raphaely 11000.00 60 107Diana Lorentz 4200.00 60 106Valli Pataballa 4800.00 60 105David Austin 4800.00 60 104Bruce Ernst 6000.00 60 103Alexander Hunold 9000.00 90 101Neena Kochhar 17000.00 90 102Lex De Haan 17000.00 90 100Steven King 24000.00 select department_id, min(first_name) keep(dense_rank FIRST order by salary) from employees group by department_id; DEPARTMENT_ID MIN(FIRST_NAME)… 30Karen 60Diana 90Lex
  • 18. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Aggregate Functions LAST
  • 19. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon THE LAST FUNCTION DEPARTMENT_ID EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY 30 119Karen Colmenares 2500.00 30 118Guy Himuro 2600.00 30 117Sigal Tobias 2800.00 30 116Shelli Baida 2900.00 30 115Alexander Khoo 3100.00 30 114Den Raphaely 11000.00 60 107Diana Lorentz 4200.00 60 106Valli Pataballa 4800.00 60 105David Austin 4800.00 60 104Bruce Ernst 6000.00 60 103Alexander Hunold 9000.00 90 101Neena Kochhar 17000.00 90 102Lex De Haan 17000.00 90 100Steven King 24000.00 select department_id, min(first_name) keep(dense_rank LAST order by salary) from employees group by department_id; DEPARTMENT_ID MIN(FIRST_NAME)… 30Den 60Alexander 90Steven
  • 20. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon WHAT IS THE MOST COMMON JOB IN EACH DEPARTMENT? select department_id, min(job_id) keep(dense_rank last order by cnt) from (select department_id, job_id, count(*) cnt from employees group by department_id, job_id) group by department_id; DEPARTMENT_ID JOB_ID CNT ------------- ---------------------------- ---------- 90 AD_VP 2 30 PU_CLERK 5 60 IT_PROG 5 90 AD_PRES 1 30 PU_MAN 1
  • 21. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon WHAT IS THE MOST COMMON JOB IN EACH DEPARTMENT? select department_id, min(job_id) keep(dense_rank last order by cnt) from (select department_id, job_id, count(*) cnt from employees group by department_id, job_id) group by department_id; DEPARTMENT_ID MIN(JOB_ID)KEEP(DENSE_RANKLAST ------------- ------------------------------ 30 PU_CLERK 60 IT_PROG 90 AD_VP
  • 22. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Aggregate Functions STATS_MODE
  • 23. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon WHAT IS THE MOST COMMON JOB IN EACH DEPARTMENT? select department_id, stats_mode(job_id) from employees group by department_id; DEPARTMENT_ID MIN(JOB_ID)KEEP(DENSE_RANKLAST ------------- ------------------------------ 30 PU_CLERK 60 IT_PROG 90 AD_VP
  • 24. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Collections
  • 25. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE I have this table: select * from country_test; c1 c2 c3 c4 ————— ————— ————— —————— india us china uk india india china uk india china china uk us us us uk I need the distinct count of countries across the c1,c2,c3,c4 columns of the table, so the output has to be c1 c2 c3 c4 cnt ————— ————— ————— ——— ———— india us china uk 4 india india china uk 3 india china china uk 3 us us us uk 2 http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:8749607800346631637
  • 26. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE ops$tkyte%ORA11GR2> with data(r) 2 as 3 (select 1 r from dual 4 union all 5 select r+1 from data where r < 4 6 ) 7 select c1, c2, c3, c4, count(distinct c) cnt 8 from ( 9 select rowid rid, 10 c1, c2, c3, c4, 11 decode(r,1,c1,2,c2,3,c3,4,c4) c 12 from data, country_test 13 ) 14 group by rid, c1, c2, c3, c4 15 / C1 C2 C3 C4 CNT ---------- ---------- ---------- ---------- ---------- india us china uk 4 us us us uk 2 india india china uk 3 india china china uk 3 http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:8749607800346631637
  • 27. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE with data as (select rownum r,c1,c2,c3,c4 from ctest) select listagg(rpad(val,21),'') within group (order by column_list) orig ,count(distinct val) countries from ( select * from data unpivot (val for column_list in (c1,c2,c3,c4)) ) group by r order by r; select * from country_test, lateral( select count(distinct c) cnt from ( select c1 c from dual union all select c2 from dual union all select c3 from dual union all select c4 from dual ) ); select country_test.*, cnt_tab.cnt from country_test, ( select count(1) cnt, rid from ( select rowid rid, c1 c from country_test union select rowid, c2 from country_test union select rowid, c3 from country_test union select rowid, c4 from country_test ) group by rid ) cnt_tab where country_test.rowid = cnt_tab.rid select * from country_test, lateral( select count(distinct val) cnt from ( select c1,c2,c3,c4 from dual ) unpivot(val for col in (c1,c2,c3,c4)) );
  • 28. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE create type string_ntt as table of varchar2(4000)
  • 29. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Collections Default Constructor
  • 30. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE create type string_ntt as table of varchar2(4000) select string_ntt('John','Paul','George','Ringo') beatles from dual; BEATLES ---------------------------------------------- STRING_NTT('John', 'Paul', 'George', 'Ringo')
  • 31. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE create type string_ntt as table of varchar2(4000) select c.*, cardinality(set(string_ntt(c1,c2,c3,c4))) from country_test c; C1 C2 C3 C4 STRING_NTT(C1,C2,C3,C4) ----- ----- ----- ----- -------------------------------------------------- india us china uk STRING_NTT('india', 'us', 'china', 'uk') india india china uk STRING_NTT('india', 'india', 'china', 'uk') india china china uk STRING_NTT('india', 'china', 'china', 'uk') us us us uk STRING_NTT('us', 'us', 'us', 'uk')
  • 32. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Collections SET
  • 33. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE select c.*, cardinality(set(string_ntt(c1,c2,c3,c4))) from country_test c; C1 C2 C3 C4 SET(STRING_NTT(C1,C2,C3,C4)) ----- ----- ----- ----- ---------------------------------------- india us china uk STRING_NTT('india', 'us', 'china', 'uk') india india china uk STRING_NTT('india', 'china', 'uk') india china china uk STRING_NTT('india', 'china', 'uk') us us us uk STRING_NTT('us', 'uk') C1 C2 C3 C4 STRING_NTT(C1,C2,C3,C4) ----- ----- ----- ----- -------------------------------------------------- india us china uk STRING_NTT('india', 'us', 'china', 'uk') india india china uk STRING_NTT('india', 'india', 'china', 'uk') india china china uk STRING_NTT('india', 'china', 'china', 'uk') us us us uk STRING_NTT('us', 'us', 'us', 'uk')
  • 34. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Collections CARDINALITY
  • 35. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DISTINCT COUNT OF A VALUE ACROSS COLUMNS IN A TABLE select c.*, cardinality(set(string_ntt(c1,c2,c3,c4))) from country_test c; C1 C2 C3 C4 CARDINALITY(SET(STRING_NTT(C1,C2,C3,C4))) ----- ----- ----- ----- ----------------------------------------- india us china uk 4 india india china uk 3 india china china uk 3 us us us uk 2 C1 C2 C3 C4 SET(STRING_NTT(C1,C2,C3,C4)) ----- ----- ----- ----- ---------------------------------------- india us china uk STRING_NTT('india', 'us', 'china', 'uk') india india china uk STRING_NTT('india', 'china', 'uk') india china china uk STRING_NTT('india', 'china', 'uk') us us us uk STRING_NTT('us', 'uk') C1 C2 C3 C4 STRING_NTT(C1,C2,C3,C4) ----- ----- ----- ----- -------------------------------------------------- india us china uk STRING_NTT('india', 'us', 'china', 'uk') india india china uk STRING_NTT('india', 'india', 'china', 'uk') india china china uk STRING_NTT('india', 'china', 'china', 'uk') us us us uk STRING_NTT('us', 'us', 'us', 'uk')
  • 36. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Collections Unnesting
  • 37. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon COLLECTION UNNESTING select * from table(string_ntt('John','Paul','George','Ringo')); COLUMN_VALUE --------------------- John Paul George Ringo
  • 38. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon KAKURO  Digits 1-9  Sum = associated clue  No duplications 6 = 1+2+3 12 = 1+2+3+6 12 = 1+2+4+5 http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
  • 39. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon > select * from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9))); COLUMN_VALUE ------------------------- create type integer_ntt as table of integer
  • 40. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Collections POWERMULTISET
  • 41. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon > select * from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9))); COLUMN_VALUE ------------------------- INTEGER_NTT(1) INTEGER_NTT(2) INTEGER_NTT(1, 2) INTEGER_NTT(3) INTEGER_NTT(1, 3) INTEGER_NTT(2, 3) INTEGER_NTT(1, 2, 3) INTEGER_NTT(4) INTEGER_NTT(1, 4) INTEGER_NTT(2, 4) INTEGER_NTT(1, 2, 4) INTEGER_NTT(3, 4) INTEGER_NTT(1, 3, 4) INTEGER_NTT(2, 3, 4) INTEGER_NTT(1, 2, 3, 4) INTEGER_NTT(5) ... INTEGER_NTT(1, 3, 4, 5, 6, 7, 8, 9) INTEGER_NTT(2, 3, 4, 5, 6, 7, 8, 9) INTEGER_NTT(1, 2, 3, 4, 5, 6, 7, 8, 9) 511 rows selected. create type integer_ntt as table of integer
  • 42. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon > select * from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9))); COLUMN_VALUE ------------------------- INTEGER_NTT(1) INTEGER_NTT(2) INTEGER_NTT(1, 2) INTEGER_NTT(3) INTEGER_NTT(1, 3) INTEGER_NTT(2, 3) INTEGER_NTT(1, 2, 3) INTEGER_NTT(4) INTEGER_NTT(1, 4) INTEGER_NTT(2, 4) INTEGER_NTT(1, 2, 4) INTEGER_NTT(3, 4) INTEGER_NTT(1, 3, 4) INTEGER_NTT(2, 3, 4) INTEGER_NTT(1, 2, 3, 4) INTEGER_NTT(5) ... INTEGER_NTT(1, 3, 4, 5, 6, 7, 8, 9) INTEGER_NTT(2, 3, 4, 5, 6, 7, 8, 9) INTEGER_NTT(1, 2, 3, 4, 5, 6, 7, 8, 9) 511 rows selected. create type integer_ntt as table of integer
  • 43. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon break on x on num_of_elements skip 1 select sum(b.column_value) x, a.num_of_elements, listagg(b.column_value,'+') within group(order by b.column_value) expr from (select rownum id , cardinality(column_value) num_of_elements, column_value combination from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a, table(a.combination) b where a.num_of_elements > 1 group by a.id,a.num_of_elements order by x,num_of_elements,expr; ID NUM_OF_ELEMENTS COMBINATION ---------- --------------- -------------------------------------------------------------- 1 1 INTEGER_NTT(1) 2 1 INTEGER_NTT(2) 3 2 INTEGER_NTT(1, 2) 4 1 INTEGER_NTT(3) 5 2 INTEGER_NTT(1, 3) 6 2 INTEGER_NTT(2, 3) 7 3 INTEGER_NTT(1, 2, 3) ... 508 7 INTEGER_NTT(3, 4, 5, 6, 7, 8, 9) 509 8 INTEGER_NTT(1, 3, 4, 5, 6, 7, 8, 9) 510 8 INTEGER_NTT(2, 3, 4, 5, 6, 7, 8, 9) 511 9 INTEGER_NTT(1, 2, 3, 4, 5, 6, 7, 8, 9) 511 rows selected. http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
  • 44. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon break on x on num_of_elements skip 1 select sum(b.column_value) x, a.num_of_elements, select a.*,b.column_value from (select rownum id , cardinality(column_value) num_of_elements, column_value combination from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a, table(a.combination) b where a.num_of_elements > 1 group by a.id,a.num_of_elements order by x,num_of_elements,expr; ID NUM_OF_ELEMENTS COMBINATION COLUMN_VALUE ---------- --------------- -------------------- ------------ 1 1 INTEGER_NTT(1) 1 2 1 INTEGER_NTT(2) 2 3 2 INTEGER_NTT(1, 2) 1 3 2 INTEGER_NTT(1, 2) 2 4 1 INTEGER_NTT(3) 3 5 2 INTEGER_NTT(1, 3) 1 5 2 INTEGER_NTT(1, 3) 3 6 2 INTEGER_NTT(2, 3) 2 6 2 INTEGER_NTT(2, 3) 3 7 3 INTEGER_NTT(1, 2, 3) 1 7 3 INTEGER_NTT(1, 2, 3) 2 7 3 INTEGER_NTT(1, 2, 3) 3 ... 2304 rows selected. http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/ 1+2+3=6 1+2=3
  • 45. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon break on x on num_of_elements skip 1 select sum(b.column_value) x, a.num_of_elements, listagg(b.column_value,'+') within group(order by b.column_value) expr from (select rownum id , cardinality(column_value) num_of_elements, column_value combination from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a, table(a.combination) b where a.num_of_elements > 1 group by a.id,a.num_of_elements order by x,num_of_elements,expr; http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/ X NUM_OF_ELEMENTS EXPR ---------- --------------- ---------- 3 2 1+2 4 2 1+3 5 2 1+4 2+3 6 2 1+5 2+4 3 1+2+3 7 2 1+6 2+5 3+4 3 1+2+4 X NUM_OF_ELEMENTS EXPR ---------- --------------- -------------------- 41 7 2+4+5+6+7+8+9 8 1+2+3+5+6+7+8+9 42 7 3+4+5+6+7+8+9 8 1+2+4+5+6+7+8+9 43 8 1+3+4+5+6+7+8+9 44 8 2+3+4+5+6+7+8+9 45 9 1+2+3+4+5+6+7+8+9 502 rows selected.
  • 46. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon break on x on num_of_elements skip 1 select sum(b.column_value) x, a.num_of_elements, listagg(b.column_value,'+') within group(order by b.column_value) expr from (select rownum id , cardinality(column_value) num_of_elements, column_value combination from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a, table(a.combination) b where a.num_of_elements > 1 group by a.id,a.num_of_elements order by x,num_of_elements,expr; http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/ X NUM_OF_ELEMENTS EXPR ---------- --------------- ---------- 3 2 1+2 4 2 1+3 5 2 1+4 2+3 6 2 1+5 2+4 3 1+2+3 7 2 1+6 2+5 3+4 3 1+2+4 X NUM_OF_ELEMENTS EXPR ---------- --------------- -------------------- 41 7 2+4+5+6+7+8+9 8 1+2+3+5+6+7+8+9 42 7 3+4+5+6+7+8+9 8 1+2+4+5+6+7+8+9 43 8 1+3+4+5+6+7+8+9 44 8 2+3+4+5+6+7+8+9 45 9 1+2+3+4+5+6+7+8+9 502 rows selected.
  • 47. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon break on x on num_of_elements skip 1 select sum(b.column_value) x, a.num_of_elements, listagg(b.column_value,'+') within group(order by b.column_value) expr from (select rownum id , cardinality(column_value) num_of_elements, column_value combination from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a, table(a.combination) b where a.num_of_elements > 1 group by a.id,a.num_of_elements order by x,num_of_elements,expr; http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/ X NUM_OF_ELEMENTS EXPR ---------- --------------- ---------- 3 2 1+2 4 2 1+3 5 2 1+4 2+3 6 2 1+5 2+4 3 1+2+3 7 2 1+6 2+5 3+4 3 1+2+4 X NUM_OF_ELEMENTS EXPR ---------- --------------- -------------------- 41 7 2+4+5+6+7+8+9 8 1+2+3+5+6+7+8+9 42 7 3+4+5+6+7+8+9 8 1+2+4+5+6+7+8+9 43 8 1+3+4+5+6+7+8+9 44 8 2+3+4+5+6+7+8+9 45 9 1+2+3+4+5+6+7+8+9 502 rows selected.
  • 48. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon break on x on num_of_elements skip 1 select sum(b.column_value) x, a.num_of_elements, listagg(b.column_value,'+') within group(order by b.column_value) expr from (select rownum id , cardinality(column_value) num_of_elements, column_value combination from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a, table(a.combination) b where a.num_of_elements > 1 group by a.id,a.num_of_elements order by x,num_of_elements,expr; http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/ X NUM_OF_ELEMENTS EXPR ---------- --------------- ---------- 3 2 1+2 4 2 1+3 5 2 1+4 2+3 6 2 1+5 2+4 3 1+2+3 7 2 1+6 2+5 3+4 3 1+2+4 X NUM_OF_ELEMENTS EXPR ---------- --------------- -------------------- 41 7 2+4+5+6+7+8+9 8 1+2+3+5+6+7+8+9 42 7 3+4+5+6+7+8+9 8 1+2+4+5+6+7+8+9 43 8 1+3+4+5+6+7+8+9 44 8 2+3+4+5+6+7+8+9 45 9 1+2+3+4+5+6+7+8+9 502 rows selected.
  • 49. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon break on x on num_of_elements skip 1 select sum(b.column_value) x, a.num_of_elements, listagg(b.column_value,'+') within group(order by b.column_value) expr from (select rownum id , cardinality(column_value) num_of_elements, column_value combination from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a, table(a.combination) b where a.num_of_elements > 1 group by a.id,a.num_of_elements order by x,num_of_elements,expr; X NUM_OF_ELEMENTS EXPR ---------- --------------- ---------- 3 2 1+2 4 2 1+3 5 2 1+4 2+3 6 2 1+5 2+4 3 1+2+3 7 2 1+6 2+5 3+4 3 1+2+4 X NUM_OF_ELEMENTS EXPR ---------- --------------- -------------------- 41 7 2+4+5+6+7+8+9 8 1+2+3+5+6+7+8+9 42 7 3+4+5+6+7+8+9 8 1+2+4+5+6+7+8+9 43 8 1+3+4+5+6+7+8+9 44 8 2+3+4+5+6+7+8+9 45 9 1+2+3+4+5+6+7+8+9 502 rows selected. http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/
  • 50. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PIVOT
  • 51. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon break on x skip 1 select * from ( select sum(b.column_value) x, a.num_of_elements, listagg(b.column_value,'+') within group(order by b.column_value) expr from (select rownum id , cardinality(column_value) num_of_elements, column_value combination from table(powermultiset(integer_ntt(1,2,3,4,5,6,7,8,9)))) a, table(a.combination) b where a.num_of_elements > 1 group by a.id,a.num_of_elements ) pivot (listagg(expr, chr(10)) within group (order by expr) for num_of_elements in(2,3,4,5,6,7,8,9)); http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/ X 2 3 4 5 6 7 8 9 -- ---- ------ -------- ---------- ------------ -------------- ---------------- --------- 3 1+2 4 1+3 5 1+4 2+3
  • 52. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon pivot (listagg(expr, chr(10)) within group (order by expr) for num_of_elements in(2,3,4,5,6,7,8,9)); http://db-oriented.com/2016/06/10/kakuro-helper-using-sql-query-with-the-powermultiset-function/ X 2 3 4 5 6 7 8 9 -- ---- ------ -------- ---------- ------------ -------------- ---------------- --------- 3 1+2 4 1+3 5 1+4 2+3 6 1+5 1+2+3 2+4 21 4+8+9 1+3+8+9 1+2+3+6+9 1+2+3+4+5+6 5+7+9 1+4+7+9 1+2+3+7+8 6+7+8 1+5+6+9 1+2+4+5+9 1+5+7+8 1+2+4+6+8 2+3+7+9 1+2+5+6+7 2+4+6+9 1+3+4+5+8 2+4+7+8 1+3+4+6+7 2+5+6+8 2+3+4+5+7 3+4+5+9 3+4+6+8 3+5+6+7 44 2+3+4+5+6+7+8+9 45 1+2+3+4+…
  • 53. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Recursive Subquery Factoring
  • 54. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon RECURSIVE SUBQUERY FACTORING with fib(x,f) as ( select 1 as x, 1 as f from dual union all select f, x+f from fib where x+f <= &n ) select f from fib; anchor member
  • 55. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon RECURSIVE SUBQUERY FACTORING with fib(x,f) as ( select 1 as x, 1 as f from dual union all select f, x+f from fib where x+f <= &n ) select f from fib; anchor member recursive member
  • 56. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon RECURSIVE SUBQUERY FACTORING with fib(x,f) as ( select 1 as x, 1 as f from dual union all select f, x+f from fib where x+f <= &n ) select f from fib; Enter value for n: 121 F ---------- 1 2 3 5 8 13 21 34 55 89 10 rows selected. anchor member recursive member
  • 57. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Pattern Matching
  • 58. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon THE MOST BASIC SQL  Row-level visibility  Maximum one output row per input row  WHERE clause
  • 59. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon AGGREGATE FUNCTIONS  Group-level visibility  Strict definition of “group”  Each input row belongs to exactly one group  Maximum one output row per group  GROUP BY clause  HAVING clause
  • 60. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon  Window-level visibility  Strict definition of “window”  Each input row has its own window  Window-level aggregates are added to input rows  OVER  PARTITION BY  ORDER BY ANALYTIC (WINDOW) FUNCTIONS
  • 61. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon  Window-level visibility  Strict definition of “window”  Each input row has its own window  Window-level aggregates are added to input rows  OVER  PARTITION BY  ORDER BY ANALYTIC (WINDOW) FUNCTIONS
  • 62. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon ANALYTIC (WINDOW) FUNCTIONS  Window-level visibility  Strict definition of “window”  Each input row has its own window  Window-level aggregates are added to input rows  OVER  PARTITION BY  ORDER BY
  • 63. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PATTERN MATCHING  Enhanced analysis of row sequences  Match-based output  One row per match (similar to the “group by” concept) or  All the match’s input rows (similar to the “window” concept)  Each input row may belong to 0, 1 or more matches
  • 64. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PATTERN MATCHING Zeckendorf's theorem Every positive integer can be represented uniquely as the sum of distinct non-consecutive Fibonacci numbers, and this representation can be found by using a greedy algorithm, choosing the largest possible Fibonacci number at each stage. 6 = 5 + 1 122 = 89 + 21 + 8 + 3 + 117 = 13 + 3 + 1 34 = 34 http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/
  • 65. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PATTERN MATCHING http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/ with fib(x,f) as ( select 1 as x, 1 as f from dual union all select f, x+f from fib where x+f <= &n ) select f from fib match_recognize( order by f desc all rows per match pattern ((A|{-B-})+) define A as sum(A.f) <= &n ) F 1 2 3 5 8 13 21 34 55 89 n = 121
  • 66. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PATTERN MATCHING http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/ with fib(x,f) as ( select 1 as x, 1 as f from dual union all select f, x+f from fib where x+f <= &n ) select f from fib match_recognize( order by f desc all rows per match pattern ((A|{-B-})+) define A as sum(A.f) <= &n ) F 89 55 34 21 13 8 5 3 2 1 n = 121
  • 67. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PATTERN MATCHING http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/ with fib(x,f) as ( select 1 as x, 1 as f from dual union all select f, x+f from fib where x+f <= &n ) select f from fib match_recognize( order by f desc all rows per match pattern ((A|{-B-})+) define A as sum(A.f) <= &n ) F 89 55 34 21 13 8 5 3 2 1 A     n = 121
  • 68. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PATTERN MATCHING http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/ with fib(x,f) as ( select 1 as x, 1 as f from dual union all select f, x+f from fib where x+f <= &n ) select f from fib match_recognize( order by f desc all rows per match pattern ((A|{-B-})+) define A as sum(A.f) <= &n ) F 89 55 34 21 13 8 5 3 2 1 A     n = 121
  • 69. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PATTERN MATCHING http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/ with fib(x,f) as ( select 1 as x, 1 as f from dual union all select f, x+f from fib where x+f <= &n ) select f from fib match_recognize( order by f desc all rows per match pattern ((A|{-B-})+) define A as sum(A.f) <= &n ) F 89 55 34 21 13 8 5 3 2 1 A     n = 121
  • 70. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PATTERN MATCHING http://marogel.wordpress.com/2015/05/22/a-greedy-algorithm-using-recursive-subquery-factoring/ with fib(x,f) as ( select 1 as x, 1 as f from dual union all select f, x+f from fib where x+f <= &n ) select f from fib match_recognize( order by f desc all rows per match pattern ((A|{-B-})+) define A as sum(A.f) <= &n ) F 89 21 8 3 A     n = 121
  • 71. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Oracle Locator
  • 72. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon create table stops ( stop_id varchar2(20) constraint stops_pk primary key, stop_code varchar2(20), stop_name varchar2(100), stop_location mdsys.sdo_geometry ); stops.txt insert into user_sdo_geom_metadata (table_name,column_name,diminfo,srid) values ('STOPS', 'STOP_LOCATION', mdsys.sdo_dim_array( mdsys.sdo_dim_element('LONG', -180.0, 180.0, 0.05), mdsys.sdo_dim_element('LAT', -90.0, 90.0, 0.05)), 8307);
  • 73. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon CREATE TABLE STOPS_EXT (stop_id varchar2(20), stop_code varchar2(20), stop_name varchar2(100), stop_desc varchar2(100), stop_lat number, stop_lon number, location_type number(1), parent_location varchar2(20), zone_id number) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY EXT_TABLES_DIR ACCESS PARAMETERS ( records delimited by 0x'0d0a' characterset UTF8 skip 1 logfile EXT_TABLES_DIR:'stops_%p_%a.log' badfile EXT_TABLES_DIR:'stops_%p_%a.txt' fields terminated by ',' optionally enclosed by '"' missing field values are null reject rows with all null fields ) LOCATION ('stops.txt') ) REJECT LIMIT UNLIMITED;
  • 74. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon insert /*+ append */ into stops ( stop_id, stop_code, stop_name, stop_location) select stop_id, stop_code, stop_name, mdsys.sdo_geometry(2001, -- 2 dimensional point 8307, -- lat/long coordinate system mdsys.sdo_point_type(stop_lon, stop_lat, null), null, -- n/a for point type null) -- n/a for point type from stops_ext; commit;
  • 75. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon External Tables
  • 76. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon insert /*+ append */ into stops ( stop_id, stop_code, stop_name, stop_location) select stop_id, stop_code, stop_name, mdsys.sdo_geometry(2001, -- 2 dimensional point 8307, -- lat/long coordinate system mdsys.sdo_point_type(stop_lon, stop_lat, null), null, -- n/a for point type null) -- n/a for point type from stops_ext; commit; create index stops_location_idx on stops (stop_location) indextype is mdsys.spatial_index parameters ('layer_gtype=POINT');
  • 77. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon (34.863356, 32.101307)
  • 78. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon STOP_CODE STOP_NAME LONGITUDE LATITUDE ---------- -------------------------------- --------- --------- 33080 ‫השפלה‬/‫אימבר‬ 34.860736 32.097785 30990 ‫המושבות‬ ‫אם‬ ‫דרך‬/‫השפלה‬ 34.858287 32.101256 35378 ‫אריה‬ ‫קרית‬ ‫רכבת‬ ‫תחנת‬ 34.86375 32.104148 31424 ‫אריה‬ ‫קריית‬ ‫רכבת‬/‫וסע‬ ‫חנה‬ 34.863596 32.105353 38334 ‫המושבות‬ ‫אם‬ ‫דרך‬/‫המר‬ ‫זבולון‬ ‫דרך‬ 34.867824 32.10336 38143 ‫גיסין‬ ‫אבשלום‬/‫דיין‬ ‫משה‬ 34.86262 32.096893 32172 ‫גיסין‬ ‫אבשלום‬/‫בזל‬ 34.864442 32.097726 32231 ‫גיסין‬ ‫אבשלום‬/‫בזל‬ 34.866672 32.098263 8 rows selected. Elapsed: 00:00:00.13 ------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 275 | 16775 | 3 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID | STOPS | 275 | 16775 | 3 (0)| 00:00:01 | |* 2 | DOMAIN INDEX (SEL: 0.100000 %)| STOPS_LOCATION_IDX | | | 3 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------------ SELECT s.stop_code, s.stop_name, s.stop_location.sdo_point.x longitude, s.stop_location.sdo_point.y latitude FROM stops s WHERE sdo_within_distance( s.stop_location, sdo_geometry(2001,8307, sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL), 'distance=500 unit=meter') = 'TRUE'; All the stops within 500 meters
  • 79. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon GEOMETRY AGGREGATION SELECT sdo_util.to_wktgeometry( sdo_aggr_union(sdoaggrtype(s.stop_location,0.05))) FROM stops s WHERE sdo_within_distance( s.stop_location, sdo_geometry(2001,8307, sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL), 'distance=500 unit=meter') = 'TRUE';
  • 80. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon GEOMETRY AGGREGATION SELECT sdo_util.to_wktgeometry( sdo_aggr_union(sdoaggrtype(s.stop_location,0.05))) FROM stops s WHERE sdo_within_distance( s.stop_location, sdo_geometry(2001,8307, sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL), 'distance=500 unit=meter') = 'TRUE';
  • 81. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon GEOMETRY AGGREGATION SELECT sdo_util.to_wktgeometry( sdo_aggr_union(sdoaggrtype(s.stop_location,0.05))) FROM stops s WHERE sdo_within_distance( s.stop_location, sdo_geometry(2001,8307, sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL), 'distance=500 unit=meter') = 'TRUE'; MULTIPOINT ((34.866672 32.098263), (34.864442 32.097726), (34.86262 32.096893), (34.867824 32.10336), (34.863596 32.105353), (34.86375 32.104148), (34.858287 32.101256), (34.860736 32.097785))
  • 82. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon MULTIPOINT ((34.866672 32.098263), (34.864442 32.097726), (34.86262 32.096893), (34.867824 32.10336), (34.863596 32.105353), (34.86375 32.104148), (34.858287 32.101256), (34.860736 32.097785))
  • 83. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon SELECT s.stop_code, s.stop_name, s.stop_location.sdo_point.x longitude, s.stop_location.sdo_point.y latitude FROM stops s WHERE sdo_nn( s.stop_location, sdo_geometry(2001,8307, sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL), 'sdo_num_res=3') = 'TRUE'; STOP_CODE STOP_NAME LONGITUDE LATITUDE ---------- ----------------------- --------- ---------- 35378 ‫אריה‬ ‫קרית‬ ‫רכבת‬ ‫תחנת‬ 34.86375 32.104148 32172 ‫גיסין‬ ‫אבשלום‬/‫בזל‬ 34.864442 32.097726 31424 ‫אריה‬ ‫קריית‬ ‫רכבת‬/‫וסע‬ ‫חנה‬ 34.863596 32.105353 3 rows selected. Elapsed: 00:00:00.21 ------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 28 | 1708 | 3 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID | STOPS | 28 | 1708 | 3 (0)| 00:00:01 | |* 2 | DOMAIN INDEX (SEL: 0.100000 %)| STOPS_LOCATION_IDX | | | 3 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------------ 3 nearest stops
  • 84. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon SELECT round(sdo_nn_distance(1)) dist_meters, s.stop_code, s.stop_name FROM stops s WHERE sdo_nn( s.stop_location, sdo_geometry(2001,8307, sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL), 'sdo_num_res=3',1) = 'TRUE' order by dist_meters; DIST_METERS STOP_CODE STOP_NAME ----------- ---------- --------------------------------------------------------------------------- 317 35378 ‫אריה‬ ‫קרית‬ ‫רכבת‬ ‫תחנת‬ 410 32172 ‫גיסין‬ ‫אבשלום‬/‫בזל‬ 449 31424 ‫אריה‬ ‫קריית‬ ‫רכבת‬/‫וסע‬ ‫חנה‬ 3 rows selected. Elapsed: 00:00:00.06 3 nearest stops + their distance
  • 85. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon COUNTRIES AND POLYGONS > desc countries Name Null? Type ----------------------------- -------- -------------------- COUNTRY_ID NUMBER COUNTRY_NAME VARCHAR2(100) POLYGON MDSYS.SDO_GEOMETRY
  • 86. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon WHICH COUNTRY CONTAINS OUR POINT? COUNTRY_NAME ---------------------------- Israel 1 row selected. Elapsed: 00:00:00.03 --------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 2 | 48 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID | COUNTRIES | 2 | 48 | 2 (0)| 00:00:01 | |* 2 | DOMAIN INDEX (SEL: 0.100000 %)| COUNTRIES_POLYGON_IDX | | | 2 (0)| 00:00:01 | --------------------------------------------------------------------------------------------------------- select c.country_name from countries c where sdo_relate( c.polygon, sdo_geometry(2001,8307, sdo_point_type(34.863356, 32.101307, NULL), NULL, NULL), 'mask=contains') = 'TRUE';
  • 87. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Online Operations
  • 88. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon ONLINE DDL OPERATIONS Offline Operations Online Operations
  • 89. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon ONLINE DDL OPERATIONS Offline Operations Online Operations Get ORA-54 due to active transactions Wait for active transactions to end
  • 90. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon ONLINE DDL OPERATIONS Offline Operations Online Operations Get ORA-54 due to active transactions Wait for active transactions to end Block new DML statements Do not block new DML statements
  • 91. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon THE KEYWORD ONLINE  11g  CREATE INDEX … [ONLINE]  ALTER INDEX … REBUILD [ONLINE]  12c  ALTER TABLE … DROP CONSTRAINT … [ONLINE]  ALTER TABLE … SET UNUSED … [ONLINE]  DROP INDEX … [ONLINE]  ALTER INDEX … UNUSABLE [ONLINE]
  • 92. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon ONLINE OPERATIONS  12c  ALTER INDEX … INVISIBLE  ALTER INDEX … VISIBLE
  • 93. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Invisible Indexes
  • 94. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon INVISIBLE INDEXES  Maintained by DML  Invisible to the optimizer  Unless optimizer_use_invisible_indexes is true
  • 95. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon ONLINE OPERATIONS  Adding a new column to a non-empty table  An optional column with no default  As of 11g, adding a mandatory column with default is a meta-data only operation:  Fast  No space  No redo  No undo  Online  As of 12c, the same is true also for optional columns
  • 96. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon “ALMOST ONLINE” OPERATIONS > drop index t_idx; drop index t_idx * ERROR at line 1: ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired Elapsed: 00:00:00.00
  • 97. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon DDL_LOCK_TIMEOUT
  • 98. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon “ALMOST ONLINE” OPERATIONS > alter session set ddl_lock_timeout=2; Session altered. > drop index t_idx; drop index t_idx * ERROR at line 1: ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired Elapsed: 00:00:02.02
  • 99. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon “ALMOST ONLINE” OPERATIONS > alter session set ddl_lock_timeout=2; Session altered. > drop index t_idx; Index dropped. Elapsed: 00:00:00.95
  • 100. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon “ALMOST ONLINE” OPERATIONS ALTER TABLE ADD CONSTRAINT
  • 101. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Online Operations ENABLE NOVALIDATE
  • 102. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon “ALMOST ONLINE” OPERATIONS ALTER TABLE ADD CONSTRAINT ALTER TABLE ADD CONSTRAINT ENABLE NOVALIDATE ALTER TABLE ENABLE VALIDATE CONSTRAINT
  • 103. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon INDEX REBUILD? index on T(CREATION_TIME) select … from T where CREATION_TIME between …
  • 104. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Index Coalesce
  • 105. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon INDEX REBUILD? index on T(CREATION_TIME) select … from T where CREATION_TIME between …
  • 106. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon INDEX REBUILD? index on T(CREATION_TIME) select … from T where CREATION_TIME between …
  • 107. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Edition Based Redefinition
  • 108. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Procedure P Procedure P My Schema Edition1 Edition2 procedure p is begin -- do something end p; create or replace procedure p as begin -- do something else end p;
  • 109. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Procedure P My Schema Edition1 Edition2 Function F Procedure P View V
  • 110. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Procedure P My Schema Edition1 Edition2 Function F Procedure P View V Edition3 Function F Package PKG
  • 111. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Procedure P My Schema Edition1 procedure p is ... select name into ... from people ... Table PEOPLE - id - name
  • 112. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Procedure P My Schema Edition1 Edition2 Edition3 Procedure P procedure p is ... select name into ... from people ... Table PEOPLE - id - name - first_name - last_nameprocedure p is ... select first_name, last_name into ... from people ...
  • 113. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Procedure P My Schema Edition1 Edition2 Edition3 Procedure P Editioning View PEOPLE Editioning View PEOPLE Table PEOPLE$T - id - name - first_name - last_name create editioning view people as select id, name from people$t create editioning view people as select id, first_name, last_name from people$t select name into ... from people select first_name, last_name into ... from people
  • 114. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon I LOVE EBR BECAUSE…  It enables to apply any change in an online fashion  The upgrade is performed in the privacy of a new unexposed edition  The upgrade can be done at any time  Supported everywhere (since Oracle 11.2), including standard edition
  • 115. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon Partition Views
  • 116. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PARTITION VIEWS T1 T2 T3 T4alter table add partition create table create or replace view drop tablealter table drop partition
  • 117. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PARTITION VIEWS > desc events_01 Name Null? Type --------------------------- -------- ---------------------------- EVENT_ID NOT NULL NUMBER EVENT_TIME NOT NULL DATE EVENT_TYPE_ID NOT NULL NUMBER DETAILS VARCHAR2(100) create or replace view events as select * from events_01 where event_time >= date'2016-01-01' and event_time < date'2016-02-01' union all select * from events_02 where event_time >= date'2016-02-01' and event_time < date'2016-03-01' union all select * from events_03 where event_time >= date'2016-03-01' and event_time < date'2016-04-01'
  • 118. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PARTITION VIEWS select event_type_id,count(*) from events where event_time between date'2016-02-20' and date'2016-02-22' group by event_Type_id; ------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 7 | 21 | 19 (6)| 00:00:01 | | 1 | HASH GROUP BY | | 7 | 21 | 19 (6)| 00:00:01 | | 2 | VIEW | EVENTS | 2884 | 8652 | 18 (0)| 00:00:01 | | 3 | UNION-ALL | | | | | | |* 4 | FILTER | | | | | | | 5 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_01 | 1 | 11 | 3 (0)| 00:00:01 | |* 6 | INDEX RANGE SCAN | EVENT_01_TIME_IDX | 1 | | 2 (0)| 00:00:01 | | 7 | TABLE ACCESS BY INDEX ROWID BATCHED | EVENTS_02 | 2882 | 31702 | 18 (0)| 00:00:01 | |* 8 | INDEX RANGE SCAN | EVENT_02_TIME_IDX | 2882 | | 9 (0)| 00:00:01 | |* 9 | FILTER | | | | | | | 10 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_03 | 1 | 11 | 3 (0)| 00:00:01 | |* 11 | INDEX RANGE SCAN | EVENT_03_TIME_IDX | 1 | | 2 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter(NULL IS NOT NULL) 6 - access("EVENT_TIME">=TO_DATE(' 2016-02-20 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME“ <TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 8 - access("EVENT_TIME">=TO_DATE(' 2016-02-20 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 9 - filter(NULL IS NOT NULL) 11 - access("EVENT_TIME">=TO_DATE(' 2016-03-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
  • 119. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PARTITION VIEWS select count(details) from events where event_time between date'2016-01-10' and date'2016-02-22' and event_type_id = 1; ------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 74 | 79 (2)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | 74 | | | | 2 | VIEW | EVENTS | 12366 | 893K| 79 (2)| 00:00:01 | | 3 | UNION-ALL | | | | | | |* 4 | TABLE ACCESS FULL | EVENTS_01 | 6367 | 99K| 40 (0)| 00:00:01 | |* 5 | TABLE ACCESS FULL | EVENTS_02 | 5998 | 95968 | 38 (0)| 00:00:01 | |* 6 | FILTER | | | | | | |* 7 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_03 | 1 | 16 | 3 (0)| 00:00:01 | |* 8 | INDEX RANGE SCAN | EVENT_03_TIME_IDX | 1 | | 2 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("EVENT_TYPE_ID"=1 AND "EVENT_TIME">=TO_DATE(' 2016-01-10 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME"< TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 5 - filter("EVENT_TYPE_ID"=1 AND "EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME">=TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 6 - filter(NULL IS NOT NULL) 7 - filter("EVENT_TYPE_ID"=1) 8 - access("EVENT_TIME">=TO_DATE(' 2016-03-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
  • 120. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PARTITION VIEWS select count(details) from events where event_time between date'2016-01-10' and date'2016-02-22' and event_type_id = 1; ------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 74 | 79 (2)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | 74 | | | | 2 | VIEW | EVENTS | 12366 | 893K| 79 (2)| 00:00:01 | | 3 | UNION-ALL | | | | | | |* 4 | TABLE ACCESS FULL | EVENTS_01 | 6367 | 99K| 40 (0)| 00:00:01 | |* 5 | TABLE ACCESS FULL | EVENTS_02 | 5998 | 95968 | 38 (0)| 00:00:01 | |* 6 | FILTER | | | | | | |* 7 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_03 | 1 | 16 | 3 (0)| 00:00:01 | |* 8 | INDEX RANGE SCAN | EVENT_03_TIME_IDX | 1 | | 2 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("EVENT_TYPE_ID"=1 AND "EVENT_TIME">=TO_DATE(' 2016-01-10 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME"< TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 5 - filter("EVENT_TYPE_ID"=1 AND "EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME">=TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 6 - filter(NULL IS NOT NULL) 7 - filter("EVENT_TYPE_ID"=1) 8 - access("EVENT_TIME">=TO_DATE(' 2016-03-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
  • 121. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PARTITION VIEWS select count(details) from events where event_time between date'2016-01-10' and date'2016-02-22' and event_type_id = 6; ------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 74 | 42 (0)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | 74 | | | | 2 | VIEW | EVENTS | 2418 | 174K| 42 (0)| 00:00:01 | | 3 | UNION-ALL | | | | | | |* 4 | TABLE ACCESS FULL | EVENTS_01 | 2388 | 38208 | 40 (0)| 00:00:01 | |* 5 | TABLE ACCESS BY INDEX ROWID BATCHED | EVENTS_02 | 29 | 464 | 2 (0)| 00:00:01 | |* 6 | INDEX RANGE SCAN | EVENT_02_TYPE_IDX | 41 | | 1 (0)| 00:00:01 | |* 7 | FILTER | | | | | | |* 8 | TABLE ACCESS BY INDEX ROWID BATCHED| EVENTS_03 | 1 | 16 | 2 (0)| 00:00:01 | |* 9 | INDEX RANGE SCAN | EVENT_03_TYPE_IDX | 1 | | 1 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("EVENT_TYPE_ID"=6 AND "EVENT_TIME">=TO_DATE(' 2016-01-10 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME“ <TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 5 - filter("EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME">=TO_DATE(' 2016-02-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 6 - access("EVENT_TYPE_ID"=6) 7 - filter(NULL IS NOT NULL) 8 - filter("EVENT_TIME"<=TO_DATE(' 2016-02-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_TIME">=TO_DATE(' 2016-03-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 9 - access("EVENT_TYPE_ID"=6)
  • 122. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon PARTITION VIEWS  It’s our responsibility to insert into the right partition  EXCHANGE PARTITION is supported  Indexing  Local indexes are supported by definition  Global indexes are not (easily) supported  Partial indexes are supported by definition
  • 123. THANK YOU Oren Nakdimon www.db-oriented.com  oren@db-oriented.com  +972-54-4393763 @DBoriented