Sie sind auf Seite 1von 149

6/13/2017

WE
ARE
SHOWING
CODING SAMPLES
SO IF YOU HAVE PASSED
THE AGE OF TWENTY THEN YOU SHOULD PROBABLY THINK
ABOUT SITTING RIGHT UP CLOSE TO THE FRONT OF THE ROOM BECAUSE OTHERWISE YOU MIGHT MISS OUT
A N D I F Y O U C A N R E A D T H I S, T H E N Y O U S H O U L D L E A V E B E C A U S E Y O U H A V E S U P E R P O W E R S A N D Y O U S H O U L D B E I N A N A V E N G E R S M O V I E N O T L E A R N I N G A B O U T I N F O R M A T I O N T E C H N O L O G Y. :-)

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

1
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 3

@connor_mc_d connormcdonald.wordpress.com

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 4

2
6/13/2017

https://www.youtube.com/c/ConnorMcDonaldOracle

https://www.facebook.com/connor.mcdonald42
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 5

12 things Devs will love about 12.2

Connor McDonald
Developer Advocate
June 2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

3
6/13/2017

why am I here ?

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 8

4
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 9

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 10

5
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 11

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 12

6
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 14

7
6/13/2017

"why am I here?"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 15

12.2!
12.2! 12.2!
12.2!12.2!
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 16

8
6/13/2017

reality

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 17

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 18

9
6/13/2017

SQL> select * from v$version;

BANNER
----------------------------------------------------------
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
PL/SQL Release 8.1.7.4.0 - Production
CORE 8.1.7.0.0 Production
TNS for HPUX: Version 8.1.7.4.0 - Production
NLSRTL Version 3.4.1.0.0 - Production

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 19

SQL> select * from v$version;

BANNER
----------------------------------------------------------
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
PL/SQL Release 8.1.7.4.0 - Production
CORE 8.1.7.0.0 Production
TNS for HPUX: Version 8.1.7.4.0 - Production
NLSRTL Version 3.4.1.0.0 - Production

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 20

10
6/13/2017

SQL> select * from v$version;

BANNER
----------------------------------------------------------
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
PL/SQL Release 8.1.7.4.0 - Production
CORE 8.1.7.0.0 Production
TNS for HPUX: Version 8.1.7.4.0 - Production
NLSRTL Version 3.4.1.0.0 - Production

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 21

you still should be here

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 22

11
6/13/2017

dont reinvent

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 23

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

12
6/13/2017

there's a lot in 12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 25

get started right now

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 26

13
6/13/2017

install nothing

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 27

https://cloud.oracle.com/tryit

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 28

14
6/13/2017

install something

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 29

http://tinyurl.com/ora122vm

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 30

15
6/13/2017

install lots :-)

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 31

http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 32

16
6/13/2017

before we get started

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 33

Safe Harbor Statement


The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracles products remains at the sole discretion of Oracle.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 34

17
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 35

test ! Test ! TEST !

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 36

18
6/13/2017

licensing

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 37

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 38

19
6/13/2017

time is short ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 39

asktom.oracle.com

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 40

20
6/13/2017

1
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 41

longer names

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 42

21
6/13/2017

128 bytes

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 43

"awesome"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 44

22
6/13/2017

SQL> create table MY_TABLE


2 (
3 LONGER_COLUMNS_ARE_BETTER_BECAUSE_THEY_GIVE_MORE_MEANING DATE
4 );

Table created.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 45

true

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 46

23
6/13/2017

"can I get a CSV of the chart of accounts?"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 47

SQL> select table_name


2 from user_tables;

TABLE_NAME
------------------------------
T001B Permitted Posting Periods
T003 Document types
T004 Chart of accounts
T009 Fiscal year variants
T010O Posting periods
T010P Posting Period Names
T012 House banks
T014 Credit control area
T077S Account group (G/L accounts)
T880 Global company data
...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 48

24
6/13/2017

and...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 49

SQL> create table FINALISED_ANNUAL_BUDGET_STATS


2 ( budget_seq int,
3 fiscal_year int,
...
...
24 );

Table created.

SQL> alter table FINALISED_ANNUAL_BUDGET_STATS


2 add constraint FINALISED_ANNUAL_BUDGET_STATS_PK
3 primary key ( budget_seq );

add constraint FINALISED_ANNUAL_BUDGET_STATS_PK


*
ERROR at line 2:
ORA-00972: identifier is too long

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 50

25
6/13/2017

but...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 51

SQL> create table MY_TABLE


2 (
3 "SomeRidiculousPieceOfNonsenseBySomeDude
WhoWantsToAlignTheDatabaseWithHisDotNetCodingStyle" DATE
4 );
SQL> select column_name,num_distinct,avg_col_len, num_nulls
2 from all_tab_cols
Table
3 created.
where table_name = upper('&table_name')
4 order by column_id;

Enter value for table_name: MY_TABLE

COLUMN_NAME
------------------------------
SomeRidiculousPieceOfNonsenseBySomeDudeWhoWantsToAlignWithHisDotNetCodi
ngStyle NUM_DISTINCT AVG_COL_LEN NUM_NULLS
------------ ----------- ----------

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 52

26
6/13/2017

get crafty :-)

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 53

SQL> create or replace


