Anda di halaman 1dari 133

4/27/2018

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

1
4/27/2018

Typical speaker ego slide

blog connor-mcdonald.com

youtube tinyurl.com/connor-tube

twitter @connor_mc_d

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

Things you will love about 12.2/18c

Connor McDonald
Developer Advocate

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

2
4/27/2018

"Whoa....hold on!"

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

?
12c, 13, 14, 15, 16, 17, 18c

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

3
4/27/2018

18c = 12.2.0.2

MOS 2285040.1

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

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

4
4/27/2018

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

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

5
4/27/2018

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

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

6
4/27/2018

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

https://asktom.oracle.com
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 14

7
4/27/2018

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

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

8
4/27/2018

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

reality

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

9
4/27/2018

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
4/27/2018

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

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. | 22

11
4/27/2018

you still should be here

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

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

12
4/27/2018

there's a lot in 12.2/18

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
4/27/2018

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
4/27/2018

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
4/27/2018

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
4/27/2018

coming soon

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

install lots :-)

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

17
4/27/2018

gold image service

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

before we get started

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

18
4/27/2018

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 Oracle’s products remains at the sole discretion of Oracle.

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

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

19
4/27/2018

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

test ! Test ! TEST !

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

20
4/27/2018

licensing

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

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

21
4/27/2018

time is short ...

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

asktom.oracle.com
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 44

22
4/27/2018

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

longer names

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

23
4/27/2018

128 bytes

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

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

24
4/27/2018

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. | 49

the ol' days

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

25
4/27/2018

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

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

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. | 52

26
4/27/2018

and...

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

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. | 54

27
4/27/2018

but...

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

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

28
4/27/2018

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 created.
3 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. | 57

have some fun :-)

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

29
4/27/2018

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_power int;
7 begin
8 l_obj := ora_dict_obj_name;
9
10 select count(*)
11 into l_power
12 from dba_role_privs
13 where grantee = user
14 and granted_role = 'SENIOR_DEV';
15
16 if l_power = 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. | 59

SQL> conn junior_dev/junior_dev@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. | 60

30
4/27/2018

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. | 61

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

31
4/27/2018

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

resource control

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

32
4/27/2018

12.1

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

multi tenant

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

33
4/27/2018

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

"seriously ?"

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

34
4/27/2018

DRCP
PL/SQL
SQL

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

DRCP
PL/SQL
SQL

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

35
4/27/2018

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

12.2

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

36
4/27/2018

pdb level controls

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

SQL> exec dbms_random.seed(0);

PL/SQL procedure successfully completed.

SQL> create table t pctfree 99 as


2 select *
3 from ( select rownum r, d.* from dba_objects )
4 order by dbms_random.value;

Table created.

SQL> create index ix on t ( r );

Index created.

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

37
4/27/2018

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

SQL> conn mcdonac/*****@pdb1


SQL> conn mcdonac/*****@pdb2
Connected.
Connected.
SQL> declare
SQL> declare
2 s timestamp;
2 s timestamp;
3 rmax int;
3 rmax int;
4 l_row t%rowtype;
4 l_row t%rowtype;
5 begin
5 begin
6 select max(r) into rmax from t;
6 select max(r) into rmax from t;
7
7
8 s := localtimestamp;
8 s := localtimestamp;
9 for i in 1 .. rmax loop
9 for i in 1 .. rmax loop
10 select * into l_row from t where r = i;
10 select * into l_row from t where r = i;
11 end loop;
11 end loop;
12 dbms_output.put_line(localtimestamp-s);
12 dbms_output.put_line(localtimestamp-s);
13 end;
13 end;
14 /
14 /
+000000000 00:00:15.613076000
+000000000 00:00:15.787332000
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.

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

38
4/27/2018

SQL> conn mcdonac/*****@pdb2


Connected.

SQL> alter system set max_iops = 300;

System altered.

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

SQL> declare
2 s timestamp;
3 rmax int;
4 l_row t%rowtype;
5 begin
6 select max(r) into rmax from t;
7
8 s := localtimestamp;
9 for i in 1 .. rmax loop
10 select * into l_row from t where r = i;
11 end loop;
12 dbms_output.put_line(localtimestamp-s);
13 end;
14 /
+000000000 00:03:58.869568000
PL/SQL procedure successfully completed.

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

39
4/27/2018

SQL> @session_events sid=58

EVENT TOTAL_WAITS TOTAL_TIMEOUTS SECS


-------------------------------------------- ----------- -------------- ----------
Disk file operations I/O 5 0 0
log file sync 2 0 .01
db file scattered read 10 0 .01
db file parallel read 2 0 .01
events in waitclass Other 92 1 .03
db file sequential read 72364 0 12.69
CPU 13.03
resmgr: I/O rate limit 471 0 215.68

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

similar controls for CPU, memory

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

40
4/27/2018

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

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

41
4/27/2018

cloning

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

in 12.1

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

42
4/27/2018

cloning is easy

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

SQL> ALTER PLUGGABLE DATABASE prod CLOSE;

Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE prod OPEN READ ONLY;

Pluggable database altered.

SQL> CREATE PLUGGABLE DATABASE prod_copy FROM prod


2 FILE_NAME_CONVERT=('/u01/oradata/cdb/prod',
3 '/u01/oradata/cdb/prod_copy');

Pluggable database created.

SQL> ALTER PLUGGABLE DATABASE prod_copy OPEN;

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

43
4/27/2018

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

SQL> ALTER PLUGGABLE DATABASE prod CLOSE;

Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE prod OPEN READ ONLY;

Pluggable database altered.

SQL> CREATE PLUGGABLE DATABASE prod_copy FROM prod


2 FILE_NAME_CONVERT=('/u01/oradata/cdb/prod',
3 '/u01/oradata/cdb/prod_copy');

Pluggable database created.

SQL> ALTER PLUGGABLE DATABASE prod_copy OPEN;

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

44
4/27/2018

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

12.2

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

45
4/27/2018

hot cloning is easy

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

SQL> ALTER PLUGGABLE DATABASE prod CLOSE;

Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE prod OPEN READ ONLY;

Pluggable database altered.

SQL> CREATE PLUGGABLE DATABASE prod_copy FROM prod


2 FILE_NAME_CONVERT=('/u01/oradata/cdb/prod',
3 '/u01/oradata/cdb/prod_copy');

Pluggable database created.

SQL> ALTER PLUGGABLE DATABASE prod_copy OPEN;

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

46
4/27/2018

SQL> conn mcdonac/*****@pdb_source


Connected. SQL> create pluggable database pdb_clone from pdb_source
2 file_name_convert=('/u01/cdb/oradata/cdb/pdbs',
SQL> create table T ( x 3int, y timestamp ) '/u01/cdb/oradata/cdb/pdbc');
2 tablespace users;
Pluggable database created.
Table created.
SQL> alter pluggable database pdb_clone open;
SQL> begin
2 for i in 1 .. 300 loop
Pluggable database altered.
3 insert into t values (i, systimestamp );
4 commit; SQL> conn mcdonac/*******@pdb_clone
5 dbms_lock.sleep(0.5);
Connected.
6 end loop; SQL> select * from t;
7 end;
8 / X Y
---------- ---------------------------------
[executing] 1 23-AUG-16 09.28.11.694621 PM
2 23-AUG-16 09.28.12.202435 PM
3 23-AUG-16 09.28.12.702239 PM
4 23-AUG-16 09.28.13.202306 PM
...
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 93

think "hot backup"

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

47
4/27/2018

think "instance recovery"

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

easier with local undo

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

48
4/27/2018

UNDO

sidebar: local undo

UNDO

UNDO UNDO UNDO

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

SQL> startup upgrade

...

SQL> ALTER DATABASE LOCAL UNDO ON;

Database altered.

we'll sort out the rest

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

49
4/27/2018

after the clone

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

SQL> create pluggable database pdb_ro from pdb_source


2 file_name_convert=('/u01/cdb/oradata/cdb/pdbs',
3 '/u01/cdb/oradata/cdb/pdbr');

Pluggable database created.


SQL> conn connor/*****@pdb_source
Connected.
SQL> alter pluggable database pdb_ro open read only;

Pluggable SQL> create table T1 as


SQL> conn database altered.
connor/*****@pdb_ro
2 select * from dba_objects;
Connected.
Table created.
SQL> desc T1
ERROR:
ORA-04043: object T1 does not exist

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

50
4/27/2018

SQL> conn / as sysdba


Connected.

SQL> alter pluggable database pdb_ro refresh


SQL> conn connor/*****@pdb_ro
Table created.
Connected.

SQL> desc T1
Name Null? Type
------------------------------ -------- -------------
OWNER VARCHAR2(128)
OBJECT_NAME VARCHAR2(128)
SUBOBJECT_NAME VARCHAR2(128)
OBJECT_ID NUMBER
DATA_OBJECT_ID NUMBER
...
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 101

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

51
4/27/2018

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

18c

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

52
4/27/2018

per pdb switch/refresh

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

Server1 create pluggable database Grey


from Grey@CDB2_Link
refresh mode auto every 2 minutes;

CDB1

Server2 create pluggable database Red


from Red@CDB1_Link
refresh mode auto every 2 minutes;

CDB2

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

53
4/27/2018

Server1 alter pluggable database refresh


mode auto every 2 minutes from
Grey@dblink switchover;

CDB1 alter pluggable database Grey


open read write;

Server2

CDB2

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

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

54
4/27/2018

QTFWBC

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

queries that finish without bloody crashing

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

55
4/27/2018

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

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

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

56
4/27/2018

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

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

57
4/27/2018

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

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

58
4/27/2018

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. | 117

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. | 118

59
4/27/2018

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

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

60
4/27/2018

and then we do this :-)

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

SQL> select count(*) from MY_TABLE;

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

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

61
4/27/2018

12.2

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

validate_conversion

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

62
4/27/2018

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. | 125

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. | 126

63
4/27/2018

CAST extended

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

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. | 128

64
4/27/2018

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. | 129

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

65
4/27/2018

column level collation

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

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

66
4/27/2018

looks great... until

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

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

67
4/27/2018

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

SQL> select * from customers


2 where upper(cust_name) = 'ADAMS';

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

68
4/27/2018

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

69
4/27/2018

DML slower

more contention

more redo/undo space

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

"not my problem"

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

70
4/27/2018

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

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

71
4/27/2018

12.2

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

column level collation

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

72
4/27/2018

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

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

73
4/27/2018

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. | 148

74
4/27/2018

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. | 150

75
4/27/2018

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
adáms
AUS 09-NOV-16 adams
AUS 10-NOV-16 adáms

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

column | table | user

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

76
4/27/2018

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. | 154

77
4/27/2018

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. | 156

78
4/27/2018

SALES

SALES_PK CUSTOMER SALE_DATE PRODUCT

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

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

79
4/27/2018

yeah... we had a crack at this before

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

SQL> alter index table_pk monitoring usage;

Index altered.

SQL> select index_name, monitoring, used


2 from v$object_usage
3 where index_name = 'TABLE_PK';

INDEX_NAME MON USED


------------ --- ----
TABLE_PK YES NO

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

80
4/27/2018

SQL> select * from table where pk_col = 1;

...

SQL> select index_name, monitoring, used


2 from v$object_usage
3 where index_name = 'TABLE_PK';

INDEX_NAME MON USED


------------ --- ----
TABLE_PK YES YES

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

but ...

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

81
4/27/2018

detection at parse

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

SQL> alter table CHILD


2 add constraint CHILD_FK foreign key (my_col )
3 references PARENT ( my_pk )
4 on delete cascade;

Table altered.

SQL> create index CHILD_FK_IX on CHILD ( my_col );

Index created.

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

82
4/27/2018

SQL> delete from PARENT


2 where my_pk = 1;

1 row deleted.

-------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-------------------------------------------------------
| 0 | DELETE STATEMENT | | 1 | 13 |
| 1 | DELETE | PARENT | | |
|* 2 | INDEX RANGE SCAN| PARENT_PK | 1 | 13 |
-------------------------------------------------------

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

SQL> select index_name, monitoring, used


2 from v$object_usage
3 where index_name = 'CHILD_FK_IX';

INDEX_NAME MON USED


------------ --- ----
TABLE_PK YES NO

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

83
4/27/2018

SQL> drop index CHILD_FK_IX;

Index dropped.

SQL> delete from PARENT


2 where my_pk = 1;

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

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

84
4/27/2018

a fresh (and better) look

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

SQL> desc DBA_INDEX_USAGE

Name Null? Type


----------------------------------- -------- ------------------
OBJECT_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(128)
OWNER NOT NULL VARCHAR2(128)
TOTAL_ACCESS_COUNT NUMBER
TOTAL_EXEC_COUNT NUMBER
TOTAL_ROWS_RETURNED NUMBER
BUCKET_0_ACCESS_COUNT NUMBER
BUCKET_1_ACCESS_COUNT NUMBER
BUCKET_2_10_ACCESS_COUNT NUMBER
BUCKET_2_10_ROWS_RETURNED NUMBER
BUCKET_11_100_ACCESS_COUNT NUMBER
BUCKET_11_100_ROWS_RETURNED NUMBER
BUCKET_101_1000_ACCESS_COUNT NUMBER
BUCKET_101_1000_ROWS_RETURNED NUMBER
BUCKET_1000_PLUS_ACCESS_COUNT NUMBER
BUCKET_1000_PLUS_ROWS_RETURNED NUMBER
LAST_USED DATE

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

85
4/27/2018

SQL> desc DBA_INDEX_USAGE

Name Null? Type


----------------------------------- -------- ------------------
OBJECT_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(128)
OWNER NOT NULL VARCHAR2(128)
TOTAL_ACCESS_COUNT NUMBER
TOTAL_EXEC_COUNT NUMBER
TOTAL_ROWS_RETURNED NUMBER
BUCKET_0_ACCESS_COUNT NUMBER
BUCKET_1_ACCESS_COUNT NUMBER
BUCKET_2_10_ACCESS_COUNT NUMBER
BUCKET_2_10_ROWS_RETURNED NUMBER
BUCKET_11_100_ACCESS_COUNT NUMBER
BUCKET_11_100_ROWS_RETURNED NUMBER
BUCKET_101_1000_ACCESS_COUNT NUMBER
BUCKET_101_1000_ROWS_RETURNED NUMBER
BUCKET_1000_PLUS_ACCESS_COUNT NUMBER
BUCKET_1000_PLUS_ROWS_RETURNED NUMBER
LAST_USED DATE

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

SQL> desc DBA_INDEX_USAGE

Name Null? Type


----------------------------------- -------- ------------------
OBJECT_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(128)
OWNER NOT NULL VARCHAR2(128)
TOTAL_ACCESS_COUNT NUMBER
TOTAL_EXEC_COUNT NUMBER
TOTAL_ROWS_RETURNED NUMBER
BUCKET_0_ACCESS_COUNT NUMBER
BUCKET_1_ACCESS_COUNT NUMBER
BUCKET_2_10_ACCESS_COUNT NUMBER
BUCKET_2_10_ROWS_RETURNED NUMBER
BUCKET_11_100_ACCESS_COUNT NUMBER
BUCKET_11_100_ROWS_RETURNED NUMBER
BUCKET_101_1000_ACCESS_COUNT NUMBER
BUCKET_101_1000_ROWS_RETURNED NUMBER
BUCKET_1000_PLUS_ACCESS_COUNT NUMBER
BUCKET_1000_PLUS_ROWS_RETURNED NUMBER
LAST_USED DATE

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

86
4/27/2018

SQL> select * from DBA_INDEX_USAGE where name = 'CHILD_FK_IX'


2 @pr
==============================
OBJECT_ID : 78909
NAME : CHILD_FK_IX
OWNER : MCDONAC
TOTAL_ACCESS_COUNT : 1078
TOTAL_EXEC_COUNT : 1078
TOTAL_ROWS_RETURNED : 1077
BUCKET_0_ACCESS_COUNT : 1
BUCKET_1_ACCESS_COUNT : 1077
BUCKET_2_10_ACCESS_COUNT : 0
BUCKET_2_10_ROWS_RETURNED : 0
BUCKET_11_100_ACCESS_COUNT : 0
BUCKET_11_100_ROWS_RETURNED : 0
BUCKET_101_1000_ACCESS_COUNT : 0
BUCKET_101_1000_ROWS_RETURNED : 0
BUCKET_1000_PLUS_ACCESS_COUNT : 0
BUCKET_1000_PLUS_ROWS_RETURNED: 0
LAST_USED : 17/08/2016 21:32:51

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

it's about execution

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

87
4/27/2018

help you, not replace you

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

indexes can be involved in...

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

88
4/27/2018

... more than execution

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

SQL> create table t1 as


2 select
3 mod(rownum,50) c1,
4 mod(rownum,50) c2,
5 rownum c3,
6 rownum c4,
7 rownum c5,
8 rpad(rownum,100) c6
9 from dual
10 connect by level <= 10000;

SQL> select count(*) from t1


2 where c1 = 12 and c2 = 12;

COUNT(*)
----------
200

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

89
4/27/2018

SQL> set autotrace traceonly explain

SQL> select *
2 from t
3 where c1 = 12
4 and c2 = 12;

---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 476 | 52 (6)|
|* 1 | TABLE ACCESS FULL| T1 | 4 | 476 | 52 (6)|
---------------------------------------------------------------

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

SQL> create index IX1 on t1 ( c1,c2 );

Index created.

SQL> select *
2 from t
3 where c1 = 12
4 and c2 = 12;

---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 200 | 23800 | 52 (6)|
|* 1 | TABLE ACCESS FULL| T1 | 200 | 23800 | 52 (6)|
---------------------------------------------------------------

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

90
4/27/2018

extended statistics

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

SQL> drop index IX;

Index dropped.

SQL> select dbms_stats.create_extended_stats('','T','(c1,c2)')


2 from dual;

DBMS_STATS.CREATE_EXTENDED_STATS('','T','(C1,C2)')
-------------------------------------------------------------
SYS_STUF3GLKIOP5F4B0BTTCFTMX0W

SQL> begin
2 dbms_stats.gather_table_stats('','T'
3 ,method_opt=>'for all columns size auto');
4 end;
5 /

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

91
4/27/2018

SQL> select *
2 from t
3 where c1 = 12
4 and c2 = 12;

---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 200 | 23800 | 52 (6)|
|* 1 | TABLE ACCESS FULL| T | 200 | 23800 | 52 (6)|
---------------------------------------------------------------

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

help your brain, not replace it

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

92
4/27/2018

so be careful

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

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

93
4/27/2018

security

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

(amazingly)

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

94
4/27/2018

hardware outages ...

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

... aren't a big deal anymore

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

95
4/27/2018

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

what will kill you ...

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

96
4/27/2018

... is getting hacked

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

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

97
4/27/2018

- Connor McDonald

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

security ... ain't easy :-(

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

98
4/27/2018

Check core_dump_dest is valid Audit known default role passwords


Make extproc secure
Secure access to catalog roles
Change sys password Disable remote login password file
Add password management for default accounts Audit utl_file_dir parameter
Audit dbms_backup_restore package permissions Secure ALL_USERS view
Check that global_names is true Stop personal data exposure on users accounts
Use proxy authentication to help resolve SSO issues
Create a role to manage users accounts Remove oo4o if not needed

Use obfuscated naming convention for users accounts Audit users accounts for weak passwords
Check that max_enabled_roles is set correctly
Secure access to dba role views
Change system password
Audit Java access to the OS
Password protect admin roles Check that O7_dictionary_accessibility is set to false

Check user_dump_dest is valid Audit use of IFILE


Lock dormant database accounts and remove after time delay Check use of system tablespace as default
Check that remote_listener is null Check that remote_os_roles is set to false
Review database accounts, ensuring they belong to business users.

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

DBSAT

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

99
4/27/2018

[oracle@host122]$ ./dbsat collect system/****** /tmp/dbsat_collect


...

Connecting to the target Oracle database...

SQL*Plus: Release 12.2.0.1.0 Production on Mon Aug 29 06:16:40 2016

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Last Successful login time: Fri Aug 26 2016 06:58:24 +01:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Setup complete.
SQL queries complete.
OS commands complete.
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit
Production
DBSAT Collector completed successfully.

Calling /u01/app/oracle/product/12.2.0/dbhome_2/bin/zip to encrypt dbsat_collect.json...

Enter password:
Verify password:
adding: dbsat_collect.json (deflated 87%)
zip completed successfully.

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

[oracle@host122 dbsat]$ ./dbsat report /tmp/dbsat_collect


...

Archive: /tmp/dbsat_collect.zip
[/tmp/dbsat_collect.zip] dbsat_collect.json password:
inflating: /tmp/dbsat_collect.json
DBSAT Reporter ran successfully.

Calling /usr/bin/zip to encrypt the generated reports...

Enter password:
Verify password:
adding: dbsat_collect.txt (deflated 78%)
adding: dbsat_collect.html (deflated 83%)
adding: dbsat_collect.xlsx (deflated 3%)
zip completed successfully.

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

100
4/27/2018

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

DBSAT

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

101
4/27/2018

not a typo

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

download from MOS

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

102
4/27/2018

18c

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

better schema management

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

103
4/27/2018

SQL> create user data_owner


2 no authentication;

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

SQL> conn data_owner/random_password

ORA-01017: invalid username/password;


logon denied

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

104
4/27/2018

and finally ....

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

Oracle
Directory Services

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

105
4/27/2018

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

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

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

106
4/27/2018

<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. | 213

{ "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. | 214

107
4/27/2018

12.1

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

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

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

108
4/27/2018

extraction

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

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. | 218

109
4/27/2018

dot notation

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

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. | 220

110
4/27/2018

12.2

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

generation

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

111
4/27/2018

{
"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. |

112
4/27/2018

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

113
4/27/2018

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. | 228

114
4/27/2018

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. | 229

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. | 230

115
4/27/2018

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

one row...

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

116
4/27/2018

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

can really spoil your day :-(

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

117
4/27/2018

SQL> select owner,


2 count(*) as cnt
3 from t
4 where owner like 'S%'
5 group by owner;

SQL> select num_rows


2 from user_tables
3 where table_name = 'T';

NUM_ROWS
-----------
7014272505

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

SQL> create materialized view log on T


2 with rowid (owner,object_id)
3 including new values;

Materialized view log created.

SQL> create materialized view T_MV


2 refresh fast on demand
3 enable query rewrite
4 as
5 select owner,
6 sum(object_id) as sum_obj,
7 count(object_id) as cnt_obj,
8 count(*) as cnt
9 from t
10 group by owner;

Materialized view created.

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

118
4/27/2018

SQL> set autotrace traceonly explain

SQL> select owner, count(*)


2 from t
3 where owner like 'S%'
4 group by owner;

--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 26 | 3 (0)|
|* 1 | MAT_VIEW REWRITE ACCESS FULL| T_MV | 2 | 26 | 3 (0)|
--------------------------------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------

1 - filter("T_MV"."OWNER" LIKE 'S%')

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

hero

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

119
4/27/2018

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

until ...

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

120
4/27/2018

SQL> insert into t


2 values ( ... , ... , ..., ..... );

1 row created.

SQL> commit;

Commit complete.

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

SQL> select owner, count(*)


2 from t
3 where owner like 'S%'
4 group by owner;

----------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 10 | 14M (1)|
| 1 | HASH GROUP BY | | 2 | 10 | 14M (1)|
|* 2 | TABLE ACCESS FULL| T | 574M| 2738M| 14M (1)|
----------------------------------------------------------------

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

121
4/27/2018

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

SQL> create or replace


2 procedure KILL_MY_CPU_MIXED_WITH_PRAYER is
3 begin
4 loop
5 dbms_mview.refresh('T_MV');
6 end loop;
7 end;
8 /

Procedure created.

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

122
4/27/2018

12.2

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

real time refresh

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

123
4/27/2018

on commit

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

SQL> create materialized view T_MV


2 refresh fast on demand
3 enable query rewrite
4 enable on query computation
5 as
6 select owner,
7 sum(object_id) as sum_obj,
8 count(object_id) as cnt_obj,
9 count(*) as cnt
10 from t
11 group by owner;

Materialized view created.

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

124
4/27/2018

SQL> set autotrace traceonly explain

SQL> select owner, count(*)


2 from t
3 where owner like 'S%'
4 group by owner;

---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 26 | 3 (0)|
|* 1 | MAT_VIEW REWRITE ACCESS FULL| T_MV | 2 | 26 | 3 (0)|
---------------------------------------------------------------------------

as before

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

SQL> insert into t


2 values ( ... , ... , ..., ..... );

1 row created.

SQL> commit;

Commit complete.

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

125
4/27/2018

SQL> select owner, count(*) cnt


2 from t
3 where owner like 'S%'
4 group by owner;

OWNER CNT
------------------------------ ----------
SYS 50941
SI_INFORMTN_SCHEMA 8
SQL> select /*+ NO_REWRITE */ owner, count(*) cnt
SYSTEM 2 from t 482
3 where owner like 'S%'
Elapsed: 00:00:01.41 4 group by owner;