2 trigger ddl_trigger
3 before create or alter on demo.SCHEMA
4 declare
5 l_obj varchar2(128);
6 l_dba int;
7 begin
8 l_obj := ora_dict_obj_name;
9
10 select count(*)
11 into l_dba
12 from dba_role_privs
13 where grantee = user
14 and granted_role = 'SENIOR_DEV';
15
16 if l_dba = 0 and length(l_obj) > 30 then
17 raise_application_error(-20000,'Identifier "'||l_obj||'" is too long');
18 end if;
19 end;

Trigger created.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 54

27
6/13/2017

SQL> conn demo/demo@db122pdb


Connected.

SQL> create table EMPLOYEES ( empno int , dept int);

Table created.

SQL> create table EMPLOYEE_RATINGS_BENEFITS_BEFORE_SALARY_REVIEW


2 ( empno int, dept int );

create table EMPLOYEE_RATINGS_BENEFITS_BEFORE_SALARY_REVIEW


*
ERROR at line 1:
ORA-04088: error during execution of trigger 'CONNOR.DDL_TRIGGER'
ORA-00604: error occurred at recursive SQL level 1
ORA-20000: Identifier "EMPLOYEE_RATINGS_BENEFITS_BEFORE_SALARY_REVIEW" is too long
ORA-06512: at line 16

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 55