OWNER CNT
------------------------------ ----------
SYS 50941
SYSTEM 482
SI_INFORMTN_SCHEMA 8

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

how ?

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

126
4/27/2018

SQL> select owner, count(*) as cnt


2 from t
3 where owner like 'S%'
4 group by owner;

OWNER CNT
------------------------------ ----------
SYS 50941
SI_INFORMTN_SCHEMA 8
SYSTEM 482

we didn't refresh the mview


SQL> select owner, cnt
2 from T_MV
3 where owner like 'S%';

OWNER CNT
------------------------------ ----------
SYS 50940
SYSTEM 482
SI_INFORMTN_SCHEMA 8

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

SQL> set autotrace traceonly explain

SQL> select owner,


2 count(*) as cnt
3 from t
4 where owner like 'S%'
5 group by owner;

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

127
4/27/2018

-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 316 | 15 (20)|
| 1 | VIEW | | 4 | 316 | 15 (20)|
| 2 | UNION-ALL | | | | |
|* 3 | FILTER | | | | |
|* 4 | HASH JOIN OUTER | | 2 | 184 | 6 (17)|
|* 5 | MAT_VIEW ACCESS FULL | T_MV | 2 | 46 | 2 (0)|
| 6 | VIEW | | 1 | 69 | 4 (25)|
| 7 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 8 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
| 9 | VIEW | | 2 | 158 | 9 (23)|
| 10 | UNION-ALL | | | | |
|* 11 | FILTER | | | | |
| 12 | NESTED LOOPS OUTER | | 1 | 102 | 4 (25)|
| 13 | VIEW | | 1 | 79 | 4 (25)|
|* 14 | FILTER | | | | |
| 15 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 16 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 17 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | 23 | 0 (0)|
| 18 | NESTED LOOPS | | 1 | 105 | 5 (20)|
| 19 | VIEW | | 1 | 82 | 4 (25)|
| 20 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 21 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 22 | MAT_VIEW ACCESS BY INDEX ROWID| T_MV | 1 | 23 | 1 (0)|
|* 23 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | | 0 (0)|
-----------------------------------------------------------------------------------------

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

what about direct queries ?

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

128
4/27/2018

SQL> select /*+ FRESH_MV


owner, cnt */ owner, cnt
2 from T_MV
3 where owner like 'S%';

OWNER CNT
------------------------------ ----------
SYSTEM 482
SYS 50941
50940
SI_INFORMTN_SCHEMA 8

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

wrap up

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

129
4/27/2018

there's a lot in 12.2/18

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

lots not covered today

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

130
4/27/2018

plenty to excite

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

oh .. nearly forgot

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

131
4/27/2018

18c XE !!!

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

never too soon to start

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

132
4/27/2018

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

Thanks for your time

blog connor-mcdonald.com

youtube tinyurl.com/connor-tube

twitter @connor_mc_d

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

133