SQL> conn connor/*******@db122pdb


Connected.

SQL> alter table DEMO.EMPLOYEES add


2 constraint EMPLOYEES_CROSS_DIVISION_DEPARTMENTS_FK foreign key
3 ( dept ) references DEMO.CROSS_DIVISION_DEPARTMENTS ( dept ) ;

Table altered.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 56

28
6/13/2017

2
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 57

PL/SQL resolved expressions

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 58

29
6/13/2017

so.... longer names

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 59

SQL> create or replace


2 procedure process_tab is
3 l_tab varchar2(30);
4 begin
5 select table_name
6 into l_tab
7 from user_tables
8 where ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

30
6/13/2017

SQL> exec process_tab;

ORA-06502: PL/SQL: numeric or value


error: character string buffer too
small

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 62

31
6/13/2017

expression in place of literal

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 63

SQL> declare
2 c_var_length constant pls_integer := 30;
3 l_str varchar2(c_var_length);
4 begin
5 null;
6 end;
7 /

PL/SQL procedure successfully completed.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

32
6/13/2017

SQL

must be resolvable at compile time

function

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 65

SQL> declare
2 c_var_length constant pls_integer := to_number('30');
3 l_str varchar2(c_var_length);
4 begin
5 null;
6 end;
7 /
l_str varchar2(c_var_length);
*
ERROR at line 3:
ORA-06550: line 3, column 25:
PLS-00491: numeric literal required

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

33
6/13/2017

SQL> declare
2 c_var_length constant pls_integer := 30;
3 l_str varchar2(c_var_length);

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> create or replace


2 procedure process_tab is
3 l_str varchar2(ora_max_name_len);
4 begin

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

34
6/13/2017

start today

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 69

SQL> create or replace


2 procedure process_tab is
3
4 $if DBMS_DB_VERSION.VER_LE_12_1 $then
5 l_str varchar2(30);
6 $else
7 l_str varchar2(ora_max_name_len);
8 $end
9
10 begin

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

35
6/13/2017

"Wasn't I just supposed to use ..."

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 71

user_tables.table_name%type

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

36
6/13/2017

Yes ... but

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 73

SQL> create or replace


2 procedure process_tab is
3 l_str varchar2( );
?
4 begin
5 select owner||'.'||table_name
6 into l_str
7 from all_tables
8 where ...
9

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

37
6/13/2017

SQL> create or replace


2 procedure process_tab is
3 l_str varchar2(2*ora_max_name_len+1);
4 begin
5 select owner||'.'||table_name
6 into l_str
7 from all_tables
8 where ...
9

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

3
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 76

38
6/13/2017

So ... I've got

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 77

SQL> desc STORE_SALES

Name Type
--------------------------------------------------------------------------------- ----------
SALES_PK NUMBER(38)
DATE_AT_WHICH_CUSTOMER_CAME_INTO_THE_STOP DATE
DATE_AT_WHICH_CUSTOMER_CAME_LEFT_THE_STOP DATE
DURATION_CUSTOMER_SPENT_BROWSING_SALES_CATALOG_BEFORE_ASKING_FOR_ASSISTANCE_MINS NUMBER(38)
ITEM_THAT_CUSTOMER_PURCHASED VARCHAR2(50)
AMOUNT_CUSTOMER_TENDERED_TO_CASHIER_IN_50DOLLAR_NOTES NUMBER(38)
AMOUNT_CUSTOMER_TENDERED_TO_CASHIER_IN_20DOLLAR_NOTES NUMBER(38)
AMOUNT_CUSTOMER_TENDERED_TO_CASHIER_IN_10DOLLAR_NOTES NUMBER(38)
AMOUNT_CUSTOMER_TENDERED_TO_CASHIER_IN_5DOLLAR_NOTES NUMBER(38)
AMOUNT_CUSTOMER_TENDERED_TO_CASHIER_IN_COINS_IN_TOTAL_CENTS NUMBER(38)
LENGTH_IN_MILLIMETERS_OF_THE_RECEIPT_WE_PRINTED_FOR_THE_CUSTOMER NUMBER(38)
AVERAGE_LENGTH_OF_SHOELACE_OF_STORE_ASSISTANT_THAT_HELPED_THE_CUSTOMER NUMBER(38)
...
...
...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

39
6/13/2017

... compile time resolvable datatype sizes

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 79

SQL> select table_name,


2 listagg(column_name, ',') within group
3 (order by column_id) cols
4 from user_tab_columns
5 group by table_name;

*
ERROR at line 1:
ORA-01489: result of string concatenation is too long

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

40
6/13/2017

tough to solve

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 81

SQL> select
2 column_name,
3 ( select listagg(column_name,',') within group ( order by column_id )
4 from all_tab_columns
5 where table_name = 'EMP'
6 and owner = 'SCOTT'
7 and column_id <= a.column_id ) cols
8 from all_tab_columns a
9 where table_name = 'EMP'
10 and owner = 'SCOTT'
11 order by column_id;

COLUMN_NAME COLS
------------------------------ ----------------------------------------------------
EMPNO EMPNO
ENAME EMPNO,ENAME
JOB EMPNO,ENAME,JOB
MGR EMPNO,ENAME,JOB,MGR
HIREDATE EMPNO,ENAME,JOB,MGR,HIREDATE
SAL EMPNO,ENAME,JOB,MGR,HIREDATE,SAL
COMM EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM
DEPTNO EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO

8 rows selected.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

41
6/13/2017

first principles

pipeline function

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 83

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 84

42
6/13/2017

improved overflow handling

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 85

SQL> select table_name,


2 listagg(column_name, ',' on overflow truncate)
3 within group (order by column_id) cols
4 from user_tab_columns
5 group by table_name;

TABLE_NAME COLS
------------- ------------------------------------------------------------
STORE_SALES SALES_PK,DATE_AT_WHICH_CUSTOMER_CAME_INTO_THE_STOP,DATE_AT_W
HICH_CUSTOMER_CAME_LEFT_THE_STOP,DURATION_CUSTOMER_SPENT_BRO
WSING_SALES_CATALOG_BEFORE_ASKING_FOR_ASSISTANCE_IN_MINS,ITE
,LENGTH_IN_MILLIMETERS_OF_THE_RECEIPT_WE_PRINTED_FOR_THE_CUS

[snip]

TIME_SPENT_WHILST_REFOLDING_ITE...(2378)

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

43
6/13/2017

plus you get control

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 87

SQL> select table_name,


2 listagg(column_name, ',' on overflow truncate '[more]')
3 within group (order by column_id) cols
4 from user_tab_columns
5 group by table_name;

TABLE_NAME COLS
------------- ------------------------------------------------------------
STORE_SALES SALES_PK,DATE_AT_WHICH_CUSTOMER_CAME_INTO_THE_STOP,DATE_AT_W
HICH_CUSTOMER_CAME_LEFT_THE_STOP,DURATION_CUSTOMER_SPENT_BRO
WSING_SALES_CATALOG_BEFORE_ASKING_FOR_ASSISTANCE_IN_MINS,ITE
,LENGTH_IN_MILLIMETERS_OF_THE_RECEIPT_WE_PRINTED_FOR_THE_CUS

[snip]

TIME_SPENT_WHILST_REFOLDING_ITE[more](2378)

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

44
6/13/2017

SQL> select table_name,


2 listagg(column_name,','
3 on overflow truncate '[more]' without count)
4 within group (order by column_id) cols
5 from user_tab_columns
6 group by table_name;

TABLE_NAME COLS
------------- ------------------------------------------------------------
STORE_SALES SALES_PK,DATE_AT_WHICH_CUSTOMER_CAME_INTO_THE_STOP,DATE_AT_W
HICH_CUSTOMER_CAME_LEFT_THE_STOP,DURATION_CUSTOMER_SPENT_BRO
WSING_SALES_CATALOG_BEFORE_ASKING_FOR_ASSISTANCE_IN_MINS,ITE
,LENGTH_IN_MILLIMETERS_OF_THE_RECEIPT_WE_PRINTED_FOR_THE_CUS

[snip]

TIME_SPENT_WHILST_REFOLDING_ITE[more]

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> select table_name,


2 listagg(column_name,','
3 on overflow truncate '' without count)
4 within group (order by column_id) cols
5 from user_tab_columns
6 group by table_name;

TABLE_NAME COLS
------------- ------------------------------------------------------------
STORE_SALES SALES_PK,DATE_AT_WHICH_CUSTOMER_CAME_INTO_THE_STOP,DATE_AT_W
HICH_CUSTOMER_CAME_LEFT_THE_STOP,DURATION_CUSTOMER_SPENT_BRO
WSING_SALES_CATALOG_BEFORE_ASKING_FOR_ASSISTANCE_IN_MINS,ITE
,LENGTH_IN_MILLIMETERS_OF_THE_RECEIPT_WE_PRINTED_FOR_THE_CUS

[snip]

TIME_SPENT_WHILST_REFOLDING_ITE

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

45
6/13/2017

4
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 91

QTFWBC

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 92

46
6/13/2017

queries that finish without bloody crashing

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 93

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 94

47
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 95

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 96

48
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 97

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 98

49
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 99

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

Elapsed: 06:12:34.00

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 100

50
6/13/2017

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

Elapsed: 06:12:34.00

ERROR at line 1:
ORA-01847: day of month must be between 1 and last day of month

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 101

and then we do this :-)

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 102

51
6/13/2017

SQL> select count(*) from MY_TABLE;

COUNT(*)
----------
0

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 103

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 104

52
6/13/2017

validate_conversion

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 105

SQL> select CREATED_DATE


2 from MY_WHOPPING_GREAT_FAT_TABLE;

CREATED_DATE
--------------------
01-FEB-2016
12-MAR-2012
54-AUG-2013
09-SEP-2014
23-OCT-2012
...
...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 106

53
6/13/2017

SQL> select to_date(created_date, 'dd-mon-yyyy')


2 from MY_WHOPPING_GREAT_FAT_TABLE
3 where validate_conversion(
4 created_date as date, 'dd-MON-yyyy'
5 ) = 1;

TO_DATE(C
---------
01-FEB-16
12-MAR-12
09-SEP-14
23-OCT-12

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 107

CAST extended

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 108

54
6/13/2017

SQL> select SALARY,


2 cast(SALARY as number
3 DEFAULT -1 ON CONVERSION ERROR) conv_sal
4 from MY_WHOPPING_GREAT_FAT_TABLE;

SALARY CONV_SAL
---------- ----------
120000 120000
172125 172125
128000 128000
125,000 -1
99500 99500
...
...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 109

SQL> select SALARY,


2 TO_NUMBER(SALARY
3 DEFAULT -1 ON CONVERSION ERROR) conv_sal
4 from MY_WHOPPING_GREAT_FAT_TABLE;

SALARY CONV_SAL
---------- ----------
120000 120000
172125 172125
TO_DATE
128000 128000 TO_NUMBER
125,000 -1
99500 99500 TO_TIMESTAMP
etc

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 110

55
6/13/2017

5
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 111

column level collation

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 112

56
6/13/2017

SQL> select *
2 from customers
3 where cust_name = 'ADAMS';

COUNTRY CREATED CUST_NAME


------------ --------- ---------------------
AUS 08-NOV-16 ADAMS

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

looks great... until

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 114

57
6/13/2017

SQL> select *
2 from customers
3 where upper(cust_name) = 'ADAMS';

COUNTRY CREATED CUST_NAME


------------ --------- ------------
AUS 07-NOV-16 Adams
AUS 08-NOV-16 ADAMS
AUS 09-NOV-16 adams

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> select * from customers


2 where upper(cust_name) = 'ADAMS';

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 116

58
6/13/2017

SQL> select column_name


2 from user_ind_columns
3 where index_name = 'CUST_IX';

COLUMN_NAME
------------------------------
CUST_NAME

SQL> select * from customers


2 where upper(cust_name) = 'ADAMS';

-------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 152 |
|* 1 | TABLE ACCESS FULL| CUSTOMERS | 1 | 152 |
-------------------------------------------------------

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> create index cust_ix


2 on customers ( cust_name );

Index created.

SQL> create index cust_ix2


2 on customers ( upper(cust_name) );

Index created.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

59
6/13/2017

DML slower

more contention

more redo/undo space

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 119

"not my problem"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 120

60
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 121

SQL> alter table customers shrink space;

*
ERROR at line 1:
ORA-10631: SHRINK clause should not be specified for this object

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

61
6/13/2017

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 123

column level collation

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 124

62
6/13/2017

? Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 125

SQL> CREATE TABLE CUSTOMERS


2 (
3 COUNTRY VARCHAR2(128),
4 CREATED DATE,
5 CUST_NAME VARCHAR2(150) COLLATE BINARY_CI
6 );

Table created.

"case insenstive"
Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

63
6/13/2017

SQL> create index cust_ix


2 on customers ( cust_name);

Index created.

SQL> set autotrace traceonly explain


SQL> select * from customers
2 where cust_name = 'ADAMS';

-----------------------------------------------------------------
| Id | Operation | Name | Rows |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| CUSTOMERS | 1 |
|* 2 | INDEX RANGE SCAN | CUST_IX | 1 |
-----------------------------------------------------------------

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

"big deal"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 128

64
6/13/2017

SQL> select * from customers


2 where cust_name = 'ADAMS';

COUNTRY CREATED CUST_NAME


------------ --------- ----------------
AUS 07-NOV-16 Adams
AUS 08-NOV-16 ADAMS
AUS 09-NOV-16 adams

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

binary_ci
SQL> select * from customers
2 where cust_name = 'ADAMS';

COUNTRY CREATED CUST_NAME


------------ --------- ----------------
AUS 07-NOV-16 Adams
AUS 08-NOV-16 ADAMS
AUS 09-NOV-16 adams

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 130

65
6/13/2017

binary_ai
SQL> select * from customers
2 where cust_name = 'ADAMS';

COUNTRY CREATED CUST_NAME


------------
AUS
AUS
---------
07-NOV-16
08-NOV-16
----------------
Adams
ADAMS
adms
AUS 09-NOV-16 adams
AUS 10-NOV-16 adms

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 131

column | table | user

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 132

66
6/13/2017

SQL> alter table people default collation binary_ai;

new columns only

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

key point

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 134

67
6/13/2017

SQL> alter table people default collation binary_ai;

*
ERROR at line 1:
ORA-43929: Collation cannot be specified if
parameter MAX_STRING_SIZE=STANDARD

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

6
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 136

68
6/13/2017

deprecated code

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 137

"huh?"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 138

69
6/13/2017

deprecate your code

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 139

so ... moved to case insensitivity


column collation

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 140

70
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 141

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 142

71
6/13/2017

SQL> create or replace


2 package customer_pkg as
3
4 cursor get_customers(p_name varchar2) is
5 select * from customers
6 where upper(customer_name) = upper(p_name);
7
8 ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> create or replace


2 package customer_pkg as
3
4 --
5 -- do not use
6 --
7 cursor get_customers(p_name varchar2) is
8 select * from customers
9 where upper(customer_name) = upper(p_name);
10
11 --
12 -- fixed with CI collation
13 --
14 cursor get_cust_ci(p_name varchar2) is
15 select * from customers
16 where customer_name = p_name;
Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

72
6/13/2017

"wot eva"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 145

new pragma

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 146

73
6/13/2017

SQL> create or replace


2 package customer_pkg as
3 cursor get_customers(p_name varchar2) is
4 select * from customers
5 where upper(customer_name) = upper(p_name);
6
7 pragma deprecate(get_customers,'Use get_cust_ci');
8
9 cursor get_cust_ci(p_name varchar2) is
10 select * from customers
11 where customer_name = p_name;

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> alter system set


2 plsql_warnings = enable:(6019,6020,6021,6022)';

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

74
6/13/2017

SQL> alter procedure PROCESS_CUSTOMERS compile;

SP2-0804: Procedure created with compilation warnings

LINE/COL ERROR
-------- -----------------------------------------------------------
1/1 PLW-05018: unit PROCESS_CUSTOMERS omitted optional AUTHID
clause; default value DEFINER used

7/9 PLW-06020: reference to a deprecated entity:


GET_CUSTOMERS declared in unit CUSTOMER_PKG[2,10].
Use get_cust_ci instead

8/9 PLW-06020: reference to a deprecated entity:

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

... and still

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 150

75
6/13/2017

"wot eva"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 151

SQL> alter system set


2 plsql_warnings = error:(6019,6020,6021,6022)';

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

76
6/13/2017

SQL> alter procedure PROCESS_CUSTOMERS compile;

SP2-0804: Procedure created with compilation errors

LINE/COL ERROR
-------- -----------------------------------------------------------
1/1 PLW-05018: unit PROCESS_CUSTOMERS omitted optional AUTHID
clause; default value DEFINER used

7/9 PLW-06020: reference to a deprecated entity:


GET_CUSTOMERS declared in unit CUSTOMER_PKG[2,10].
Use get_cust_ci instead

8/9 PLW-06020: reference to a deprecated entity:

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

7
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 154

77
6/13/2017

external tables

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 155

ext_emp

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

78
6/13/2017

SQL> create table ext_emp (


2 empno number(4),
3 ename varchar2(10),
4 12 (
job type oracle_loader
varchar2(9),
5 13 mgr default directory TMP
number(4),
6 14 access parameters
hiredate date,
7 15 sal ( records delimited by newline
number(7,2),
8 16 comm fields
number(7,2), by ','
terminated
9 17 deptnomissing field values are null
number(2)
10 18) ( empno,ename,job,mgr,hiredate,sal,comm,deptno )
19 )
11 organization external
20 location ('emp20161001.dat'));

Table created.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

ext_emp

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

79
6/13/2017

SQL> select * from ext_emp;


select * from ext_emp
*
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEFETCH callout
ORA-30653: reject limit reached

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

easy fix

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 160

80
6/13/2017

SQL> create table ext_emp (


2 empno number(4),
...
12 ( type oracle_loader
13 default directory TMP
14 access parameters
15 ( records delimited by newline
16 fields terminated by ','
17 missing field values are null
18 ( empno,ename,job,mgr,hiredate,sal,comm,deptno )
19 )
20 location ('emp20161001.dat'))
21 REJECT LIMIT UNLIMITED;

Table created.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

it's ddl

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 162

81
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 163

ITIL :-(

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 164

82
6/13/2017

service
call
help
desk DONEproblem
!
record

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 166

83
6/13/2017

query time modification

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 167

SQL> select * from ext_emp


2 external modify ( reject limit unlimited );

EMPNO ENAME JOB MGR HIREDATE SAL


---------- ---------- --------- ---------- --------- ---------- ---
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
7521 WARD SALESMAN 7698 22-FEB-81 1250
7566 JONES MANAGER 7839 02-APR-81 2975

...

7902 FORD ANALYST 7566 03-DEC-81 3000


7934 MILLER CLERK 7782 23-JAN-82 1300

13 rows selected.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

84
6/13/2017

file names

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 169

SQL> create table ext_emp (


2 empno number(4),

...

20 location ('emp20161001.dat'))

Table created.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

85
6/13/2017

SQL> select * from ext_emp


2 external modify ( location ('emp20161002.dat') );

EMPNO ENAME JOB MGR HIREDATE SAL


---------- ---------- --------- ---------- --------- ---------- ---
7902 FORD ANALYST 7566 03-DEC-81 3000
7934 MILLER CLERK 7782 23-JAN-82 1300
7566 JONES MANAGER 7839 02-APR-81 2975

...

7499 ALLEN SALESMAN 7698 20-FEB-81 1600


7521 WARD SALESMAN 7698 22-FEB-81 1250

8 rows selected.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

select * from ext_tab external modify (


[ default directory ]
[ location ]
[ access parameters ]
[ reject limit ]
);

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

86
6/13/2017

8
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 173

ACCOUNTING,KING,PRESIDENT,5000
ACCOUNTING,MILLER,CLERK,1300

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 174

87
6/13/2017

<department name="ACCOUNTING">
<employees>
<employee>
<ename>KING</ename>
<job>PRESIDENT</job>
<sal>5000</sal>
</employee>
<employee>
<ename>MILLER</ename>
<job>CLERK</job>
<sal>1300</sal>
</employee>
</employees>
</department>

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 175

{ "NAME" :"ACCOUNTING"
, "EMPLOYEES" : [
{"ENAME" : "KING",
"JOB" : "PRESIDENT",
"SAL" : 5000
},
{"ENAME" : "MILLER",
"JOB" : "CLERK",
"SAL" : 1300
}]
}

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 176

88
6/13/2017

12.1.0.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 177

alter table T
add constraint t_chk
check
(
my_doc is JSON
)

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 178

89
6/13/2017

extraction

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 179

SQL> select json_value(my_doc,


2 '$.ACCOUNTING.EMPLOYEES[0].ENAME') as ename
3 from t;

ENAME
----------
KING

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 180

90
6/13/2017

dot notation

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 181

SQL> select t.my_doc.ACCOUNTING.EMPLOYEES.ENAME emps,


2 t.my_doc.ACCOUNTING.EMPLOYEES.JOB jobs,
3 t.my_doc.ACCOUNTING.EMPLOYEES.SAL sals
4 from T t;

EMPS JOBS SALS


-------------------- ------------------- ---------------
[KING,MILLER] [PRESIDENT,CLERK] [5000,1300]

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 182

91
6/13/2017

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 183

generation

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 184

92
6/13/2017

{
"department": "Accounting",
"employees": [
{
"name": "Shelley,Higgins",
"job": "Accounting Manager"
},
{
"name": "William,Gietz",
"job": "Public Accountant"
}
]
}

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

{"newJSONfunctions": [
"json_array",
"json_object",
"json_arrayagg",
"json_objectagg"
] }

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

93
6/13/2017

SQL> select
2 json_array(department_id, department_name) depts
3 from hr.departments
4 where department_id > 200;

DEPTS
--------------------------------------------------------
[210,"IT Support"]
[220,"NOC"]
[230,"IT Helpdesk"]
[240,"Government Sales"]
[250,"Retail Sales"]
[260,"Recruiting"]
[270,"Payroll"]

7 rows selected.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> select
2 json_object(
3 'DeptID' is department_id,
4 'Name' is department_name) depts
5 from hr.departments
6 where department_id > 200;

DEPTS
------------------------------------------------
{"DeptID":210,"Name":"IT Support"}
{"DeptID":220,"Name":"NOC"}
{"DeptID":230,"Name":"IT Helpdesk"}
{"DeptID":240,"Name":"Government Sales"}
{"DeptID":250,"Name":"Retail Sales"}
{"DeptID":260,"Name":"Recruiting"}
{"DeptID":270,"Name":"Payroll"}

7 rows selected.
Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

94
6/13/2017

SQL> select json_object(


2 'department' value d.department_name,
3 'employees' value json_arrayagg(
4 json_object(
5 'name' value first_name||','||last_name,
6 'job' value job_title
7 )))
8 from hr.departments d, hr.employees e, hr.jobs j
9 where d.department_id = e.department_id
10 and e.job_id = j.job_id
11 and d.department_id = 110
12 group by d.department_name;

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

json_exists JSON Partitioning

Materialized Views
Search index
... and more JSON goodies
GeoJSON
In-Memory support
JSON Data Guide
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 190

95
6/13/2017

SQL> desc ORDERS


NAME TYPE
------------------ -----------
ORDER_DETAILS BLOB

{"date": "2016-05-03 10:40:36",


"loyaltyCardNo": 1230,
"location": {
"city": "Dallas",
"state": "TX},
"salesAmount": 7.55,
"order": [ {
"item": "Espresso, ... }
}

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 191

SQL> SELECT JSON_DATAGUIDE(o.order_details) FROM orders o;

JSON_DATAGUIDE(O.ORDER_DETAILS)
----------------------------------------------------------------------
[ {"o:path": "$.date", "type": "string", "o:length": 32 },
{"o:path": "$.order", "type": "array", "o:length": 256 },
{"o:path": "$.location", "type": "object", "o:length": 32},
{"o:path": "$.location.city", "type": "string", "o:length": 8},

...
...

{ "o:path": "$.salesAmount", "type": "number", "o:length": 4 },


{ "o:path": "$.loyaltyCardNo","type": "number", "o:length": 8}]

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 192

96
6/13/2017

9
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 193

analytic views

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 194

97
6/13/2017

here's the two problems

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 195

1) good data modelling ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 196

98
6/13/2017

... is often wasted :-(

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 197

SQL> create table FINANCIAL_RESULTS


2 ( fin_id int,
3 fiscal_year date,
4 department_id int,

...
...

19 profit number(10,2),
...
...
32 );

Table created.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 198

99
6/13/2017

"What is the profit for 2016 ?"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 199

sounds easy

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 200

100
6/13/2017

SQL> select sum(profit) total


2 from financial_results
3 where fiscal_year = date '2016-01-01';

TOTAL
------------
24274312.17

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 201

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 202

101
6/13/2017

it's never like that :-(

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 203

BI tools / metadata

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 204

102
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 205

SQL> select sum(profit) total


2 from financial_results
3 where fiscal_year = date '2016-01-01';

TOTAL
------------
24274312.17

huh?

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 206

103
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 207

data profit

SQL

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 208

104
6/13/2017

data profit

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 209

and everyone has Excel

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 210

105
6/13/2017

profit 2.0

data profit

profit 3.0
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 211

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 212

106
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 213

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 214

107
6/13/2017

1+1=3
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 215

2) lies and deceit

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 216

108
6/13/2017

"SQL is easy"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 217

SELECT <info you want>

FROM <its source>

WHERE <your criteria>

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 218

109
6/13/2017

select ...
WITH
from details
my_fact_table
as ( f,
dim_region dr,
dim_customer dc,
dim_gender dg,
dim_locality dl,
dim_cal_year dyc,
)
dim_fiscal_year
,pct_dist as ( dyf
where select
...
from
...
my_fact_table f,
dim_region dr,
dim_customer dc,
dim_gender dg
where ...
)
,pct_region as ( first_value(blah ignore nulls )
select ...
from my_fact_table f,
within_group (
dim_region dr, partition by blah
dim_customer dc,
dim_gender dg order by x nulls first )
where ...
)
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 219

why ?

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 220

110
6/13/2017

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 221

complex BI layers

complexity for BI staff

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 222

111
6/13/2017

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 223

analytic views

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 224

112
6/13/2017

aggregations
cross-row calculations
classifications
in the database

hierarchies distributions

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 225

single source of truth

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 226

113
6/13/2017

simple queries for BI

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 227

select
time_hierarchy.member_name as time,
product_hierarchy.member_name as product,
geo_hierarchy.member_name as geo,
sales,
sales_year_ago,
sales_chg_year_ago,
sales_pctchg_year_ago
from
sales_av hierarchies(time_hierarchy, product_hierarchy, geo_hierarchy)
where
time_hierarchy.level_name = 'YEAR'
and product_hierarchy.level_name = 'CATEGORY'
and geo_hierarchy.level_name = 'REGION;

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 228

114
6/13/2017

select
time_hierarchy.member_name as time,
product_hierarchy.member_name as product,
geo_hierarchy.member_name as geo,
sales,
sales_year_ago,
sales_chg_year_ago,
sales_pctchg_year_ago
from
sales_av hierarchies(time_hierarchy, product_hierarchy, geo_hierarchy)
where
time_hierarchy.level_name = 'MONTH'
and product_hierarchy.level_name = 'CATEGORY'
and geo_hierarchy.level_name = 'REGION;

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 229

select
time_hierarchy.member_name as time,
product_hierarchy.member_name as product,
geo_hierarchy.member_name as geo,
sales,
sales_year_ago,
sales_chg_year_ago,
sales_pctchg_year_ago
from
sales_av hierarchies(time_hierarchy, product_hierarchy, geo_hierarchy)
where
time_hierarchy.level_name = 'YEAR'
and product_hierarchy.level_name = 'ITEM'
and geo_hierarchy.level_name = 'REGION;

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 230

115
6/13/2017

select
time_hierarchy.member_name as time,
product_hierarchy.member_name as product,
geo_hierarchy.member_name as geo,
sales,
sales_year_ago,
sales_chg_year_ago,
sales_pctchg_year_ago
from
sales_av hierarchies(time_hierarchy, product_hierarchy, geo_hierarchy)
where
time_hierarchy.level_name = 'YEAR'
and product_hierarchy.level_name = 'ITEM'
and geo_hierarchy.level_name = 'REGION;

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 231

huge topic

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 232

116
6/13/2017

livesql.oracle.com

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 233

10
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 234

117
6/13/2017

almost correct SQL

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 235

"huh?"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 236

118
6/13/2017

background

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 237

don't you hate ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 238

119
6/13/2017

ALERT: Batch load failed

Batch process ended in error.

Module: Financial Reconcilation


Issue: Yearly total
Expected: $7,102,231.76
Actual: $7,102,231.32

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 239

$7,100,000
$8,200,000
$7,700,000

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 240

120
6/13/2017

sometimes ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 241

close enough ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 242

121
6/13/2017

... is good enough

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 243

the hardest one ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 244

122
6/13/2017

SQL> select count(distinct ...) cdist


2 from my_super_massive_table;

CDIST
-------
12

Elapsed: 01:32:17.00

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

12.1.0.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 246

123
6/13/2017

SQL> select approx_count_distinct(...) cdist


2 from my_super_massive_table;

CDIST
-------
12

Elapsed: 00:12:43.00

Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

but ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 248

124
6/13/2017

SQL> select count(*)


2 from user_source
3 where upper(text) like '%COUNT(%DISTINCT%';

COUNT(*)
----------
1723

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 249

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 250

125
6/13/2017

SQL> alter session set approx_for_count_distinct = true;

Session altered.

SQL> select count(distinct ...)


approx_count_distinct(...)
2 from my_super_massive_table;

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 251

approx_count_distinct_detail

approx_median

more functions

to_approx_...
approx_percentile

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 252

126
6/13/2017

more confidence

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 253

SQL> select department,


2 approx_median(salary deterministic) med_sal
3 from employees
4 group by department
5 order by department;

DEPARTMENT MED_SAL
---------- -------------
10 4400
20 6000
30 2765
40 6500

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 254

127
6/13/2017

SQL> select
2 department,
3 approx_median(salary deterministic, 'ERROR_RATE') err
4 from employees
5 group by department
6 order by department;

DEPARTMENT ERR
---------- -------------
10 .002718282
20 .021746255
30 .021746255
40 .002718282
50 .019027973
60 .019027973

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 255

SQL> select
2 department,
3 approx_median(salary, 'CONFIDENCE') conf
4 from employees
5 group by department
6 order by department;

DEPARTMENT CONF
---------- -------------
10 .997281718
20 .999660215
30 .999660215
40 .997281718
50 .999611674
60 .999611674
70 .997281718

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 256

128
6/13/2017

11
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 257

partitioning

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 258

129
6/13/2017

10g and earlier

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 259

SQL> create table SALES


2 ( cal_year date,
3 txn_id int,
...
...
24 )
25 partition by range ( cal_year )
26 (
27 partition p_low values less than ( date '2000-01-01' ),
28 partition p2000 values less than ( date '2001-01-01' ),
...
...
34 partition p2016 values less than ( date '2017-01-01' )
35 );

Table created.
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 260

130
6/13/2017

SQL> insert into SALES


2 values ( trunc(sysdate), .... );

insert into SALES


*
ERROR at line 1:
ORA-14400: inserted partition key does not map to any partition

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 261

11g

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 262

131
6/13/2017

interval partitioning

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 263

SQL> create table SALES


2 ( cal_year date,
3 txn_is int
4 )
5 partition by range ( cal_year )
6 interval ( numtoyminterval(1,'YEAR') )
7 (
8 partition p_low values less than ( date '2000-01-01' )
9 );

Table created.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 264

132
6/13/2017

lists

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 265

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 266

133
6/13/2017

SQL> create table PEOPLE


2 (
3 id int,
4 forename varchar2(30),
5 surname varchar2(30),
6 gender varchar2(1)
7 )
8 partition by list (gender)
9 (
10 partition male values ('M'),
11 partition female values ('F')
12 );

Table created.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 267

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 268

134
6/13/2017

SQL> insert into PEOPLE


3 values ( 1,'Connor','McDonald','U');

insert into PEOPLE *

ERROR at line 1:
ORA-14400: inserted partition key does not map to any partition

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 269

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 270

135
6/13/2017

automatic lists

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 271

SQL> create table PEOPLE


2 (
3 id int,
4 forename varchar2(30),
5 surname varchar2(30),
6 gender varchar2(1)
7 )
8 partition by list (gender) automatic
9 (
10 partition male values ('M'),
11 partition female values ('F')
12 );

Table created.
must still be >=1
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 272

136
6/13/2017

SQL> insert into PEOPLE


2 values ( 1,'Connor','McDonald','U');

1 row created.

SQL> select partition_name


2 from user_tab_partitions
3 where table_name = 'PEOPLE';

PARTITION_NAME
-------------------------------------------------
FEMALE
MALE
SYS_P661

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 273

existing tables

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 274

137
6/13/2017

SQL> alter table PEOPLE set partitioning automatic;

Table altered.

SQL> alter table PEOPLE set partitioning manual;

Table altered.

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 275

12
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 276

138
6/13/2017

save the largest for last

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 277

LOBs

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 278

139
6/13/2017

"hold on a minute!"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 279

1997
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 280

140
6/13/2017

securefile LOBs

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 281

"hold on a minute!"

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 282

141
6/13/2017

2007
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 283

LOBs are cool

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 284

142
6/13/2017

compression

de-duplication
securefile LOBs are cooler
encryption
write cache
Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 285

until ...

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 286

143
6/13/2017

n(databases) > 1

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 287

SQL> create table t ( id int, c clob );

Table created.

SQL> insert into t values (1,rpad('x',32000,'x'));

1 row created.

SQL> select *
2 from t;

ID C
---------- --------------------------------------------
1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 288

144
6/13/2017

SQL> select *
2 from t@db11;

ERROR:
ORA-22992: cannot use LOB locators selected from remote tables

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 289

12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 290

145
6/13/2017

SQL> select *
2 from t@db122;

ID C
---------- --------------------------------------------
1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 291

http://docs.oracle.com/database/122/ADLOB/distributed-LOBs.htm

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 292

146
6/13/2017

wrap up

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 293

there's a lot in 12.2

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 294

147
6/13/2017

lots not covered today

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 295

plenty to excite

Copyright 2016, Oracle and/or its affiliates. All rights reserved. | 296

148
6/13/2017

ORA-03113
Connor McDonald

@connor_mc_d

297 Copyright 2016, Oracle and/or its affiliates. All rights reserved. |

149

Das könnte Ihnen auch gefallen