SlideShare ist ein Scribd-Unternehmen logo
1 von 279
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 1
SQL> select sample_font
2 from dual ;
Can you read this ?
Note: Small fonts in this presentation
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 4
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 5
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 6https://www.youtube.com/c/ConnorMcDonaldOracle
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 7
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
bio
8
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
make you more successful with Oracle
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
SQL-lectric !!!
Connor McDonald
Developer Advocate for SQL
2016
Oracle Confidential –
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
why talk about SQL
(reason 1)
12
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
People are (re)learning...
13
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
...SQL is pretty important
14
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
“….the complexity of dealing with a
non-ACID data store in every part of
our business logic would be too
great, and there was simply no way
our business could function without
SQL queries.”
Google, VLDB 2013
“[Facebook] started in the Hadoop
world. We are now bringing in
relational to enhance that. ... [we]
realized that using the wrong
technology for certain kinds of
problems can be difficult.”
Ken Rudin, Facebook, TDWI 2013
15
http://tdwi.org/articles/2013/05/06/facebooks-relational-platform.aspxhttps://www.linkedin.com/groups/Find-out-why-Google-decided-4434815.S.273792742
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
why talk about SQL
(reason 2)
16
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
why talk about SQL
(reason 3)
19
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
we all want to be cool 
20
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"microservices"
21
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"simple function"
22
"insulated data access"
"test in isolation"
SQL> SELECT sal
2 FROM EMP
3 WHERE EMPNO = 12
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
its all about the SQL
23
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 24
this session
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 25
my favourites
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 26
strong focus on 12c
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Favourite:
subquery factoring
27
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
WITH clause
28
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> WITH last_hire AS
2 ( select deptno, max(hiredate)
3 from emp
4 group by deptno
5 )
6 select * from last_hire;
DEPTNO MAX(HIRED
---------- ---------
30 03-DEC-81
20 12-JAN-83
10 23-JAN-82
29
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"gee.......wow"
30
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
why is it cool ?
31
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
good solution metaphor
32
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
here's the problem
33
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
we're awful at set theory....
34
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
...set theory is awful 
35
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
not our fault
36
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Codd & Date
37
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"data is represented as mathematical n-ary relations, an n-ary
relation being a subset of the Cartesian product of n domains."
38
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 39
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
humans are procedural
40
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
business analysts...
procedural analysis
41
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
technical analysts...
procedural specifications
42
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
programmers
procedural programs
43
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
procedural
44
relational
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
good solution metaphor
45
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"First, get the total salary paid by department...
SQL> WITH dept_salaries AS (
2 SELECT dname, SUM(sal) dept_sal
3 FROM emp e, dept d
4 WHERE e.deptno = d.deptno
5 GROUP BY dname),
46
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"...then get the average of these totals...
6 avg_sal AS ( SELECT AVG(dept_sal) avsal
7 FROM dept_salaries)
47
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"...then list those departments above average."
8 SELECT * FROM dept_salaries d, avg_sal a
9 WHERE d.dept_sal > a.avsal
10 ORDER BY d.dname;
48
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> WITH dept_salaries AS (
2 SELECT dname, SUM(sal) dept_sal
3 FROM emp e, dept d
4 WHERE e.deptno = d.deptno
5 GROUP BY dname),
6 avg_sal AS ( SELECT AVG(dept_sal) avsal
7 FROM dept_salaries)
8 SELECT * FROM dept_salaries d, avg_sal a
9 WHERE d.dept_sal > a.avsal
10 ORDER BY d.dname;
49
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
procedural approach....
50
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
...set based solution
51
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
things to note...
52
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
execution plan
53
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
two possibilities
54
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
temporary storage
55
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
----------------------------------------------------------------------
| Id | Operation | Name |
----------------------------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | TEMP TABLE TRANSFORMATION | |
| 2 | LOAD AS SELECT | |
| 3 | HASH GROUP BY | |
| 4 | MERGE JOIN | |
| 5 | TABLE ACCESS BY INDEX ROWID| DEPT |
| 6 | INDEX FULL SCAN | PK_DEPT |
| 7 | SORT JOIN | |
| 8 | TABLE ACCESS FULL | EMP |
| 9 | SORT ORDER BY | |
| 10 | NESTED LOOPS | |
| 11 | VIEW | |
| 12 | SORT AGGREGATE | |
| 13 | VIEW | |
| 14 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6624_AF422F5 |
| 15 | VIEW | |
| 16 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6624_AF422F5 |
----------------------------------------------------------------------
56
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> alter session set sql_trace = true;
Session altered.
SQL> WITH dept_salaries AS (
2 SELECT dname, SUM(sal) dept_sal
3 FROM emp e, dept d
4 WHERE e.deptno = d.deptno
5 GROUP BY dname),
6 avg_sal AS ( SELECT AVG(dept_sal) asal
7 FROM dept_salaries)
8 SELECT * FROM dept_salaries d, avg_sal a
9 WHERE d.dept_sal > a.asal
10 ORDER BY d.dname;
DNAME DEPT_SAL ASAL
-------------- ---------- ----------
RESEARCH 21750 19350
SQL> alter session set sql_trace = false;
Session altered.
57
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
PARSING IN CURSOR #12 len=179 dep=1 uid=0 oct=1...
CREATE GLOBAL TEMPORARY
TABLE "SYS"."SYS_TEMP_0FD9D6625_AF422F5"
("C0" VARCHAR2(14),"C1" NUMBER )
IN_MEMORY_METADATA CURSOR_SPECIFIC_SEGMENT
STORAGE (OBJNO 4254950949 ) NOPARALLEL
END OF STMT
58
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
no temporary storage
59
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
------------------------------------------------------
| Id | Operation | Name |
------------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
| 2 | NESTED LOOPS | |
| 3 | VIEW | |
| 4 | SORT AGGREGATE | |
| 5 | VIEW | |
| 6 | HASH GROUP BY | |
| 7 | MERGE JOIN | |
| 8 | TABLE ACCESS BY INDEX ROWID| DEPT |
| 9 | INDEX FULL SCAN | PK_DEPT |
| 10 | SORT JOIN | |
| 11 | TABLE ACCESS FULL | EMP |
| 12 | VIEW | |
| 13 | SORT GROUP BY | |
| 14 | MERGE JOIN | |
| 15 | TABLE ACCESS BY INDEX ROWID | DEPT |
| 16 | INDEX FULL SCAN | PK_DEPT |
| 17 | SORT JOIN | |
| 18 | TABLE ACCESS FULL | EMP |
------------------------------------------------------
60
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
explicit control
61
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> WITH dept_salaries AS (
2 SELECT /*+ INLINE */ dname, SUM(sal) dept_sal
3 FROM emp e, dept d
4 WHERE e.deptno = d.deptno
5 GROUP BY dname),
6 avg_sal AS ( SELECT AVG(dept_sal) asal
7 FROM dept_salaries)
8 SELECT * FROM dept_salaries d, avg_sal a
9 WHERE d.dept_sal > a.asal
10 ORDER BY d.dname;
62
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> WITH dept_salaries AS (
2 SELECT /*+ MATERIALIZE*/ dname, SUM(sal) dept_sal
3 FROM emp e, dept d
4 WHERE e.deptno = d.deptno
5 GROUP BY dname),
6 avg_sal AS ( SELECT AVG(dept_sal) asal
7 FROM dept_salaries)
8 SELECT * FROM dept_salaries d, avg_sal a
9 WHERE d.dept_sal > a.asal
10 ORDER BY d.dname;
63
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
undocumented .... sort of
64
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
useful control over optimizer
65
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
useful control over database links
66
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
... more on WITH later
67
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Favourite:
temporal validity
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
very common
70
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
when is a row "valid"
71
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> CREATE TABLE emp_temporal (
2 empno NUMBER,
3 name VARCHAR2(30),
4 sal NUMBER,
5 deptno NUMBER,
6 start_dt DATE,
7 end_dt DATE,
8
9 );
Table created.
72
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
12c - part of the definition
73
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> CREATE TABLE emp_temporal (
2 empno NUMBER,
3 name VARCHAR2(30),
4 sal NUMBER,
5 deptno NUMBER,
6 start_dt DATE,
7 end_dt DATE,
8 PERIOD FOR valid_range (start_dt, end_dt)
9 );
Table created.
74
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
examples
75
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select * from emp_temporal
2 order by empno, start_dt;
EMPNO NAME SAL DEPTNO START_DT END_DT
---------- ------------ ---------- ---------- --------- ---------
7369 SMITH 806 20 01-JAN-14 01-MAR-14
7369 SMITHX 8060 21 02-MAR-14 01-OCT-14
7499 ALLEN 1606 30 01-JAN-14 01-MAR-14
7499 ALLENX 16060 31 02-MAR-14 01-OCT-14
7521 WARD 1256 30 01-JAN-14 01-MAR-14
7521 WARDX 12560 31 02-MAR-14 01-OCT-14
7566 JONES 2981 20 01-JAN-14 01-MAR-14
7566 JONESX 29810 21 02-MAR-14 01-OCT-14
7654 MARTIN 1256 30 01-JAN-14 01-MAR-14
7654 MARTINX 12560 31 02-MAR-14 01-OCT-14
7698 BLAKE 2856 30 01-JAN-14 01-MAR-14
76
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select * from emp_temporal
2 as of period for valid_range '01-FEB-14';
EMPNO NAME SAL DEPTNO START_DT END_DT
---------- ------------ ---------- ---------- --------- ---------
7369 SMITH 806 20 01-JAN-14 01-MAR-14
7499 ALLEN 1606 30 01-JAN-14 01-MAR-14
7521 WARD 1256 30 01-JAN-14 01-MAR-14
7566 JONES 2981 20 01-JAN-14 01-MAR-14
7654 MARTIN 1256 30 01-JAN-14 01-MAR-14
77
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
so what's happening ?
78
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
a slight digression
79
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Favourite:
query expansion
80
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 81
SQL> set autotrace traceonly stat
SQL> select * from MY_STUFF
2 where CREATED > sysdate
Statistics
------------------------------------------
651 recursive calls
0 db block gets
2243 consistent gets
24 physical reads
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 82
SQL> variable c clob
SQL> begin
2 dbms_utility.expand_sql_text
3 ( 'select * from MY_STUFF'||
4 'where created > sysdate',:c);
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> print c
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 83
SQL> create or replace
2 view MY_STUFF as
3 select
4 o.owner,
5 o.created,
6 s.bytes,
7 s.tablespace_name
8 from
9 dba_segments s,
10 all_objects o
11 where o.owner = s.owner
12 and o.object_name = s.segment_name;
View created.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 84
SELECT "A1"."OWNER" "OWNER",
"A1"."NAME" "NAME",
"A1"."CREATED" "CREATED",
"A1"."BYTES" "BYTES",
"A1"."TABLESPACE_NAME" "TABLESPACE_NAME"
FROM (SELECT "A2"."OWNER" "OWNER",
"A2"."OBJECT_NAME" "NAME",
"A2"."CREATED" "CREATED",
"A3"."BYTES" "BYTES",
"A3"."TABLESPACE_NAME" "TABLESPACE_NAME" FROM (SELECT "A4"
."OWNER" "OWNER",
"A4"."SEGMENT_NAME" "SEGMENT_NAME",
"A4"."PARTITION_NAME" "PARTITION_NAME",
"A4"."SEGMENT_TYPE" "SEGMENT_TYPE",
"A4"."SEGMENT_SUBTYPE" "SEGMENT_SUBTYPE",
"A4"."TABLESPACE_NAME" "TABLESPACE_NAME",
"A4"."HEADER_FILE" "HEADER_FILE",
"A4"."HEADER_BLOCK" "HEADER_BLOCK",
DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072,
"A4"."BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1,
"SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_BLOCKS"("A4"."TABLESPACE_ID",
"A4"."RELATIVE_FNO",
"A4"."HEADER_BLOCK",
"A4"."SEGMENT_TYPE_ID",
"A4"."BUFFER_POOL_ID",
"A4"."SEGMENT_FLAGS",
"A4"."SEGMENT_OBJD",
"A4"."BLOCKS"),
"A4"."BLOCKS"))*"A4"."BLOCKSIZE" "BYTES",
DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072,
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 85
"A4"."HEADER_BLOCK",
"A4"."SEGMENT_TYPE_ID",
"A4"."BUFFER_POOL_ID",
"A4"."SEGMENT_FLAGS",
"A4"."SEGMENT_OBJD",
"A4"."BLOCKS"),
"A4"."BLOCKS")) "BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072,
"A4"."EXTENTS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1,
"SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_EXTENTS"("A4"."TABLESPACE_ID",
"A4"."RELATIVE_FNO",
"A4"."HEADER_BLOCK",
"A4"."SEGMENT_TYPE_ID",
"A4"."BUFFER_POOL_ID",
"A4"."SEGMENT_FLAGS",
"A4"."SEGMENT_OBJD",
"A4"."EXTENTS"),
"A4"."EXTENTS")) "EXTENTS",
"A4"."INITIAL_EXTENT" "INITIAL_EXTENT",
"A4"."NEXT_EXTENT" "NEXT_EXTENT",
"A4"."MIN_EXTENTS" "MIN_EXTENTS",
"A4"."MAX_EXTENTS" "MAX_EXTENTS",
"A4"."MAX_SIZE" "MAX_SIZE",
"A4"."RETENTION" "RETENTION",
"A4"."MINRETENTION" "MINRETENTION",
"A4"."PCT_INCREASE" "PCT_INCREASE",
"A4"."FREELISTS" "FREELISTS",
"A4"."FREELIST_GROUPS" "FREELIST_GROUPS",
"A4"."RELATIVE_FNO" "RELATIVE_FNO",
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 86
"A198"."SUBNAME" "PARTITION_NAME",
"A196"."OBJECT_TYPE" "SEGMENT_TYPE",
"A195"."TYPE#" "SEGMENT_TYPE_ID",DECODE(BIT
AND("A195"."SPARE1",2097408),2097152,'SECUREFILE',256,'ASSM','MSSM')
"SEGMENT_SUBTYPE",
"A197"."TS#" "TABLESPACE_ID",
"A197"."NAME" "TABLESPACE_NAME",
"A197"."BLOCKSIZE" "BLOCKSIZE",
"A194"."FILE#" "HEADER_FILE",
"A195"."BLOCK#" "HEADER_BLOCK",
"A195"."BLOCKS"*"A197"."BLOCKSIZE" "BYTES",
"A195"."BLOCKS" "BLOCKS",
"A195"."EXTENTS" "EXTENTS",
"A195"."INIEXTS"*"A197"."BLOCKSIZE" "INITIAL_EXTENT",
"A195"."EXTSIZE"*"A197"."BLOCKSIZE" "NEXT_EXTENT",
"A195"."MINEXTS" "MIN_EXTENTS",
"A195"."MAXEXTS"
"MAX_EXTENTS",DECODE(BITAND("A195"."SPARE1",4194304),4194304,
"A195"."BITMAPRANGES",NULL) "MAX_SIZE",TO_CHAR(DECODE(
BITAND("A195"."SPARE1",2097152),2097152,
DECODE("A195"."LISTS",0,'NONE',1,'AUTO',2,'MIN',3,'MAX',4,'DEFAULT','INVALID'
),NULL))
"RETENTION",DECODE(BITAND("A195"."SPARE1",2097152),2097152,
"A195"."GROUPS",NULL)
"MINRETENTION",DECODE(BITAND("A197"."FLAGS",3),1,TO_NUMBER(NULL),
"A195"."EXTPCT") "PCT_INCREASE",DECODE(BITAND("A197"."FLAGS",32),32,
TO_NUMBER(NULL),DECODE("A195"."LISTS",0,1,
"A195"."LISTS"))
"FREELISTS",DECODE(BITAND("A197"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A195"
."GROUPS",0,1,
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 87
DECODE(BITAND("A209"."PROPERTY",8192),8192,'NESTED TABLE','TABLE')
"OBJECT_TYPE",
2 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID",
"A209"."OBJ#" "OBJECT_ID",
"A209"."FILE#" "HEADER_FILE",
"A209"."BLOCK#" "HEADER_BLOCK",
"A209"."TS#" "TS_NUMBER" FROM "SYS"."TAB$" "A209" WHERE
BITAND("A209"."PROPERTY",1024)=0) UNI
ON ALL (SELECT 'TABLE PARTITION' "OBJECT_TYPE",19 "OBJECT_TYPE_ID",5
"SEGMENT_TYPE_ID",
"A208"."OBJ#" "OBJECT_ID",
"A208"."FILE#" "HEADER_FILE",
"A208"."BLOCK#" "HEADER_BLOCK",
"A208"."TS#" "TS_NUMBER" FROM "SYS"."TABPART$" "A208") UNION ALL
(SELECT 'CLUSTER' "OBJECT_TYPE",3 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID",
"A207"."OBJ#" "OBJECT_ID",
"A207"."FILE#" "HEADER_FILE",
"A207"."BLOCK#" "HEADER_BLOCK",
"A207"."TS#" "TS_NUMBER" FROM "SYS"."CLU$" "A207") UNION ALL
(SELECT DECODE("A206"."TYPE#",8,'LOBINDEX','INDEX') "OBJECT_TYPE",1
"OBJECT_TYPE_ID",6 "SEGMENT_TYPE_ID",
"A206"."OBJ#" "OBJECT_ID",
"A206"."FILE#" "HEADER_FILE",
"A206"."BLOCK#" "HEADER_BLOCK",
"A206"."TS#" "TS_NUMBER" FROM "SYS"."IND$" "A206" WHERE "A206"."TYPE#"=1 OR
"A206"."TYPE#"=2 OR
"A206"."TYPE#"=3 OR
"A206"."TYPE#"=4 OR
"A206"."TYPE#"=6 OR
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 88
"A205"."TS#" "TS_NUMBER" FROM "SYS"."INDPART$" "A205") UNION ALL
(SELECT 'LOBSEGMENT' "OBJECT_TYPE",21 "OBJECT_TYPE_ID",8 "SEGMENT_TYPE_ID",
"A204"."LOBJ#" "OBJECT_ID",
"A204"."FILE#" "HEADER_FILE",
"A204"."BLOCK#" "HEADER_BLOCK",
"A204"."TS#" "TS_NUMBER" FROM "SYS"."LOB$" "A204" WHERE
BITAND("A204"."PROPERTY",64)=0 OR
BITAND("A204"."PROPERTY",128)=128) UNION ALL
(SELECT 'TABLE SUBPARTITION' "OBJECT_TYPE",34 "OBJECT_TYPE_ID",5
"SEGMENT_TYPE_ID",
"A203"."OBJ#" "OBJECT_ID",
"A203"."FILE#" "HEADER_FILE",
"A203"."BLOCK#" "HEADER_BLOCK",
"A203"."TS#" "TS_NUMBER" FROM "SYS"."TABSUBPART$" "A203") UNION ALL
(SELECT 'INDEX SUBPARTITION' "OBJECT_TYPE",35 "OBJECT_TYPE_ID",6
"SEGMENT_TYPE_ID",
"A202"."OBJ#" "OBJECT_ID",
"A202"."FILE#" "HEADER_FILE",
"A202"."BLOCK#" "HEADER_BLOCK",
"A202"."TS#" "TS_NUMBER" FROM "SYS"."INDSUBPART$" "A202") UNION ALL
(SELECT DECODE("A201"."FRAGTYPE$",'P','LOB PARTITION','LOB SUBPARTITION')
"OBJECT_TYPE",DECODE("A201"."FRAGTYPE$",'P',40,41) "OBJECT_TYPE_ID",8
"SEGMENT_TYPE_ID",
"A201"."FRAGOBJ#" "OBJECT_ID",
"A201"."FILE#" "HEADER_FILE",
"A201"."BLOCK#" "HEADER_BLOCK",
"A201"."TS#" "TS_NUMBER" FROM "SYS"."LOBFRAG$" "A201")) "A196",
"SYS"."SEG$" "A195",
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 89
"A195"."FILE#"="A194"."RELFILE#") UNION ALL
(SELECT NVL("A193"."NAME",'SYS') "OWNER",
"A191"."NAME" "SEGMENT_NAME",NULL "PARTITION_NAME",
DECODE("A190"."TYPE#",1,'ROLLBACK',10,'TYPE2 UNDO') "SEGMENT_TYPE",
"A190"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE",
"A192"."TS#" "TABLESPACE_ID",
"A192"."NAME" "TABLESPACE_NAME",
"A192"."BLOCKSIZE" "BLOCKSIZE",
"A189"."FILE#" "HEADER_FILE",
"A190"."BLOCK#" "HEADER_BLOCK",
"A190"."BLOCKS"*"A192"."BLOCKSIZE" "BYTES",
"A190"."BLOCKS" "BLOCKS",
"A190"."EXTENTS" "EXTENTS",
"A190"."INIEXTS"*"A192"."BLOCKSIZE" "INITIAL_EXTENT",
"A190"."EXTSIZE"*"A192"."BLOCKSIZE" "NEXT_EXTENT",
"A190"."MINEXTS" "MIN_EXTENTS",
"A190"."MAXEXTS"
"MAX_EXTENTS",DECODE(BITAND("A190"."SPARE1",4194304),4194304,
"A190"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL "MINRETENTION",
"A190"."EXTPCT"
"PCT_INCREASE",DECODE(BITAND("A192"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A1
90"."LISTS",0,1,
"A190"."LISTS"))
"FREELISTS",DECODE(BITAND("A192"."FLAGS",32),32,TO_NUMBER(NULL),
DECODE("A190"."GROUPS",0,1,"A190"."GROUPS")) "FREELIST_GROUPS",
"A190"."FILE#" "RELATIVE_FNO",BITAND("A190"."CACHEHINT",3)
"BUFFER_POOL_ID",BITAND("A190"."CACHEHINT",12)/4 "FLASH_CACHE",
BITAND("A190"."CACHEHINT",48)/16 "CELL_FLASH_CACHE",NVL("A190"."SPARE1",0)
"SEGMENT_FLAGS",
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 90
"A191"."TS#"="A189"."TS#" AND
"A191"."FILE#"="A189"."RELFILE#") UNION ALL
(SELECT NVL("A188"."NAME",'SYS') "OWNER",
TO_CHAR("A185"."FILE#")||'.'||TO_CHAR("A186"."BLOCK#") "SEGMENT_NAME",NULL
"PARTITION_NAME",
DECODE("A186"."TYPE#",2,'DEFERRED ROLLBACK',3,
'TEMPORARY',4,'CACHE',9,'SPACE HEADER','UNDEFINED') "SEGMENT_TYPE",
"A186"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE",
"A187"."TS#" "TABLESPACE_ID",
"A187"."NAME" "TABLESPACE_NAME",
"A187"."BLOCKSIZE" "BLOCKSIZE",
"A185"."FILE#" "HEADER_FILE",
"A186"."BLOCK#" "HEADER_BLOCK",
"A186"."BLOCKS"*"A187"."BLOCKSIZE" "BYTES",
"A186"."BLOCKS" "BLOCKS",
"A186"."EXTENTS" "EXTENTS",
"A186"."INIEXTS"*"A187"."BLOCKSIZE" "INITIAL_EXTENT",
"A186"."EXTSIZE"*"A187"."BLOCKSIZE" "NEXT_EXTENT",
"A186"."MINEXTS" "MIN_EXTENTS",
"A186"."MAXEXTS"
"MAX_EXTENTS",DECODE(BITAND("A186"."SPARE1",4194304),4194304,
"A186"."BITMAPRANGES",NULL) "MAX_SIZE",NULL
"RETENTION",NULL
"MINRETENTION",DECODE(BITAND("A187"."FLAGS",3),1,TO_NUMBER(NULL),
"A186"."EXTPCT")
"PCT_INCREASE",DECODE(BITAND("A187"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A1
86"."LISTS",0,1,
"A186"."LISTS"))
"FREELISTS",DECODE(BITAND("A187"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A186"
."GROUPS",0,1,
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 91
"A186"."TYPE#"<>6 AND
"A186"."TYPE#"<>8 AND
"A186"."TYPE#"<>10 AND
"A186"."TYPE#"<>11 AND
"A186"."TS#"="A185"."TS#"
AND
"A186"."FILE#"="A185"."RELFILE#") UNION ALL
(SELECT NVL("A184"."NAME",'SYS') "OWNER",'HEATMAP' "SEGMENT_NAME",
NULL "PARTITION_NAME",'SYSTEM STATISTICS' "SEGMENT_TYPE",
"A182"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE",
"A183"."TS#" "TABLESPACE_ID",
"A183"."NAME" "TABLESPACE_NAME",
"A183"."BLO
CKSIZE" "BLOCKSIZE",
"A181"."FILE#" "HEADER_FILE",
"A182"."BLOCK#" "HEADER_BLOCK",
"A182"."BLOCKS"*"A183"."BLOCKSIZE" "BYTES",
"A182"."BLOCKS" "BLOCKS",
"A182"."EXTENTS" "EXTENTS",
"A182"."INIEXTS"*"A183"."BLOCKSIZE" "INITIAL_EXTENT",
"A182"."EXTSIZE"*"A183"."BLOCKSIZE" "NEXT_EXTENT",
"A182"."MINEXTS" "MIN_EXTENTS",
"A182"."MAXEXTS"
"MAX_EXTENTS",DECODE(BITAND("A182"."SPARE1",4194304),4194304,
"A182"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL
"MINRETENTION",DECODE(BITAND("A183"."FLAGS",3),1,TO_NUMBER(NULL),
"A182"."EXTPCT")
"PCT_INCREASE",DECODE(BITAND("A183"."FLAGS",32),32,TO_NUMBER(NULL),DEC
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 92
"SYS"."TS$" "A183",
"SYS"."SEG$" "A182",
"SYS"."FILE$" "A181" WHERE "A182"."TS#"="A183"."TS#" AND
"A182"."USER#"="A184"."USER#"(+) AND
"A182"."TYPE#"=11 AND
"A182"."TS#"="A181"."TS#" AND
"A182"."FILE#"="A181"."RELFILE#")) "A4") "A3", (SELECT "A5"."NAME" "OWNER",
"A6"."NAME" "OBJECT_NAME",
"A6"."SUBNAME" "SUBOBJECT_NAME",
"A6"."OBJ#" "OBJECT_ID",
"A6"."DATAOBJ#" "DATA_OBJECT_ID",DECODE("A6"."TYPE#",0,'NEXT OBJECT',1,'INDEX',
2,'TABLE',3,'CLUSTER',4,'VIEW',5,'SYNONYM
',6,'SEQUENCE',7,'PROCEDURE',8,'FUNCTION',9,'PACKAGE',11,'PACKAGE BODY',12,
'TRIGGER',13,'TYPE',14,'TYPE BODY',19,'TABLE PARTITION',20,'INDEX PARTITION',
21,'LOB',22,'LIBRARY',23,'DIRECTORY',24,'QUEUE',28,'JAVA SOURCE',29,'JAVA CLASS',30,
'JAVA RESOURCE',32,'INDEXTYPE',33,'OPERATOR',34,
'TABLE SUBPARTITION',35,'INDEX SUBPARTITION',40,'LOB PARTITION',41,'LOB SUBPARTITION',42
,NVL( (SELECT 'REWRITE EQUIVALENCE' "'REWRITEEQUIVALENCE'" FROM SYS."SUM$" "A52" WHERE
"A52"."OBJ#"="A6"."OBJ#" AND
BITAND("A52"."XPFLAGS",8388608)=8388608),'MATERIALIZED VIEW'),43,'DIMENSION',
44,'CONTEXT',46,'RULE SET',47,'RESOURCE PLAN',48,'CONSUMER GROUP',55,'XML SCHEMA',56,'JAVA
DATA',57,'EDITION',59,'RULE',
60,'CAPTURE',61,'APPLY',62,'EVALUATION CONTEXT',66,'JOB',67,'PROGRAM',68,'JOB CLASS',69,
'WINDOW',72,'SCHEDULER GROUP',74,'SCHEDULE',79,'CHAIN',81,'FILE GROUP',82,'MINING
MODEL',87,'ASSEMBLY',90,'CREDENTIAL',92,'CUBE
DIMENSION',93,'CUBE',94,'MEASURE FOLDER',95,'CUBE BUILD PROCESS',100,'FILE WATCHER',
101,'DESTINATION',114,'SQL TRANSLATION PROFILE',115,'UNIFIED AUDIT POLICY','UNDEFINED')
"OBJECT_TYPE",
"A6"."CTIME" "CREATED",
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
16 ...
93
more
pages
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
back to temporal validity
94
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> variable c clob
SQL> begin
2 dbms_utility.expand_sql_text(
3 q'{select * from emp_temporal
4 as of period for valid_range '01-FEB-14'}',:c);
6 end;
7 /
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> print c
C
------------------------------------------------
SELECT
"A1"."EMPNO"
...
FROM (
SELECT "A2"."EMPNO" "EMPNO",
"A2"."NAME"
FROM "SCOTT"."EMP_TEMPORAL" "A2"
WHERE ("A2"."START_DT" IS NULL
OR "A2"."START_DT"<='01-FEB-14')
AND ("A2"."END_DT" IS NULL
OR "A2"."END_DT">'01-FEB-14')
) "A1"
96
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
existing tables
97
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> desc EMPLOYEE
Name Null? Type
------------------------- -------- ---------------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(12,2)
DEPTNO NUMBER(2)
SQL> alter table EMPLOYEE add period for TIME_RANGE;
Table altered.
98
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> desc EMPLOYEE
Name Null? Type
------------------------- -------- ---------------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(12,2)
DEPTNO NUMBER(2)
still looks the same ?
99
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select column_name , hidden_column
2 from USER_TAB_COLS
3 where table_name = 'EMPLOYEE'
4 order by column_id;
COLUMN_NAME HIDDEN_COLUMN
------------------------------ -------------
EMPNO NO
ENAME NO
JOB NO
MGR NO
HIREDATE NO
SAL NO
COMM NO
DEPTNO NO
TIME_RANGE_START YES
TIME_RANGE_END YES
TIME_RANGE YES
100
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
multi temporal validity
101
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> alter table EMP_TEMPORAL add period for CAL_RANGE;
Table altered.
SQL> alter table EMP_TEMPORAL add period for FINYR_RANGE;
Table altered.
102
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"room to grow"
103
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
no temporal constraints
104
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> alter table EMP_TEMPORAL add primary key (empno);
Table altered.
SQL> insert into EMP_TEMPORAL
2 (empno, name, start_dt, end_dt )
3 values (20,'BROWN', '01-FEB-14','01-MAR-14');
1 row created.
SQL> insert into EMP_TEMPORAL
2 (empno, name, start_dt, end_dt )
3 values (20,'BROWN', '01-MAY-14','01-SEP-14');
insert into EMP_TEMPORAL
*
ERROR at line 1:
ORA-00001: unique constraint (SYS_C009892) violated
105
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
add START_DT to primary key ?
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
no temporal validation
107
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> insert into EMP_TEMPORAL
2 (empno, name, start_dt, end_dt )
3 values (10,'JONES', '01-JAN-14','01-MAY-14');
1 row created.
SQL> insert into EMP_TEMPORAL
2 (empno, name, start_dt, end_dt )
3 values (10,'JONES', '01-FEB-14','01-MAR-14');
1 row created.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
no (native) temporal DML
109
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> update EMP_TEMPORAL
2 as of period for valid_range '01-FEB-14'
3 set sal = 10
4 where empno = 20;
as of period for valid_range '01-FEB-14'
*
ERROR at line 2:
ORA-08187: snapshot expression not allowed here
110
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> update
2 ( select * from EMP_TEMPORAL
3 as of period for valid_range '01-FEB-14'
4 )
5 set sal = 10
6 where empno = 20;
1 row updated.
111
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
take note ..
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"Temporal validity is not supported
with a multitenant container
database"
113
12.1.0.1
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Favourite:
top-n simplifications
114
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"5 most recently hired employees"
115
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 where rownum <= 5
4 order by hiredate desc;
EMPNO ENAME HIREDATE
---------- ---------- -------------------
7654 MARTIN 28/09/1981 00:00:00
7566 JONES 02/04/1981 00:00:00
7521 WARD 22/02/1981 00:00:00
7499 ALLEN 20/02/1981 00:00:00
7369 SMITH 17/12/1980 00:00:00
116
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
inline view
117
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select *
2 from (
3 select empno, ename, hiredate
4 from emp
5 order by hiredate desc
6 )
7 where rownum <= 5;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7876 ADAMS 23-MAY-87
7788 SCOTT 19-APR-87
...
118
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
------------------------------------------------
| Id | Operation | Name | Rows |
------------------------------------------------
| 0 | SELECT STATEMENT | | 5 |
|* 1 | COUNT STOPKEY | | |
| 2 | VIEW | | 14 |
|* 3 | SORT ORDER BY STOPKEY| | 14 |
| 4 | TABLE ACCESS FULL | EMP | 14 |
------------------------------------------------
119
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select *
2 from (
3 select
4 empno, ename, hiredate,
5 row_number() over ( order by hiredate desc) rn
6 from emp
7 )
8 where rn <= 5;
120
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
-------------------------------------------------
| Id | Operation | Name | Rows |
-------------------------------------------------
| 0 | SELECT STATEMENT | | 14 |
|* 1 | VIEW | | 14 |
|* 2 | WINDOW SORT PUSHED RANK| | 14 |
| 3 | TABLE ACCESS FULL | EMP | 14 |
-------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("RN"<=5)
2 - filter(ROW_NUMBER() OVER
( ORDER BY HIREDATE") DESC )<=5)
121
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
12c .... easier
122
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 fetch first 5 rows only;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7876 ADAMS 23-MAY-87
7788 SCOTT 19-APR-87
...
123
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
behind the scenes
124
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
-------------------------------------------------
| Id | Operation | Name | Rows |
-------------------------------------------------
| 0 | SELECT STATEMENT | | 14 |
|* 1 | VIEW | | 14 |
|* 2 | WINDOW SORT PUSHED RANK| | 14 |
| 3 | TABLE ACCESS FULL | EMP | 14 |
-------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("from$_subquery$_002".
"rowlimit_$$_rownumber"<=5)
2 - filter(ROW_NUMBER() OVER
( ORDER BY HIREDATE") DESC )<=5)
125
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
variations
126
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 fetch first 1 row only;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7876 ADAMS 23-MAY-87
127
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 fetch first 5 row only;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7876 ADAMS 23-MAY-87
7788 SCOTT 19-APR-87
7934 MILLER 23-JAN-82
7900 JAMES 03-DEC-81
7902 FORD 03-DEC-81
128
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 fetch first 10 percent rows only;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7876 ADAMS 23-MAY-87
7788 SCOTT 19-APR-87
129
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
pagination
130
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 offset 5 rows fetch next 3 rows only;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7839 KING 17-NOV-81
7654 MARTIN 28-SEP-81
7844 TURNER 08-SEP-81
131
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
can mimic rownum
132
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 fetch first 3 rows only;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7369 SMITH 17-DEC-80
7499 ALLEN 20-FEB-81
7521 WARD 22-FEB-81
133
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
-----------------------------------------------
| Id | Operation | Name | Rows |
-----------------------------------------------
| 0 | SELECT STATEMENT | | 14 |
|* 1 | VIEW | | 14 |
|* 2 | WINDOW NOSORT STOPKEY| | 14 |
| 3 | TABLE ACCESS FULL | EMP | 14 |
-----------------------------------------------
1 - filter("from$_subquery$_002"."rowlimit_$
2 - filter(ROW_NUMBER() OVER ( ORDER BY NULL ) <= 3
134
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
things to note
135
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 fetch LAST 5 rows only;
fetch LAST 5 rows only
*
ERROR at line 4:
ORA-00905: missing keyword
136
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select *
2 from (
3 select empno, ename, hiredate
4 from emp
5 order by hiredate asc
6 fetch first 5 rows only
7 )
8 order by hiredate desc;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7698 BLAKE 01-MAY-81
7566 JONES 02-APR-81
7521 WARD 22-FEB-81
7499 ALLEN 20-FEB-81
7369 SMITH 17-DEC-80
137
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
or ...
138
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 offset ( select count(*)-5 from emp) rows
5 fetch first 5 rows only;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7698 BLAKE 01-MAY-81
7566 JONES 02-APR-81
7521 WARD 22-FEB-81
7499 ALLEN 20-FEB-81
7369 SMITH 17-DEC-80
139
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
----------------------------------------------
| Id | Operation | Name | Rows |
----------------------------------------------
| 0 | SELECT STATEMENT | | 14 |
|* 1 | VIEW | | 14 |
| 2 | WINDOW SORT | | 14 |
| 3 | TABLE ACCESS FULL| EMP | 14 |
| 4 | SORT AGGREGATE | | 1 |
| 5 | INDEX FULL SCAN | PK_EMP | 14 |
----------------------------------------------
140
ugh
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
no percent pagination
141
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 offset 20 percent fetch
5 next 10 percent rows only;
offset 20 percent fetch next 10 percent rows only
*
ERROR at line 4:
ORA-00905: missing keyword
142
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 offset
5 ( select 20/100*count(*) from emp) rows
6 fetch next 10 percent rows only;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7934 MILLER 23-JAN-82
7902 FORD 03-DEC-81
143
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
PL/SQL quirk
144
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"Note that in real life,
you would use bind variables
instead of hard-coded literals"
145
- Tom Kyte,
Oracle Magazine
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> variable x number
SQL> exec :x := 5
PL/SQL procedure successfully completed.
SQL> select empno, ename, hiredate
2 from emp
3 order by hiredate desc
4 fetch first :x rows only;
EMPNO ENAME HIREDATE
---------- ---------- ---------
7876 ADAMS 23-MAY-87
7788 SCOTT 19-APR-87
7934 MILLER 23-JAN-82
7900 JAMES 03-DEC-81
7902 FORD 03-DEC-81
146
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> declare
2 l_num number := 5;
3 begin
4 for i in (
5 select empno, ename, hiredate
6 from emp
7 order by hiredate desc
8 fetch first l_num rows only
9 )
10 loop
11 null;
12 end loop;
13 end;
14 /
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 26618
Session ID: 25 Serial number: 53023
147
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> declare
2 l_num number := 5;
3 begin
4 for i in (
5 select empno, ename, hiredate
6 from emp
7 order by hiredate desc
8 fetch first cast(l_num as number) rows only
9 )
10 loop
11 null;
12 end loop;
13 end;
14 /
PL/SQL procedure successfully completed.
148
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Favourite:
pattern matching
149
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
analytics ... since 8.1.6
150
median
top n
moving average
etc
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"analysis"
often
"patterns"
151
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
real example
152
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 153
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
AML
154
anti-money laundering
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"Find 10 consecutive deposits in a
24 hour period, then
a withdrawal within three days of
the last deposit, at a different outlet"
155
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
ACCT TSTAMP WTHD_TSTAMP T AMT
---------- ------------------ ------------------ - ----------
54261 25/01/13 17:20:55 D 100
54261 25/01/13 17:56:58 D 165
54261 26/01/13 11:24:14 D 30
54261 26/01/13 11:47:53 D 45
54261 26/01/13 12:59:38 D 100
54261 26/01/13 13:26:04 D 80
54261 26/01/13 14:41:09 D 50
54261 26/01/13 14:53:12 D 50
54261 26/01/13 15:15:05 D 50
54261 26/01/13 15:51:17 D 50
54261 26/01/13 16:15:02 D 120
54261 26/01/13 16:36:51 D 100
54261 26/01/13 16:55:09 D 100
54261 26/01/13 18:07:17 26/01/13 18:07:17 W -500
156
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
hard...
157
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
pattern matching
158
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select acct, tstamp, wthd_tstamp, txn_type, amt
2 from account_txns
3 MATCH_RECOGNIZE
4 (
5 partition by acct
6 order by tstamp
7 measures
8 dep.tstamp dep_tstamp,
9 wthd.tstamp wthd_tstamp
10
11 all rows per match
12 pattern ( dep{10,} wthd )
13 define
14 dep as
15 txn_type = 'D',
16 wthd as
17 txn_type = 'W'
18 and last(dep.tstamp)-first(dep.tstamp) < interval '1' day
19 and wthd.tstamp - last(dep.tstamp) < interval '3' day
20 and wthd.location != last(dep.location)
21 )
159
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Favourite:
join enhancements
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
11.2
161
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> create table emp2 as
2 select * from emp;
Table created.
SQL> select *
2 from emp e,
3 emp2 e2,
4 dept d
5 where e.deptno = d.deptno(+)
6 and e2.deptno = d.deptno(+)
7 and e.empno = e2.empno
8 /
where e.deptno = d.deptno(+)
*
ERROR at line 5:
ORA-01417: a table may be outer joined to at most one other table
162
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
but ANSI syntax works …
163
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
12c
164
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select *
2 from emp e,
3 emp2 e2,
4 dept d
5 where e.deptno = d.deptno(+)
6 and e2.deptno = d.deptno(+)
7 and e.empno = e2.empno
8 /
EMPNO ENAME JOB MGR
---------- ---------- --------- ----------
7934 MILLER CLERK 7782
...
165
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
correlated inline views
166
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> create table DEPT_BENEFITS as
2 select d.*, 10 benefits from dept d;
Table created.
SQL> insert into DEPT_BENEFITS
2 select d.*, 20 benefits from dept d;
4 rows created.
167
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select e.empno, e.deptno, d.benefits
2 from emp e,
3 DEPT_BENEFITS d
4 where e.deptno = d.deptno
5 order by 1,3;
EMPNO DEPTNO BENEFITS
---------- ---------- ----------
7369 20 10
7369 20 20
7499 30 10
7499 30 20
7521 30 10
7521 30 20
...
...
168
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"benefits for each employee"
169
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select e.empno, d.deptno, b.benefits
2 from emp e,
3 ( select benefits
4 from DEPT_BENEFITS d
5 where d.deptno = e.deptno
6 ) b
7 order by 1,3;
where d.deptno = e.deptno
*
ERROR at line 5:
ORA-00904: "E"."DEPTNO": invalid identifier
170
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
CROSS APPLY
171
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select e.empno, e.deptno, b.benefits
2 from emp e
3 CROSS APPLY
4 ( select benefits
5 from DEPT_BENEFITS d
6 where d.deptno = e.deptno
7 ) b
8 order by 1,3;
EMPNO DEPTNO BENEFITS
---------- ---------- ----------
7369 20 10
7369 20 20
7499 30 10
...
...
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"big deal"
173
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select e.empno, d.deptno, b.benefits
2 from emp e,
3 ( select benefits
4 from DEPT_BENEFITS d
5
6 ) b
7
8 order by 1,3;
where d.deptno = e.deptno
174
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"best benefit for each employee"
175
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select e.empno, e.deptno, b.benefits
2 from emp e
3 CROSS APPLY
4 ( select benefits
5 from DEPT_BENEFITS d
6 where d.deptno = e.deptno
7 order by benefits desc
8 fetch first 1 rows only
9 ) b
10 order by 1,3;
EMPNO DEPTNO BENEFITS
---------- ---------- ----------
7369 20 20
7499 30 20
7521 30 20
7566 20 20
7654 30 20
...
176
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Favourite:
DML error logging
177
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> insert /*+ APPEND */ into MY_TABLE
2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;
178
MY_WHOPPING_GREAT_FAT_TABLE;
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 179
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 180
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 181
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 182
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 183
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> insert /*+ APPEND */ into MY_TABLE
2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;
Elapsed: 06:12:34.00
184
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> insert /*+ APPEND */ into MY_TABLE
2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;
Elapsed: 06:12:34.00
ERROR at line 1:
ORA-00001: unique constraint (DEMO.WHOPPER_PK) violated
185
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select count(*) from MY_TABLE;
COUNT(*)
----------
0
186
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
what we want
187
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
keep successful rows
188
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
skip / bypass bad rows
189
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> insert /*+ APPEND */ into MY_TABLE
2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE
4 where "not a duplicate"
5 and "datatypes are ok"
6 and "foreign keys are ok"
7 and "check constraints are ok"
190
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> exec DBMS_ERRLOG.CREATE_ERROR_LOG('EMP')
191
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
ERR$_EMP
192
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
DBMS_ERRLOG.CREATE_ERROR_LOG (
dml_table_name IN VARCHAR2,
err_log_table_name IN VARCHAR2 := NULL,
err_log_table_owner IN VARCHAR2 := NULL,
...
193
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> desc ERR$_EMP
Name Null? Type
----------------------------- -------- ----------------
ORA_ERR_NUMBER$ NUMBER
ORA_ERR_MESG$ VARCHAR2(2000)
ORA_ERR_ROWID$ ROWID
ORA_ERR_OPTYP$ VARCHAR2(2)
ORA_ERR_TAG$ VARCHAR2(2000)
EMPNO VARCHAR2(4000)
ENAME VARCHAR2(4000)
JOB VARCHAR2(4000)
MGR VARCHAR2(4000)
HIREDATE VARCHAR2(4000)
SAL VARCHAR2(4000)
COMM VARCHAR2(4000)
DEPTNO VARCHAR2(4000)
194
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 195
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
demo
196
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select * from NEW_DATA;
EMPNO SAL DEPTNO
---------- ---------- ----------
1000 5000 20
100X 3550 10
2000 2500 50
7934 4000 20
197
non-numeric
no dept 50
duplicate
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> exec dbms_errlog.create_error_log( 'EMP' );
PL/SQL procedure successfully completed.
SQL> insert into EMP (empno,sal,deptno)
2 select empno,sal,deptno
3 from NEW_DATA
4 LOG ERRORS REJECT LIMIT UNLIMITED;
1 row created.
198
50
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select ORA_ERR_OPTYP$ op, ORA_ERR_MESG$, EMPNO
2 from ERR$_EMP
OP ORA_ERR_MESG$ EMPNO
-- ------------------------------------------------------------ -----
I ORA-01722: invalid number 100X
I ORA-02291: integrity constraint (SCOTT.FK_DEPTNO) violated 2000
I ORA-00001: unique constraint (SCOTT.PK_EMP) violated 7934
199
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
favourite:
query blocks
200
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle201
C# application
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle202
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
C#, C++
203
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
C#, C++
PL/SQL
204
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
No comments
205
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 206
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"C# is self-documenting"
207
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
good code in any language ...
208
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
... should self document
209
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL is no different
210
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
select emp.*
from emp,
( select trunc(hiredate,'YYYY'), max(empno) empno
from emp
where empno > 0
group by trunc(hiredate,'YYYY') ) x,
( select deptno, avg(sal)
from emp
group by deptno ) y
where x.empno = emp.empno
and y.deptno = emp.deptno
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Explain plan
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Id | Operation | Name |
----------------------------------------------|
0 | SELECT STATEMENT | |
1 | HASH JOIN | |
2 | TABLE ACCESS BY INDEX ROWID | EMP |
3 | NESTED LOOPS | |
4 | VIEW | |
5 | SORT GROUP BY | |
6 | TABLE ACCESS BY INDEX ROWID| EMP |
7 | INDEX FULL SCAN | E2 |
8 | INDEX RANGE SCAN | E1 |
9 | VIEW | |
10 | SORT GROUP BY | |
11 | TABLE ACCESS BY INDEX ROWID | EMP |
12 | INDEX RANGE SCAN | E2 |
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
explain plan for
select emp.*
from emp,
( select /*+ QB_NAME(lastemp) */
trunc(hiredate,'YYYY'), max(empno) empno
from emp
where empno > 0
group by trunc(hiredate,'YYYY') ) x,
( select /*+ QB_NAME(avgsal) */
deptno, avg(sal)
from emp
group by deptno ) y
where x.empno = emp.empno
and y.deptno = emp.deptno
explain plan for
select emp.*
from emp,
( select /*+ QB_NAME(lastemp) */
trunc(hiredate,'YYYY'), max(empno) empno
from emp
where empno > 0
group by trunc(hiredate,'YYYY') ) x,
( select /*+ QB_NAME(avgsal) */
deptno, avg(sal)
from emp
group by deptno ) y
where x.empno = emp.empno
and y.deptno = emp.deptno
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
explain plan for
select emp.*
from emp,
( select /*+ QB_NAME(lastemp) */
trunc(hiredate,'YYYY'), max(empno) empno
from emp
where empno > 0
group by trunc(hiredate,'YYYY') ) x,
( select /*+ QB_NAME(avgsal) */
deptno, avg(sal)
from emp
group by deptno ) y
where x.empno = emp.empno
and y.deptno = emp.deptno
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Id | Operation | Name |
----------------------------------------------|
0 | SELECT STATEMENT | |
1 | HASH JOIN | |
2 | TABLE ACCESS BY INDEX ROWID | EMP |
3 | NESTED LOOPS | |
4 | VIEW | |
5 | SORT GROUP BY | |
6 | TABLE ACCESS BY INDEX ROWID| EMP |
7 | INDEX FULL SCAN | E2 |
8 | INDEX RANGE SCAN | E1 |
9 | VIEW | |
10 | SORT GROUP BY | |
11 | TABLE ACCESS BY INDEX ROWID | EMP |
12 | INDEX RANGE SCAN | E2 |
Query Block Name / Alias (identified by operation id):
---------------------------------------------------------
1 - SEL$1
3 - AVGSAL / Y@SEL$1
4 - AVGSAL
5 - AVGSAL / EMP@AVGSAL
6 - SEL$1 / EMP@SEL$1
7 - LASTEMP / X@SEL$1
8 - LASTEMP
9 - LASTEMP / EMP@LASTEMP
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
query PLAN_TABLE
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Id | Operation | Name | Query Block
----------------------------------------------|--------------
0 | SELECT STATEMENT | |
1 | HASH JOIN | |
2 | TABLE ACCESS BY INDEX ROWID | EMP |
3 | NESTED LOOPS | |
4 | VIEW | |
5 | SORT GROUP BY | |
6 | TABLE ACCESS BY INDEX ROWID| EMP |
7 | INDEX FULL SCAN | E2 |
8 | INDEX RANGE SCAN | E1 |
9 | VIEW | |
10 | SORT GROUP BY | |
11 | TABLE ACCESS BY INDEX ROWID | EMP |
12 | INDEX RANGE SCAN | E2 |
SEL$4ADCCA61
SEL$4ADCCA61
AVGSAL
AVGSAL
AVGSAL
AVGSAL
SEL$4ADCCA61
LASTEMP
LASTEMP
LASTEMP
LASTEMP
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Runtime statistics as well
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select /*+ gather_plan_statistics */
2 emp.*
3 from emp,
4 ( select /*+ QB_NAME(lastemp) */
5 trunc(hiredate,'YYYY'), max(empno) empno
6 from emp
7 where empno > 0
8 group by trunc(hiredate,'YYYY') ) x,
9 ( select /*+ QB_NAME(avgsal) */
10 deptno, avg(sal)
11 from emp
12 group by deptno ) y
13 where x.empno = emp.empno
14 and y.deptno = emp.deptno
15 /
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select * from
2 table(dbms_xplan.display_cursor(null,null,'IOSTATS LAST +ALIAS'));
-----------------------------------------------------------------------------------
|Id | Operation | Name |Starts | E-Rows | A-Rows |A-Time | Buffers |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 4 |00:00.01 | 21 |
| 1 | HASH JOIN | | 1 | 13 | 4 |00:00.01 | 21 |
| 2 | HASH JOIN | | 1 | 14 | 14 |00:00.01 | 14 |
| 3 | VIEW | | 1 | 3 | 3 |00:00.01 | 7 |
| 4 | HASH GROUP BY | | 1 | 3 | 3 |00:00.01 | 7 |
| 5 | TABLE ACCESS FULL| EMP | 1 | 14 | 14 |00:00.01 | 7 |
| 6 | TABLE ACCESS FULL | EMP | 1 | 14 | 14 |00:00.01 | 7 |
| 7 | VIEW | | 1 | 13 | 4 |00:00.01 | 7 |
| 8 | HASH GROUP BY | | 1 | 13 | 4 |00:00.01 | 7 |
| 9 | TABLE ACCESS FULL | EMP | 1 | 14 | 14 |00:00.01 | 7 |
-----------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
3 - AVGSAL / Y@SEL$1
4 - AVGSAL
5 - AVGSAL / EMP@AVGSAL
6 - SEL$1 / EMP@SEL$1
7 - LASTEMP / X@SEL$1
8 - LASTEMP
9 - LASTEMP / EMP@LASTEMP
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> alter session set
2 events = '10053 trace name context forever, level 1';
Session altered.
223
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
**************************
Query transformations (QT)
**************************
CBQT: Validity checks passed for 7jpzpr2475cqw.
CSE: Sub-expression elimination in query block SEL$1 (#0)
*************************
Common Subexpression elimination (CSE)
*************************
CSE: CSE not performed on query block LAST_EMP(#0).
CSE: Sub-expression elimination in query block AVG_SAL (#0)
CSE: CSE not performed on query block AV_SAL (#0).
CSE: CSE not performed on query block SEL$1 (#0).
***************************
Order-by elimination (OBYE)
***************************
OBYE: Considering Order-by Elimination from view SEL$1 (#0)
224
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
assist with hints
225
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
select
/*+ QB_NAME(top)
INDEX(@yr_hire emp (empno))
FULL(@av_sal emp)
*/
emp.*
from emp,
( select /*+ QB_NAME(YR_HIRE) */
trunc(hiredate,'YYYY'), max(empno) empno
from emp
where empno > 0
group by trunc(hiredate,'YYYY') ) x,
( select /*+ QB_NAME(AV_SAL) */
deptno, avg(sal)
from emp
group by deptno ) y
where x.empno = emp.empno
and y.deptno = emp.deptno
226
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Help the next person
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
It’s probably you
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Favourite:
subquery factoring
229
part 2
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
first principles
230
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select rpad(' ',level)||ename,
2 from emp
3 start with mgr is null
4 connect by prior empno = mgr
ENAME
---------------------------
KING
BLAKE
JAMES
ALLEN
WARD
CLARK
MILLER
231
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select empno, ename, mgr
2 from emp
3 where mgr is null;
EMPNO ENAME MGR
---------- -------------------- ----------
7839 KING
232
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select e2.empno, e2.ename, e2.mgr
2 from emp e2,
3 ( select empno, mgr
4 from emp
5 where mgr is null ) inner
6 where e2.mgr = inner.empno;
EMPNO ENAME MGR
---------- -------------------- ----------
7566 JONES 7839
7698 BLAKE 7839
7782 CLARK 7839
233
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select e3.empno, e3.ename, e3.mgr
2 from emp e3,
3 ( select e2.empno, e2.ename, e2.mgr
4 from emp e2,
5 ( select empno, mgr
6 from emp
7 where mgr is null ) inner
8 where e2.mgr = inner.empno ) inner
9 where e3.mgr = inner.empno;
EMPNO ENAME MGR
---------- -------------------- ----------
7902 FORD 7566
7788 SCOTT 7566
7900 JAMES 7698
7844 TURNER 7698
7654 MARTIN 7698
7521 WARD 7698
7934 MILLER 7782
234
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select e4.empno, e4.ename, e4.mgr
2 from emp e4,
3 ( select e3.empno, e3.ename, e3.mgr
4 from emp e3,
5 ( select e2.empno, e2.ename, e2.mgr
6 from emp e2,
7 ( select empno, mgr
8 from emp
9 where mgr is null ) inner
10 where e2.mgr = inner.empno ) inner
11 where e3.mgr = inner.empno ) inner
12 where e4.mgr = inner.empno;
EMPNO ENAME MGR
---------- -------------------- ----------
7876 ADAMS 7788
recursive...
235
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 236
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
WITH can be recursive
237
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> with EACH_LEVEL (empno, name, mgr) as
2 ( --
3 -- start with
4 --
5 select empno, ename, mgr
6 from emp
7 where mgr is null
8 --
9 -- connect by
10 --
11 union all
12 select emp.empno, emp.ename, emp.mgr
13 from emp, EACH_LEVEL
14 where emp.mgr = each_level.empno
15 )
16 select *
17 from each_level;
238
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
EMPNO NAME MGR
---------- --------------- ----------
7839 KING
7566 JONES 7839
7698 BLAKE 7839
7782 CLARK 7839
7499 ALLEN 7698
7521 WARD 7698
7654 MARTIN 7698
7788 SCOTT 7566
7844 TURNER 7698
7900 JAMES 7698
7902 FORD 7566
7934 MILLER 7782
7369 SMITH 7902
7876 ADAMS 7788
239
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
two part structure
240
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
with RECURSIVE_WITH (c1,c2,c3) as
(
<starting/entry point>
union all
<recursive relationship>
)
select ...
from RECURSIVE_WITH
241
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
you control pseudo-functions
242
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> with each_level (empno, name, mgr, rlevel) as
2 ( select empno, ename, mgr, 1 rlevel
3 from emp
4 where mgr is null
5 union all
6 select emp.empno, emp.ename, emp.mgr, rlevel+1
7 from emp, each_level
8 where emp.mgr = each_level.empno
9 )
10 select * from each_level;
EMPNO NAME MGR RLEVEL
---------- --------------- ---------- ----------
7839 KING 1
7566 JONES 7839 2
7698 BLAKE 7839 2
7782 CLARK 7839 2
7499 ALLEN 7698 3
<etc>
243
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> with each_level (empno, name, mgr, level) as
2 ( select empno, ename, mgr, 1 level
3 from emp
4 where mgr is null
5 union all
6 select emp.empno, emp.ename, emp.mgr, level+1
7 from emp, each_level
8 where emp.mgr = each_level.empno
9 )
10 select empno, name, mgr, level from each_level;
with each_level (empno, name, mgr, level) as
*
ERROR at line 1:
ORA-00904: : invalid identifier
244
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> with each_level (empno, name, mgr, rlevel) as
2 ( select empno, ename, mgr, 1 rlevel
3 from emp
4 where mgr is null
5 union all
6 select emp.empno, emp.ename, emp.mgr, rlevel+1
7 from emp, each_level
8 where emp.mgr = each_level.empno
9 )
10 select empno, name, mgr, rlevel as "LEVEL"
11 from each_level;
245
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> with each_level (empno, name, mgr, padding) as
2 ( select empno, ename, mgr, '' padding
3 from emp
4 where mgr is null
5 union all
6 select e.empno, e.ename, e.mgr, padding || ' '
7 from emp e, each_level
8 where e.mgr = each_level.empno
9 )
10 select empno, padding||name name
11 from each_level;
ERROR:
ORA-01489: result of string concatenation is too long
246
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> with each_level (empno, name, mgr, padding) as
2 ( select empno, ename, mgr,
3 cast('' as varchar2(100)) padding
4 from emp
5 where mgr is null
6 union all
7 select e.empno, e.ename, e.mgr, padding || ' '
8 from emp e, each_level
9 where e.mgr = each_level.empno
10 )
11 select empno, padding||name name
12 from each_level;
EMPNO NAME
---------- --------------------------------
7839 KING
7566 JONES
...
247
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> with each_level (empno, name) as
2 ( select empno, ename from emp
3 where mgr is null
4 union all
5 select e.empno,
6 each_level.name||'-'||e.ename
7 from emp e, each_level
8 where e.mgr = each_level.empno
9 )
10 select empno, name from each_level;
EMPNO NAME
---------- --------------------------------
7839 KING
7566 KING-JONES
7698 KING-BLAKE
7782 KING-CLARK
7499 KING-BLAKE-ALLEN
7521 KING-BLAKE-WARD
<etc>
248
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
some nice touches...
249
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> with each_level (empno, name, hiredate, mgr) as
2 ( ... )
9 SEARCH BREADTH FIRST BY HIREDATE SET IDX
10 select name, hiredate, idx from each_level;
NAME HIREDATE IDX
-------------------------------- --------- ----------
KING 17-NOV-81 1
KING-JONES 02-APR-81 2
KING-BLAKE 01-MAY-81 3
KING-CLARK 09-JUN-81 4
KING-BLAKE-ALLEN 20-FEB-81 5
KING-BLAKE-WARD 22-FEB-81 6
[snip]
KING-JONES-FORD-SMITH 17-DEC-80 13
KING-JONES-SCOTT-ADAMS 23-MAY-87 14
250
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> with each_level (empno, name, hiredate, mgr) as
2 ( ... )
9 SEARCH DEPTH FIRST BY HIREDATE SET IDX
10 select name, hiredate, idx from each_level;
NAME HIREDATE IDX
-------------------------------- --------- ----------
KING 17-NOV-81 1
KING-JONES 02-APR-81 2
KING-JONES-FORD 03-DEC-81 3
KING-JONES-FORD-SMITH 17-DEC-80 4
KING-JONES-SCOTT 19-APR-87 5
KING-JONES-SCOTT-ADAMS 23-MAY-87 6
KING-BLAKE 01-MAY-81 7
KING-BLAKE-ALLEN 20-FEB-81 8
etc
251
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
get used to it .....
ANSI
252
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Favourite:
sql transposition
253
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
rows to columns, colums to rows
254
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"I need sales by product
for each quarter....now"
255
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select product,
2 trunc(txn_date,'Q') mth, sum(quantity) total
3 from SALES
4 group by product,trunc(txn_date,'Q')
5 order by 1,2;
PRODUCT MTH TOTAL
-------------------- --- ----------
CHAINSAW JAN 251473
CHAINSAW APR 254830
CHAINSAW JUL 251994
CHAINSAW OCT 243748
HAMMER JAN 249889
HAMMER APR 256566
HAMMER JUL 252992
HAMMER OCT 249104
SCREW DRIVER JAN 245988
SCREW DRIVER APR 249219
SCREW DRIVER JUL 252128
256
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"That’s junk...surely you know
I wanted it ACROSS the page"
257
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 258
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 259
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
PIVOT clause
260
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select *
2 from (select product,
3 trunc(txn_date,'Q') mth,
4 quantity
5 from sales )
6 pivot( sum(quantity) for mth in
7 ( 'JAN','APR','JUL','OCT' ) )
11 order by 1
12 /
PRODUCT 'JAN' 'APR' 'JUL' 'OCT'
-------------------- ---------- ---------- ---------- ----------
CHAINSAW 251473 254830 251994 243748
HAMMER 249889 256566 252992 249104
SCREW DRIVER 245988 249219 252128 244721
SPADE 242434 254090 259613 248428
WHEEL BARROW 243899 249327 252296 254137
261
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
"nah...make it go DOWN the page
262
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> create table PIVOTED_SALES as select *
2 from (select product,
3 trunc(txn_date,'Q') mth,
4 quantity
5 from sales )
6 pivot( sum(quantity) for mth in
7 ( 'JAN',
8 'APR',
9 'JUL',
10 'OCT') )
11 order by 1
12 /
Table created.
263
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
UNPIVOT clause
264
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> desc PIVOTED_SALES
Name Null? Type
----------------------------- -------- -------------
PRODUCT VARCHAR2(20)
Q1 NUMBER
Q2 NUMBER
Q3 NUMBER
Q4 NUMBER
265
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL> select *
2 from PIVOTED_SALES
3 UNPIVOT
4 ( quantity for quarter in (Q1,Q2,Q3,Q4) )
5 /
PRODUCT QUARTER QUANTITY
-------------------- ------- ----------
CHAINSAW Q1 251473
CHAINSAW Q2 254830
CHAINSAW Q3 251994
CHAINSAW Q4 243748
HAMMER Q1 249889
HAMMER Q2 256566
HAMMER Q3 252992
HAMMER Q4 249104
SCREW DRIVER Q1 245988
SCREW DRIVER Q2 249219
SCREW DRIVER Q3 252128
...
column values
become "quantity"
column names
become "quarter"
266
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
elements must be known in advance
267
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 268
Wrap up
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 269
lots not covered today
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
why talk about SQL
(reason 4)
270
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Life is too short
271
(look away now if you are squeamish)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 272
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 273
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.accessibility.*;
import com.sun.java.accessibility.util.*;
public AssistiveExample extends JPanel
implements MouseMotionListener, ActionListener,
GUIInitializedListener {
Timer timer;
static JFrame frame;
JLabel nameLabel = new JLabel();
JLabel descriptionLabel = new JLabel();
JLabel tableLabel = new JLabel();
JCheckBox selectionCheckBox = new JCheckBox("Selection",
false);
JCheckBox textCheckBox = new JCheckBox("Text", false);
JCheckBox valueCheckBox = new JCheckBox("Value", false);
JCheckBox componentCheckBox = new JCheckBox("Component",
false);
JCheckBox actionCheckBox = new JCheckBox("Action", false);
JCheckBox hypertextCheckBox = new JCheckBox("Hypertext",
false);
JCheckBox iconCheckBox = new JCheckBox("Icon", false);
JCheckBox tableCheckBox = new JCheckBox("Table", false);
JCheckBox editableTextCheckBox = new JCheckBox("EditableText",
false);
JLabel classLabel = new JLabel();
JLabel parentLabel = new JLabel();
JLabel relationLabel = new JLabel();
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL is faster
274
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL is easier
275
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 276
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
SQL is more exciting
277
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle278
Connor McDonaldORA-03113
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
Creative Commons Image Resources
https://commons.wikimedia.org/wiki/File:Horse_Race_Finish_Line_(11888565543).jpg
https://pixabay.com/en/iphone-iphone-6-apple-flat-762044/
https://pixabay.com/en/curve-return-pass-road-384406/
https://pixabay.com/en/high-five-figure-man-blue-150911/
https://pixabay.com/en/joker-jester-card-playing-card-164030/
https://commons.wikimedia.org/wiki/File:2008-08-19_Flat_tire.jpg
https://upload.wikimedia.org/wikipedia/commons/4/4d/3DCrystal_ball.png

Weitere ähnliche Inhalte

Was ist angesagt?

APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentConnor McDonald
 
OpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tipsOpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tipsConnor McDonald
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Connor McDonald
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101Connor McDonald
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersConnor McDonald
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featuesConnor McDonald
 
Perth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL TechniquesPerth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL TechniquesConnor McDonald
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLConnor McDonald
 
Sangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediSangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediConnor McDonald
 
Sangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLSangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLConnor McDonald
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesConnor McDonald
 
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerConnor McDonald
 
18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18cChris Saxon
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQLChris Saxon
 
12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for Developers12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for DevelopersConnor McDonald
 
20200402 oracle cloud infrastructure data science
20200402 oracle cloud infrastructure data science20200402 oracle cloud infrastructure data science
20200402 oracle cloud infrastructure data scienceKenichi Sonoda
 
[Code night] natural language proccessing and machine learning
[Code night] natural language proccessing and machine learning[Code night] natural language proccessing and machine learning
[Code night] natural language proccessing and machine learningKenichi Sonoda
 
20200812 Cbject Detection with OpenCV and CNN
20200812 Cbject Detection with OpenCV and CNN20200812 Cbject Detection with OpenCV and CNN
20200812 Cbject Detection with OpenCV and CNNKenichi Sonoda
 
ILOUG 2019 - 25 years of hints and tips
ILOUG 2019 - 25 years of hints and tipsILOUG 2019 - 25 years of hints and tips
ILOUG 2019 - 25 years of hints and tipsConnor McDonald
 

Was ist angesagt? (20)

APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
 
OpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tipsOpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tips
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
Perth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL TechniquesPerth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL Techniques
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
 
Sangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediSangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL Jedi
 
Sangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLSangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQL
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
 
18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQL
 
12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for Developers12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for Developers
 
20200402 oracle cloud infrastructure data science
20200402 oracle cloud infrastructure data science20200402 oracle cloud infrastructure data science
20200402 oracle cloud infrastructure data science
 
[Code night] natural language proccessing and machine learning
[Code night] natural language proccessing and machine learning[Code night] natural language proccessing and machine learning
[Code night] natural language proccessing and machine learning
 
20200812 Cbject Detection with OpenCV and CNN
20200812 Cbject Detection with OpenCV and CNN20200812 Cbject Detection with OpenCV and CNN
20200812 Cbject Detection with OpenCV and CNN
 
ILOUG 2019 - 25 years of hints and tips
ILOUG 2019 - 25 years of hints and tipsILOUG 2019 - 25 years of hints and tips
ILOUG 2019 - 25 years of hints and tips
 

Ähnlich wie Cool SQL Features

HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]David Buck
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsConnor McDonald
 
AskTOM Office Hours on Database Triggers
AskTOM Office Hours on Database TriggersAskTOM Office Hours on Database Triggers
AskTOM Office Hours on Database TriggersSteven Feuerstein
 
ILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c featuresILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c featuresConnor McDonald
 
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015Dave Stokes
 
MySQL Group Replication: Handling Network Glitches - Best Practices
MySQL Group Replication: Handling Network Glitches - Best PracticesMySQL Group Replication: Handling Network Glitches - Best Practices
MySQL Group Replication: Handling Network Glitches - Best PracticesFrederic Descamps
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cConnor McDonald
 
Developers vs DBA's - APACOUC webinar 2017
Developers vs DBA's - APACOUC webinar 2017Developers vs DBA's - APACOUC webinar 2017
Developers vs DBA's - APACOUC webinar 2017Connor McDonald
 
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL ChangesUsing Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL ChangesChris Saxon
 
Oracle Cloud에서 애플리케이션을 개발하고 테스트하는 손쉬운 방법
Oracle Cloud에서 애플리케이션을 개발하고 테스트하는 손쉬운 방법Oracle Cloud에서 애플리케이션을 개발하고 테스트하는 손쉬운 방법
Oracle Cloud에서 애플리케이션을 개발하고 테스트하는 손쉬운 방법Mee Nam Lee
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresConnor McDonald
 
GraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajevGraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajevOracle Developers
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAsConnor McDonald
 
Chicago EPM Day-Excellence in Consolidations with HFM
Chicago EPM Day-Excellence in Consolidations with HFMChicago EPM Day-Excellence in Consolidations with HFM
Chicago EPM Day-Excellence in Consolidations with HFMAlithya
 
ILOUG 2019 - Flashback, the forgotten feature
ILOUG 2019 - Flashback, the forgotten featureILOUG 2019 - Flashback, the forgotten feature
ILOUG 2019 - Flashback, the forgotten featureConnor McDonald
 
はじめてのOracle Cloud Infrastructure(Oracle Cloudウェビナーシリーズ: 2020年6月24日)
はじめてのOracle Cloud Infrastructure(Oracle Cloudウェビナーシリーズ: 2020年6月24日)はじめてのOracle Cloud Infrastructure(Oracle Cloudウェビナーシリーズ: 2020年6月24日)
はじめてのOracle Cloud Infrastructure(Oracle Cloudウェビナーシリーズ: 2020年6月24日)オラクルエンジニア通信
 
How to Upgrade Hundreds or Thousands of Databases
How to Upgrade Hundreds or Thousands of DatabasesHow to Upgrade Hundreds or Thousands of Databases
How to Upgrade Hundreds or Thousands of DatabasesGuatemala User Group
 
Troubleshooting Ecommerce Performance
 Troubleshooting Ecommerce Performance Troubleshooting Ecommerce Performance
Troubleshooting Ecommerce PerformanceDiego Cardozo
 

Ähnlich wie Cool SQL Features (20)

HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
 
AskTOM Office Hours on Database Triggers
AskTOM Office Hours on Database TriggersAskTOM Office Hours on Database Triggers
AskTOM Office Hours on Database Triggers
 
ILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c featuresILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c features
 
Partitioning 101
Partitioning 101Partitioning 101
Partitioning 101
 
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015
 
MySQL Group Replication: Handling Network Glitches - Best Practices
MySQL Group Replication: Handling Network Glitches - Best PracticesMySQL Group Replication: Handling Network Glitches - Best Practices
MySQL Group Replication: Handling Network Glitches - Best Practices
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
Developers vs DBA's - APACOUC webinar 2017
Developers vs DBA's - APACOUC webinar 2017Developers vs DBA's - APACOUC webinar 2017
Developers vs DBA's - APACOUC webinar 2017
 
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL ChangesUsing Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
 
Oracle Cloud에서 애플리케이션을 개발하고 테스트하는 손쉬운 방법
Oracle Cloud에서 애플리케이션을 개발하고 테스트하는 손쉬운 방법Oracle Cloud에서 애플리케이션을 개발하고 테스트하는 손쉬운 방법
Oracle Cloud에서 애플리케이션을 개발하고 테스트하는 손쉬운 방법
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
 
GraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajevGraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajev
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
Chicago EPM Day-Excellence in Consolidations with HFM
Chicago EPM Day-Excellence in Consolidations with HFMChicago EPM Day-Excellence in Consolidations with HFM
Chicago EPM Day-Excellence in Consolidations with HFM
 
ILOUG 2019 - Flashback, the forgotten feature
ILOUG 2019 - Flashback, the forgotten featureILOUG 2019 - Flashback, the forgotten feature
ILOUG 2019 - Flashback, the forgotten feature
 
はじめてのOracle Cloud Infrastructure(Oracle Cloudウェビナーシリーズ: 2020年6月24日)
はじめてのOracle Cloud Infrastructure(Oracle Cloudウェビナーシリーズ: 2020年6月24日)はじめてのOracle Cloud Infrastructure(Oracle Cloudウェビナーシリーズ: 2020年6月24日)
はじめてのOracle Cloud Infrastructure(Oracle Cloudウェビナーシリーズ: 2020年6月24日)
 
Oracle SQLcl
Oracle SQLcl Oracle SQLcl
Oracle SQLcl
 
How to Upgrade Hundreds or Thousands of Databases
How to Upgrade Hundreds or Thousands of DatabasesHow to Upgrade Hundreds or Thousands of Databases
How to Upgrade Hundreds or Thousands of Databases
 
Troubleshooting Ecommerce Performance
 Troubleshooting Ecommerce Performance Troubleshooting Ecommerce Performance
Troubleshooting Ecommerce Performance
 

Mehr von Connor McDonald

Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestConnor McDonald
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQLConnor McDonald
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsConnor McDonald
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousConnor McDonald
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresConnor McDonald
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousConnor McDonald
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne Connor McDonald
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsConnor McDonald
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistencyConnor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsConnor McDonald
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessionsConnor McDonald
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresConnor McDonald
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql featuresConnor McDonald
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerConnor McDonald
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsConnor McDonald
 
OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersConnor McDonald
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingConnor McDonald
 

Mehr von Connor McDonald (19)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAs
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
 
OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developers
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processing
 

Kürzlich hochgeladen

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Kürzlich hochgeladen (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Cool SQL Features

  • 1. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 1 SQL> select sample_font 2 from dual ; Can you read this ? Note: Small fonts in this presentation
  • 2.
  • 3. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 3
  • 4. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 4
  • 5. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 5
  • 6. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 6https://www.youtube.com/c/ConnorMcDonaldOracle
  • 7. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 7
  • 8. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle bio 8
  • 9. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
  • 10. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle make you more successful with Oracle
  • 11. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | SQL-lectric !!! Connor McDonald Developer Advocate for SQL 2016 Oracle Confidential –
  • 12. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle why talk about SQL (reason 1) 12
  • 13. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle People are (re)learning... 13
  • 14. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ...SQL is pretty important 14
  • 15. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle “….the complexity of dealing with a non-ACID data store in every part of our business logic would be too great, and there was simply no way our business could function without SQL queries.” Google, VLDB 2013 “[Facebook] started in the Hadoop world. We are now bringing in relational to enhance that. ... [we] realized that using the wrong technology for certain kinds of problems can be difficult.” Ken Rudin, Facebook, TDWI 2013 15 http://tdwi.org/articles/2013/05/06/facebooks-relational-platform.aspxhttps://www.linkedin.com/groups/Find-out-why-Google-decided-4434815.S.273792742
  • 16. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle why talk about SQL (reason 2) 16
  • 17.
  • 18. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
  • 19. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle why talk about SQL (reason 3) 19
  • 20. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle we all want to be cool  20
  • 21. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "microservices" 21
  • 22. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "simple function" 22 "insulated data access" "test in isolation" SQL> SELECT sal 2 FROM EMP 3 WHERE EMPNO = 12
  • 23. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle its all about the SQL 23
  • 24. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 24 this session
  • 25. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 25 my favourites
  • 26. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 26 strong focus on 12c
  • 27. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Favourite: subquery factoring 27
  • 28. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle WITH clause 28
  • 29. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> WITH last_hire AS 2 ( select deptno, max(hiredate) 3 from emp 4 group by deptno 5 ) 6 select * from last_hire; DEPTNO MAX(HIRED ---------- --------- 30 03-DEC-81 20 12-JAN-83 10 23-JAN-82 29
  • 30. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "gee.......wow" 30
  • 31. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle why is it cool ? 31
  • 32. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle good solution metaphor 32
  • 33. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle here's the problem 33
  • 34. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle we're awful at set theory.... 34
  • 35. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ...set theory is awful  35
  • 36. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle not our fault 36
  • 37. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Codd & Date 37
  • 38. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "data is represented as mathematical n-ary relations, an n-ary relation being a subset of the Cartesian product of n domains." 38
  • 39. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 39
  • 40. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle humans are procedural 40
  • 41. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle business analysts... procedural analysis 41
  • 42. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle technical analysts... procedural specifications 42
  • 43. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle programmers procedural programs 43
  • 44. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle procedural 44 relational
  • 45. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle good solution metaphor 45
  • 46. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "First, get the total salary paid by department... SQL> WITH dept_salaries AS ( 2 SELECT dname, SUM(sal) dept_sal 3 FROM emp e, dept d 4 WHERE e.deptno = d.deptno 5 GROUP BY dname), 46
  • 47. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "...then get the average of these totals... 6 avg_sal AS ( SELECT AVG(dept_sal) avsal 7 FROM dept_salaries) 47
  • 48. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "...then list those departments above average." 8 SELECT * FROM dept_salaries d, avg_sal a 9 WHERE d.dept_sal > a.avsal 10 ORDER BY d.dname; 48
  • 49. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> WITH dept_salaries AS ( 2 SELECT dname, SUM(sal) dept_sal 3 FROM emp e, dept d 4 WHERE e.deptno = d.deptno 5 GROUP BY dname), 6 avg_sal AS ( SELECT AVG(dept_sal) avsal 7 FROM dept_salaries) 8 SELECT * FROM dept_salaries d, avg_sal a 9 WHERE d.dept_sal > a.avsal 10 ORDER BY d.dname; 49
  • 50. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle procedural approach.... 50
  • 51. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ...set based solution 51
  • 52. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle things to note... 52
  • 53. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle execution plan 53
  • 54. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle two possibilities 54
  • 55. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle temporary storage 55
  • 56. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ---------------------------------------------------------------------- | Id | Operation | Name | ---------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | 1 | TEMP TABLE TRANSFORMATION | | | 2 | LOAD AS SELECT | | | 3 | HASH GROUP BY | | | 4 | MERGE JOIN | | | 5 | TABLE ACCESS BY INDEX ROWID| DEPT | | 6 | INDEX FULL SCAN | PK_DEPT | | 7 | SORT JOIN | | | 8 | TABLE ACCESS FULL | EMP | | 9 | SORT ORDER BY | | | 10 | NESTED LOOPS | | | 11 | VIEW | | | 12 | SORT AGGREGATE | | | 13 | VIEW | | | 14 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6624_AF422F5 | | 15 | VIEW | | | 16 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6624_AF422F5 | ---------------------------------------------------------------------- 56
  • 57. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> alter session set sql_trace = true; Session altered. SQL> WITH dept_salaries AS ( 2 SELECT dname, SUM(sal) dept_sal 3 FROM emp e, dept d 4 WHERE e.deptno = d.deptno 5 GROUP BY dname), 6 avg_sal AS ( SELECT AVG(dept_sal) asal 7 FROM dept_salaries) 8 SELECT * FROM dept_salaries d, avg_sal a 9 WHERE d.dept_sal > a.asal 10 ORDER BY d.dname; DNAME DEPT_SAL ASAL -------------- ---------- ---------- RESEARCH 21750 19350 SQL> alter session set sql_trace = false; Session altered. 57
  • 58. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle PARSING IN CURSOR #12 len=179 dep=1 uid=0 oct=1... CREATE GLOBAL TEMPORARY TABLE "SYS"."SYS_TEMP_0FD9D6625_AF422F5" ("C0" VARCHAR2(14),"C1" NUMBER ) IN_MEMORY_METADATA CURSOR_SPECIFIC_SEGMENT STORAGE (OBJNO 4254950949 ) NOPARALLEL END OF STMT 58
  • 59. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle no temporary storage 59
  • 60. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ------------------------------------------------------ | Id | Operation | Name | ------------------------------------------------------ | 0 | SELECT STATEMENT | | | 1 | SORT ORDER BY | | | 2 | NESTED LOOPS | | | 3 | VIEW | | | 4 | SORT AGGREGATE | | | 5 | VIEW | | | 6 | HASH GROUP BY | | | 7 | MERGE JOIN | | | 8 | TABLE ACCESS BY INDEX ROWID| DEPT | | 9 | INDEX FULL SCAN | PK_DEPT | | 10 | SORT JOIN | | | 11 | TABLE ACCESS FULL | EMP | | 12 | VIEW | | | 13 | SORT GROUP BY | | | 14 | MERGE JOIN | | | 15 | TABLE ACCESS BY INDEX ROWID | DEPT | | 16 | INDEX FULL SCAN | PK_DEPT | | 17 | SORT JOIN | | | 18 | TABLE ACCESS FULL | EMP | ------------------------------------------------------ 60
  • 61. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle explicit control 61
  • 62. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> WITH dept_salaries AS ( 2 SELECT /*+ INLINE */ dname, SUM(sal) dept_sal 3 FROM emp e, dept d 4 WHERE e.deptno = d.deptno 5 GROUP BY dname), 6 avg_sal AS ( SELECT AVG(dept_sal) asal 7 FROM dept_salaries) 8 SELECT * FROM dept_salaries d, avg_sal a 9 WHERE d.dept_sal > a.asal 10 ORDER BY d.dname; 62
  • 63. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> WITH dept_salaries AS ( 2 SELECT /*+ MATERIALIZE*/ dname, SUM(sal) dept_sal 3 FROM emp e, dept d 4 WHERE e.deptno = d.deptno 5 GROUP BY dname), 6 avg_sal AS ( SELECT AVG(dept_sal) asal 7 FROM dept_salaries) 8 SELECT * FROM dept_salaries d, avg_sal a 9 WHERE d.dept_sal > a.asal 10 ORDER BY d.dname; 63
  • 64. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle undocumented .... sort of 64
  • 65. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle useful control over optimizer 65
  • 66. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle useful control over database links 66
  • 67. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ... more on WITH later 67
  • 68. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Favourite: temporal validity
  • 69. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
  • 70. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle very common 70
  • 71. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle when is a row "valid" 71
  • 72. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> CREATE TABLE emp_temporal ( 2 empno NUMBER, 3 name VARCHAR2(30), 4 sal NUMBER, 5 deptno NUMBER, 6 start_dt DATE, 7 end_dt DATE, 8 9 ); Table created. 72
  • 73. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 12c - part of the definition 73
  • 74. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> CREATE TABLE emp_temporal ( 2 empno NUMBER, 3 name VARCHAR2(30), 4 sal NUMBER, 5 deptno NUMBER, 6 start_dt DATE, 7 end_dt DATE, 8 PERIOD FOR valid_range (start_dt, end_dt) 9 ); Table created. 74
  • 75. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle examples 75
  • 76. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * from emp_temporal 2 order by empno, start_dt; EMPNO NAME SAL DEPTNO START_DT END_DT ---------- ------------ ---------- ---------- --------- --------- 7369 SMITH 806 20 01-JAN-14 01-MAR-14 7369 SMITHX 8060 21 02-MAR-14 01-OCT-14 7499 ALLEN 1606 30 01-JAN-14 01-MAR-14 7499 ALLENX 16060 31 02-MAR-14 01-OCT-14 7521 WARD 1256 30 01-JAN-14 01-MAR-14 7521 WARDX 12560 31 02-MAR-14 01-OCT-14 7566 JONES 2981 20 01-JAN-14 01-MAR-14 7566 JONESX 29810 21 02-MAR-14 01-OCT-14 7654 MARTIN 1256 30 01-JAN-14 01-MAR-14 7654 MARTINX 12560 31 02-MAR-14 01-OCT-14 7698 BLAKE 2856 30 01-JAN-14 01-MAR-14 76
  • 77. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * from emp_temporal 2 as of period for valid_range '01-FEB-14'; EMPNO NAME SAL DEPTNO START_DT END_DT ---------- ------------ ---------- ---------- --------- --------- 7369 SMITH 806 20 01-JAN-14 01-MAR-14 7499 ALLEN 1606 30 01-JAN-14 01-MAR-14 7521 WARD 1256 30 01-JAN-14 01-MAR-14 7566 JONES 2981 20 01-JAN-14 01-MAR-14 7654 MARTIN 1256 30 01-JAN-14 01-MAR-14 77
  • 78. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle so what's happening ? 78
  • 79. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle a slight digression 79
  • 80. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Favourite: query expansion 80
  • 81. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 81 SQL> set autotrace traceonly stat SQL> select * from MY_STUFF 2 where CREATED > sysdate Statistics ------------------------------------------ 651 recursive calls 0 db block gets 2243 consistent gets 24 physical reads
  • 82. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 82 SQL> variable c clob SQL> begin 2 dbms_utility.expand_sql_text 3 ( 'select * from MY_STUFF'|| 4 'where created > sysdate',:c); 5 end; 6 / PL/SQL procedure successfully completed. SQL> print c
  • 83. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 83 SQL> create or replace 2 view MY_STUFF as 3 select 4 o.owner, 5 o.created, 6 s.bytes, 7 s.tablespace_name 8 from 9 dba_segments s, 10 all_objects o 11 where o.owner = s.owner 12 and o.object_name = s.segment_name; View created.
  • 84. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 84 SELECT "A1"."OWNER" "OWNER", "A1"."NAME" "NAME", "A1"."CREATED" "CREATED", "A1"."BYTES" "BYTES", "A1"."TABLESPACE_NAME" "TABLESPACE_NAME" FROM (SELECT "A2"."OWNER" "OWNER", "A2"."OBJECT_NAME" "NAME", "A2"."CREATED" "CREATED", "A3"."BYTES" "BYTES", "A3"."TABLESPACE_NAME" "TABLESPACE_NAME" FROM (SELECT "A4" ."OWNER" "OWNER", "A4"."SEGMENT_NAME" "SEGMENT_NAME", "A4"."PARTITION_NAME" "PARTITION_NAME", "A4"."SEGMENT_TYPE" "SEGMENT_TYPE", "A4"."SEGMENT_SUBTYPE" "SEGMENT_SUBTYPE", "A4"."TABLESPACE_NAME" "TABLESPACE_NAME", "A4"."HEADER_FILE" "HEADER_FILE", "A4"."HEADER_BLOCK" "HEADER_BLOCK", DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072, "A4"."BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1, "SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_BLOCKS"("A4"."TABLESPACE_ID", "A4"."RELATIVE_FNO", "A4"."HEADER_BLOCK", "A4"."SEGMENT_TYPE_ID", "A4"."BUFFER_POOL_ID", "A4"."SEGMENT_FLAGS", "A4"."SEGMENT_OBJD", "A4"."BLOCKS"), "A4"."BLOCKS"))*"A4"."BLOCKSIZE" "BYTES", DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072,
  • 85. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 85 "A4"."HEADER_BLOCK", "A4"."SEGMENT_TYPE_ID", "A4"."BUFFER_POOL_ID", "A4"."SEGMENT_FLAGS", "A4"."SEGMENT_OBJD", "A4"."BLOCKS"), "A4"."BLOCKS")) "BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072, "A4"."EXTENTS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1, "SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_EXTENTS"("A4"."TABLESPACE_ID", "A4"."RELATIVE_FNO", "A4"."HEADER_BLOCK", "A4"."SEGMENT_TYPE_ID", "A4"."BUFFER_POOL_ID", "A4"."SEGMENT_FLAGS", "A4"."SEGMENT_OBJD", "A4"."EXTENTS"), "A4"."EXTENTS")) "EXTENTS", "A4"."INITIAL_EXTENT" "INITIAL_EXTENT", "A4"."NEXT_EXTENT" "NEXT_EXTENT", "A4"."MIN_EXTENTS" "MIN_EXTENTS", "A4"."MAX_EXTENTS" "MAX_EXTENTS", "A4"."MAX_SIZE" "MAX_SIZE", "A4"."RETENTION" "RETENTION", "A4"."MINRETENTION" "MINRETENTION", "A4"."PCT_INCREASE" "PCT_INCREASE", "A4"."FREELISTS" "FREELISTS", "A4"."FREELIST_GROUPS" "FREELIST_GROUPS", "A4"."RELATIVE_FNO" "RELATIVE_FNO",
  • 86. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 86 "A198"."SUBNAME" "PARTITION_NAME", "A196"."OBJECT_TYPE" "SEGMENT_TYPE", "A195"."TYPE#" "SEGMENT_TYPE_ID",DECODE(BIT AND("A195"."SPARE1",2097408),2097152,'SECUREFILE',256,'ASSM','MSSM') "SEGMENT_SUBTYPE", "A197"."TS#" "TABLESPACE_ID", "A197"."NAME" "TABLESPACE_NAME", "A197"."BLOCKSIZE" "BLOCKSIZE", "A194"."FILE#" "HEADER_FILE", "A195"."BLOCK#" "HEADER_BLOCK", "A195"."BLOCKS"*"A197"."BLOCKSIZE" "BYTES", "A195"."BLOCKS" "BLOCKS", "A195"."EXTENTS" "EXTENTS", "A195"."INIEXTS"*"A197"."BLOCKSIZE" "INITIAL_EXTENT", "A195"."EXTSIZE"*"A197"."BLOCKSIZE" "NEXT_EXTENT", "A195"."MINEXTS" "MIN_EXTENTS", "A195"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A195"."SPARE1",4194304),4194304, "A195"."BITMAPRANGES",NULL) "MAX_SIZE",TO_CHAR(DECODE( BITAND("A195"."SPARE1",2097152),2097152, DECODE("A195"."LISTS",0,'NONE',1,'AUTO',2,'MIN',3,'MAX',4,'DEFAULT','INVALID' ),NULL)) "RETENTION",DECODE(BITAND("A195"."SPARE1",2097152),2097152, "A195"."GROUPS",NULL) "MINRETENTION",DECODE(BITAND("A197"."FLAGS",3),1,TO_NUMBER(NULL), "A195"."EXTPCT") "PCT_INCREASE",DECODE(BITAND("A197"."FLAGS",32),32, TO_NUMBER(NULL),DECODE("A195"."LISTS",0,1, "A195"."LISTS")) "FREELISTS",DECODE(BITAND("A197"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A195" ."GROUPS",0,1,
  • 87. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 87 DECODE(BITAND("A209"."PROPERTY",8192),8192,'NESTED TABLE','TABLE') "OBJECT_TYPE", 2 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID", "A209"."OBJ#" "OBJECT_ID", "A209"."FILE#" "HEADER_FILE", "A209"."BLOCK#" "HEADER_BLOCK", "A209"."TS#" "TS_NUMBER" FROM "SYS"."TAB$" "A209" WHERE BITAND("A209"."PROPERTY",1024)=0) UNI ON ALL (SELECT 'TABLE PARTITION' "OBJECT_TYPE",19 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID", "A208"."OBJ#" "OBJECT_ID", "A208"."FILE#" "HEADER_FILE", "A208"."BLOCK#" "HEADER_BLOCK", "A208"."TS#" "TS_NUMBER" FROM "SYS"."TABPART$" "A208") UNION ALL (SELECT 'CLUSTER' "OBJECT_TYPE",3 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID", "A207"."OBJ#" "OBJECT_ID", "A207"."FILE#" "HEADER_FILE", "A207"."BLOCK#" "HEADER_BLOCK", "A207"."TS#" "TS_NUMBER" FROM "SYS"."CLU$" "A207") UNION ALL (SELECT DECODE("A206"."TYPE#",8,'LOBINDEX','INDEX') "OBJECT_TYPE",1 "OBJECT_TYPE_ID",6 "SEGMENT_TYPE_ID", "A206"."OBJ#" "OBJECT_ID", "A206"."FILE#" "HEADER_FILE", "A206"."BLOCK#" "HEADER_BLOCK", "A206"."TS#" "TS_NUMBER" FROM "SYS"."IND$" "A206" WHERE "A206"."TYPE#"=1 OR "A206"."TYPE#"=2 OR "A206"."TYPE#"=3 OR "A206"."TYPE#"=4 OR "A206"."TYPE#"=6 OR
  • 88. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 88 "A205"."TS#" "TS_NUMBER" FROM "SYS"."INDPART$" "A205") UNION ALL (SELECT 'LOBSEGMENT' "OBJECT_TYPE",21 "OBJECT_TYPE_ID",8 "SEGMENT_TYPE_ID", "A204"."LOBJ#" "OBJECT_ID", "A204"."FILE#" "HEADER_FILE", "A204"."BLOCK#" "HEADER_BLOCK", "A204"."TS#" "TS_NUMBER" FROM "SYS"."LOB$" "A204" WHERE BITAND("A204"."PROPERTY",64)=0 OR BITAND("A204"."PROPERTY",128)=128) UNION ALL (SELECT 'TABLE SUBPARTITION' "OBJECT_TYPE",34 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID", "A203"."OBJ#" "OBJECT_ID", "A203"."FILE#" "HEADER_FILE", "A203"."BLOCK#" "HEADER_BLOCK", "A203"."TS#" "TS_NUMBER" FROM "SYS"."TABSUBPART$" "A203") UNION ALL (SELECT 'INDEX SUBPARTITION' "OBJECT_TYPE",35 "OBJECT_TYPE_ID",6 "SEGMENT_TYPE_ID", "A202"."OBJ#" "OBJECT_ID", "A202"."FILE#" "HEADER_FILE", "A202"."BLOCK#" "HEADER_BLOCK", "A202"."TS#" "TS_NUMBER" FROM "SYS"."INDSUBPART$" "A202") UNION ALL (SELECT DECODE("A201"."FRAGTYPE$",'P','LOB PARTITION','LOB SUBPARTITION') "OBJECT_TYPE",DECODE("A201"."FRAGTYPE$",'P',40,41) "OBJECT_TYPE_ID",8 "SEGMENT_TYPE_ID", "A201"."FRAGOBJ#" "OBJECT_ID", "A201"."FILE#" "HEADER_FILE", "A201"."BLOCK#" "HEADER_BLOCK", "A201"."TS#" "TS_NUMBER" FROM "SYS"."LOBFRAG$" "A201")) "A196", "SYS"."SEG$" "A195",
  • 89. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 89 "A195"."FILE#"="A194"."RELFILE#") UNION ALL (SELECT NVL("A193"."NAME",'SYS') "OWNER", "A191"."NAME" "SEGMENT_NAME",NULL "PARTITION_NAME", DECODE("A190"."TYPE#",1,'ROLLBACK',10,'TYPE2 UNDO') "SEGMENT_TYPE", "A190"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE", "A192"."TS#" "TABLESPACE_ID", "A192"."NAME" "TABLESPACE_NAME", "A192"."BLOCKSIZE" "BLOCKSIZE", "A189"."FILE#" "HEADER_FILE", "A190"."BLOCK#" "HEADER_BLOCK", "A190"."BLOCKS"*"A192"."BLOCKSIZE" "BYTES", "A190"."BLOCKS" "BLOCKS", "A190"."EXTENTS" "EXTENTS", "A190"."INIEXTS"*"A192"."BLOCKSIZE" "INITIAL_EXTENT", "A190"."EXTSIZE"*"A192"."BLOCKSIZE" "NEXT_EXTENT", "A190"."MINEXTS" "MIN_EXTENTS", "A190"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A190"."SPARE1",4194304),4194304, "A190"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL "MINRETENTION", "A190"."EXTPCT" "PCT_INCREASE",DECODE(BITAND("A192"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A1 90"."LISTS",0,1, "A190"."LISTS")) "FREELISTS",DECODE(BITAND("A192"."FLAGS",32),32,TO_NUMBER(NULL), DECODE("A190"."GROUPS",0,1,"A190"."GROUPS")) "FREELIST_GROUPS", "A190"."FILE#" "RELATIVE_FNO",BITAND("A190"."CACHEHINT",3) "BUFFER_POOL_ID",BITAND("A190"."CACHEHINT",12)/4 "FLASH_CACHE", BITAND("A190"."CACHEHINT",48)/16 "CELL_FLASH_CACHE",NVL("A190"."SPARE1",0) "SEGMENT_FLAGS",
  • 90. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 90 "A191"."TS#"="A189"."TS#" AND "A191"."FILE#"="A189"."RELFILE#") UNION ALL (SELECT NVL("A188"."NAME",'SYS') "OWNER", TO_CHAR("A185"."FILE#")||'.'||TO_CHAR("A186"."BLOCK#") "SEGMENT_NAME",NULL "PARTITION_NAME", DECODE("A186"."TYPE#",2,'DEFERRED ROLLBACK',3, 'TEMPORARY',4,'CACHE',9,'SPACE HEADER','UNDEFINED') "SEGMENT_TYPE", "A186"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE", "A187"."TS#" "TABLESPACE_ID", "A187"."NAME" "TABLESPACE_NAME", "A187"."BLOCKSIZE" "BLOCKSIZE", "A185"."FILE#" "HEADER_FILE", "A186"."BLOCK#" "HEADER_BLOCK", "A186"."BLOCKS"*"A187"."BLOCKSIZE" "BYTES", "A186"."BLOCKS" "BLOCKS", "A186"."EXTENTS" "EXTENTS", "A186"."INIEXTS"*"A187"."BLOCKSIZE" "INITIAL_EXTENT", "A186"."EXTSIZE"*"A187"."BLOCKSIZE" "NEXT_EXTENT", "A186"."MINEXTS" "MIN_EXTENTS", "A186"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A186"."SPARE1",4194304),4194304, "A186"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL "MINRETENTION",DECODE(BITAND("A187"."FLAGS",3),1,TO_NUMBER(NULL), "A186"."EXTPCT") "PCT_INCREASE",DECODE(BITAND("A187"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A1 86"."LISTS",0,1, "A186"."LISTS")) "FREELISTS",DECODE(BITAND("A187"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A186" ."GROUPS",0,1,
  • 91. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 91 "A186"."TYPE#"<>6 AND "A186"."TYPE#"<>8 AND "A186"."TYPE#"<>10 AND "A186"."TYPE#"<>11 AND "A186"."TS#"="A185"."TS#" AND "A186"."FILE#"="A185"."RELFILE#") UNION ALL (SELECT NVL("A184"."NAME",'SYS') "OWNER",'HEATMAP' "SEGMENT_NAME", NULL "PARTITION_NAME",'SYSTEM STATISTICS' "SEGMENT_TYPE", "A182"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE", "A183"."TS#" "TABLESPACE_ID", "A183"."NAME" "TABLESPACE_NAME", "A183"."BLO CKSIZE" "BLOCKSIZE", "A181"."FILE#" "HEADER_FILE", "A182"."BLOCK#" "HEADER_BLOCK", "A182"."BLOCKS"*"A183"."BLOCKSIZE" "BYTES", "A182"."BLOCKS" "BLOCKS", "A182"."EXTENTS" "EXTENTS", "A182"."INIEXTS"*"A183"."BLOCKSIZE" "INITIAL_EXTENT", "A182"."EXTSIZE"*"A183"."BLOCKSIZE" "NEXT_EXTENT", "A182"."MINEXTS" "MIN_EXTENTS", "A182"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A182"."SPARE1",4194304),4194304, "A182"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL "MINRETENTION",DECODE(BITAND("A183"."FLAGS",3),1,TO_NUMBER(NULL), "A182"."EXTPCT") "PCT_INCREASE",DECODE(BITAND("A183"."FLAGS",32),32,TO_NUMBER(NULL),DEC
  • 92. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 92 "SYS"."TS$" "A183", "SYS"."SEG$" "A182", "SYS"."FILE$" "A181" WHERE "A182"."TS#"="A183"."TS#" AND "A182"."USER#"="A184"."USER#"(+) AND "A182"."TYPE#"=11 AND "A182"."TS#"="A181"."TS#" AND "A182"."FILE#"="A181"."RELFILE#")) "A4") "A3", (SELECT "A5"."NAME" "OWNER", "A6"."NAME" "OBJECT_NAME", "A6"."SUBNAME" "SUBOBJECT_NAME", "A6"."OBJ#" "OBJECT_ID", "A6"."DATAOBJ#" "DATA_OBJECT_ID",DECODE("A6"."TYPE#",0,'NEXT OBJECT',1,'INDEX', 2,'TABLE',3,'CLUSTER',4,'VIEW',5,'SYNONYM ',6,'SEQUENCE',7,'PROCEDURE',8,'FUNCTION',9,'PACKAGE',11,'PACKAGE BODY',12, 'TRIGGER',13,'TYPE',14,'TYPE BODY',19,'TABLE PARTITION',20,'INDEX PARTITION', 21,'LOB',22,'LIBRARY',23,'DIRECTORY',24,'QUEUE',28,'JAVA SOURCE',29,'JAVA CLASS',30, 'JAVA RESOURCE',32,'INDEXTYPE',33,'OPERATOR',34, 'TABLE SUBPARTITION',35,'INDEX SUBPARTITION',40,'LOB PARTITION',41,'LOB SUBPARTITION',42 ,NVL( (SELECT 'REWRITE EQUIVALENCE' "'REWRITEEQUIVALENCE'" FROM SYS."SUM$" "A52" WHERE "A52"."OBJ#"="A6"."OBJ#" AND BITAND("A52"."XPFLAGS",8388608)=8388608),'MATERIALIZED VIEW'),43,'DIMENSION', 44,'CONTEXT',46,'RULE SET',47,'RESOURCE PLAN',48,'CONSUMER GROUP',55,'XML SCHEMA',56,'JAVA DATA',57,'EDITION',59,'RULE', 60,'CAPTURE',61,'APPLY',62,'EVALUATION CONTEXT',66,'JOB',67,'PROGRAM',68,'JOB CLASS',69, 'WINDOW',72,'SCHEDULER GROUP',74,'SCHEDULE',79,'CHAIN',81,'FILE GROUP',82,'MINING MODEL',87,'ASSEMBLY',90,'CREDENTIAL',92,'CUBE DIMENSION',93,'CUBE',94,'MEASURE FOLDER',95,'CUBE BUILD PROCESS',100,'FILE WATCHER', 101,'DESTINATION',114,'SQL TRANSLATION PROFILE',115,'UNIFIED AUDIT POLICY','UNDEFINED') "OBJECT_TYPE", "A6"."CTIME" "CREATED",
  • 93. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 16 ... 93 more pages
  • 94. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle back to temporal validity 94
  • 95. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> variable c clob SQL> begin 2 dbms_utility.expand_sql_text( 3 q'{select * from emp_temporal 4 as of period for valid_range '01-FEB-14'}',:c); 6 end; 7 /
  • 96. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> print c C ------------------------------------------------ SELECT "A1"."EMPNO" ... FROM ( SELECT "A2"."EMPNO" "EMPNO", "A2"."NAME" FROM "SCOTT"."EMP_TEMPORAL" "A2" WHERE ("A2"."START_DT" IS NULL OR "A2"."START_DT"<='01-FEB-14') AND ("A2"."END_DT" IS NULL OR "A2"."END_DT">'01-FEB-14') ) "A1" 96
  • 97. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle existing tables 97
  • 98. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> desc EMPLOYEE Name Null? Type ------------------------- -------- --------------- EMPNO NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(12,2) DEPTNO NUMBER(2) SQL> alter table EMPLOYEE add period for TIME_RANGE; Table altered. 98
  • 99. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> desc EMPLOYEE Name Null? Type ------------------------- -------- --------------- EMPNO NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(12,2) DEPTNO NUMBER(2) still looks the same ? 99
  • 100. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select column_name , hidden_column 2 from USER_TAB_COLS 3 where table_name = 'EMPLOYEE' 4 order by column_id; COLUMN_NAME HIDDEN_COLUMN ------------------------------ ------------- EMPNO NO ENAME NO JOB NO MGR NO HIREDATE NO SAL NO COMM NO DEPTNO NO TIME_RANGE_START YES TIME_RANGE_END YES TIME_RANGE YES 100
  • 101. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle multi temporal validity 101
  • 102. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> alter table EMP_TEMPORAL add period for CAL_RANGE; Table altered. SQL> alter table EMP_TEMPORAL add period for FINYR_RANGE; Table altered. 102
  • 103. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "room to grow" 103
  • 104. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle no temporal constraints 104
  • 105. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> alter table EMP_TEMPORAL add primary key (empno); Table altered. SQL> insert into EMP_TEMPORAL 2 (empno, name, start_dt, end_dt ) 3 values (20,'BROWN', '01-FEB-14','01-MAR-14'); 1 row created. SQL> insert into EMP_TEMPORAL 2 (empno, name, start_dt, end_dt ) 3 values (20,'BROWN', '01-MAY-14','01-SEP-14'); insert into EMP_TEMPORAL * ERROR at line 1: ORA-00001: unique constraint (SYS_C009892) violated 105
  • 106. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle add START_DT to primary key ?
  • 107. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle no temporal validation 107
  • 108. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> insert into EMP_TEMPORAL 2 (empno, name, start_dt, end_dt ) 3 values (10,'JONES', '01-JAN-14','01-MAY-14'); 1 row created. SQL> insert into EMP_TEMPORAL 2 (empno, name, start_dt, end_dt ) 3 values (10,'JONES', '01-FEB-14','01-MAR-14'); 1 row created.
  • 109. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle no (native) temporal DML 109
  • 110. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> update EMP_TEMPORAL 2 as of period for valid_range '01-FEB-14' 3 set sal = 10 4 where empno = 20; as of period for valid_range '01-FEB-14' * ERROR at line 2: ORA-08187: snapshot expression not allowed here 110
  • 111. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> update 2 ( select * from EMP_TEMPORAL 3 as of period for valid_range '01-FEB-14' 4 ) 5 set sal = 10 6 where empno = 20; 1 row updated. 111
  • 112. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle take note ..
  • 113. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "Temporal validity is not supported with a multitenant container database" 113 12.1.0.1
  • 114. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Favourite: top-n simplifications 114
  • 115. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "5 most recently hired employees" 115
  • 116. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 where rownum <= 5 4 order by hiredate desc; EMPNO ENAME HIREDATE ---------- ---------- ------------------- 7654 MARTIN 28/09/1981 00:00:00 7566 JONES 02/04/1981 00:00:00 7521 WARD 22/02/1981 00:00:00 7499 ALLEN 20/02/1981 00:00:00 7369 SMITH 17/12/1980 00:00:00 116
  • 117. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle inline view 117
  • 118. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * 2 from ( 3 select empno, ename, hiredate 4 from emp 5 order by hiredate desc 6 ) 7 where rownum <= 5; EMPNO ENAME HIREDATE ---------- ---------- --------- 7876 ADAMS 23-MAY-87 7788 SCOTT 19-APR-87 ... 118
  • 119. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ------------------------------------------------ | Id | Operation | Name | Rows | ------------------------------------------------ | 0 | SELECT STATEMENT | | 5 | |* 1 | COUNT STOPKEY | | | | 2 | VIEW | | 14 | |* 3 | SORT ORDER BY STOPKEY| | 14 | | 4 | TABLE ACCESS FULL | EMP | 14 | ------------------------------------------------ 119
  • 120. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * 2 from ( 3 select 4 empno, ename, hiredate, 5 row_number() over ( order by hiredate desc) rn 6 from emp 7 ) 8 where rn <= 5; 120
  • 121. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ------------------------------------------------- | Id | Operation | Name | Rows | ------------------------------------------------- | 0 | SELECT STATEMENT | | 14 | |* 1 | VIEW | | 14 | |* 2 | WINDOW SORT PUSHED RANK| | 14 | | 3 | TABLE ACCESS FULL | EMP | 14 | ------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("RN"<=5) 2 - filter(ROW_NUMBER() OVER ( ORDER BY HIREDATE") DESC )<=5) 121
  • 122. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 12c .... easier 122
  • 123. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 fetch first 5 rows only; EMPNO ENAME HIREDATE ---------- ---------- --------- 7876 ADAMS 23-MAY-87 7788 SCOTT 19-APR-87 ... 123
  • 124. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle behind the scenes 124
  • 125. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ------------------------------------------------- | Id | Operation | Name | Rows | ------------------------------------------------- | 0 | SELECT STATEMENT | | 14 | |* 1 | VIEW | | 14 | |* 2 | WINDOW SORT PUSHED RANK| | 14 | | 3 | TABLE ACCESS FULL | EMP | 14 | ------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("from$_subquery$_002". "rowlimit_$$_rownumber"<=5) 2 - filter(ROW_NUMBER() OVER ( ORDER BY HIREDATE") DESC )<=5) 125
  • 126. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle variations 126
  • 127. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 fetch first 1 row only; EMPNO ENAME HIREDATE ---------- ---------- --------- 7876 ADAMS 23-MAY-87 127
  • 128. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 fetch first 5 row only; EMPNO ENAME HIREDATE ---------- ---------- --------- 7876 ADAMS 23-MAY-87 7788 SCOTT 19-APR-87 7934 MILLER 23-JAN-82 7900 JAMES 03-DEC-81 7902 FORD 03-DEC-81 128
  • 129. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 fetch first 10 percent rows only; EMPNO ENAME HIREDATE ---------- ---------- --------- 7876 ADAMS 23-MAY-87 7788 SCOTT 19-APR-87 129
  • 130. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle pagination 130
  • 131. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 offset 5 rows fetch next 3 rows only; EMPNO ENAME HIREDATE ---------- ---------- --------- 7839 KING 17-NOV-81 7654 MARTIN 28-SEP-81 7844 TURNER 08-SEP-81 131
  • 132. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle can mimic rownum 132
  • 133. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 fetch first 3 rows only; EMPNO ENAME HIREDATE ---------- ---------- --------- 7369 SMITH 17-DEC-80 7499 ALLEN 20-FEB-81 7521 WARD 22-FEB-81 133
  • 134. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ----------------------------------------------- | Id | Operation | Name | Rows | ----------------------------------------------- | 0 | SELECT STATEMENT | | 14 | |* 1 | VIEW | | 14 | |* 2 | WINDOW NOSORT STOPKEY| | 14 | | 3 | TABLE ACCESS FULL | EMP | 14 | ----------------------------------------------- 1 - filter("from$_subquery$_002"."rowlimit_$ 2 - filter(ROW_NUMBER() OVER ( ORDER BY NULL ) <= 3 134
  • 135. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle things to note 135
  • 136. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 fetch LAST 5 rows only; fetch LAST 5 rows only * ERROR at line 4: ORA-00905: missing keyword 136
  • 137. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * 2 from ( 3 select empno, ename, hiredate 4 from emp 5 order by hiredate asc 6 fetch first 5 rows only 7 ) 8 order by hiredate desc; EMPNO ENAME HIREDATE ---------- ---------- --------- 7698 BLAKE 01-MAY-81 7566 JONES 02-APR-81 7521 WARD 22-FEB-81 7499 ALLEN 20-FEB-81 7369 SMITH 17-DEC-80 137
  • 138. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle or ... 138
  • 139. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 offset ( select count(*)-5 from emp) rows 5 fetch first 5 rows only; EMPNO ENAME HIREDATE ---------- ---------- --------- 7698 BLAKE 01-MAY-81 7566 JONES 02-APR-81 7521 WARD 22-FEB-81 7499 ALLEN 20-FEB-81 7369 SMITH 17-DEC-80 139
  • 140. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ---------------------------------------------- | Id | Operation | Name | Rows | ---------------------------------------------- | 0 | SELECT STATEMENT | | 14 | |* 1 | VIEW | | 14 | | 2 | WINDOW SORT | | 14 | | 3 | TABLE ACCESS FULL| EMP | 14 | | 4 | SORT AGGREGATE | | 1 | | 5 | INDEX FULL SCAN | PK_EMP | 14 | ---------------------------------------------- 140 ugh
  • 141. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle no percent pagination 141
  • 142. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 offset 20 percent fetch 5 next 10 percent rows only; offset 20 percent fetch next 10 percent rows only * ERROR at line 4: ORA-00905: missing keyword 142
  • 143. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 offset 5 ( select 20/100*count(*) from emp) rows 6 fetch next 10 percent rows only; EMPNO ENAME HIREDATE ---------- ---------- --------- 7934 MILLER 23-JAN-82 7902 FORD 03-DEC-81 143
  • 144. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle PL/SQL quirk 144
  • 145. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "Note that in real life, you would use bind variables instead of hard-coded literals" 145 - Tom Kyte, Oracle Magazine
  • 146. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> variable x number SQL> exec :x := 5 PL/SQL procedure successfully completed. SQL> select empno, ename, hiredate 2 from emp 3 order by hiredate desc 4 fetch first :x rows only; EMPNO ENAME HIREDATE ---------- ---------- --------- 7876 ADAMS 23-MAY-87 7788 SCOTT 19-APR-87 7934 MILLER 23-JAN-82 7900 JAMES 03-DEC-81 7902 FORD 03-DEC-81 146
  • 147. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> declare 2 l_num number := 5; 3 begin 4 for i in ( 5 select empno, ename, hiredate 6 from emp 7 order by hiredate desc 8 fetch first l_num rows only 9 ) 10 loop 11 null; 12 end loop; 13 end; 14 / ERROR at line 1: ORA-03113: end-of-file on communication channel Process ID: 26618 Session ID: 25 Serial number: 53023 147
  • 148. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> declare 2 l_num number := 5; 3 begin 4 for i in ( 5 select empno, ename, hiredate 6 from emp 7 order by hiredate desc 8 fetch first cast(l_num as number) rows only 9 ) 10 loop 11 null; 12 end loop; 13 end; 14 / PL/SQL procedure successfully completed. 148
  • 149. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Favourite: pattern matching 149
  • 150. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle analytics ... since 8.1.6 150 median top n moving average etc
  • 151. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "analysis" often "patterns" 151
  • 152. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle real example 152
  • 153. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 153
  • 154. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle AML 154 anti-money laundering
  • 155. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "Find 10 consecutive deposits in a 24 hour period, then a withdrawal within three days of the last deposit, at a different outlet" 155
  • 156. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ACCT TSTAMP WTHD_TSTAMP T AMT ---------- ------------------ ------------------ - ---------- 54261 25/01/13 17:20:55 D 100 54261 25/01/13 17:56:58 D 165 54261 26/01/13 11:24:14 D 30 54261 26/01/13 11:47:53 D 45 54261 26/01/13 12:59:38 D 100 54261 26/01/13 13:26:04 D 80 54261 26/01/13 14:41:09 D 50 54261 26/01/13 14:53:12 D 50 54261 26/01/13 15:15:05 D 50 54261 26/01/13 15:51:17 D 50 54261 26/01/13 16:15:02 D 120 54261 26/01/13 16:36:51 D 100 54261 26/01/13 16:55:09 D 100 54261 26/01/13 18:07:17 26/01/13 18:07:17 W -500 156
  • 157. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle hard... 157
  • 158. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle pattern matching 158
  • 159. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select acct, tstamp, wthd_tstamp, txn_type, amt 2 from account_txns 3 MATCH_RECOGNIZE 4 ( 5 partition by acct 6 order by tstamp 7 measures 8 dep.tstamp dep_tstamp, 9 wthd.tstamp wthd_tstamp 10 11 all rows per match 12 pattern ( dep{10,} wthd ) 13 define 14 dep as 15 txn_type = 'D', 16 wthd as 17 txn_type = 'W' 18 and last(dep.tstamp)-first(dep.tstamp) < interval '1' day 19 and wthd.tstamp - last(dep.tstamp) < interval '3' day 20 and wthd.location != last(dep.location) 21 ) 159
  • 160. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Favourite: join enhancements
  • 161. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 11.2 161
  • 162. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> create table emp2 as 2 select * from emp; Table created. SQL> select * 2 from emp e, 3 emp2 e2, 4 dept d 5 where e.deptno = d.deptno(+) 6 and e2.deptno = d.deptno(+) 7 and e.empno = e2.empno 8 / where e.deptno = d.deptno(+) * ERROR at line 5: ORA-01417: a table may be outer joined to at most one other table 162
  • 163. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle but ANSI syntax works … 163
  • 164. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 12c 164
  • 165. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * 2 from emp e, 3 emp2 e2, 4 dept d 5 where e.deptno = d.deptno(+) 6 and e2.deptno = d.deptno(+) 7 and e.empno = e2.empno 8 / EMPNO ENAME JOB MGR ---------- ---------- --------- ---------- 7934 MILLER CLERK 7782 ... 165
  • 166. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle correlated inline views 166
  • 167. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> create table DEPT_BENEFITS as 2 select d.*, 10 benefits from dept d; Table created. SQL> insert into DEPT_BENEFITS 2 select d.*, 20 benefits from dept d; 4 rows created. 167
  • 168. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select e.empno, e.deptno, d.benefits 2 from emp e, 3 DEPT_BENEFITS d 4 where e.deptno = d.deptno 5 order by 1,3; EMPNO DEPTNO BENEFITS ---------- ---------- ---------- 7369 20 10 7369 20 20 7499 30 10 7499 30 20 7521 30 10 7521 30 20 ... ... 168
  • 169. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "benefits for each employee" 169
  • 170. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select e.empno, d.deptno, b.benefits 2 from emp e, 3 ( select benefits 4 from DEPT_BENEFITS d 5 where d.deptno = e.deptno 6 ) b 7 order by 1,3; where d.deptno = e.deptno * ERROR at line 5: ORA-00904: "E"."DEPTNO": invalid identifier 170
  • 171. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle CROSS APPLY 171
  • 172. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select e.empno, e.deptno, b.benefits 2 from emp e 3 CROSS APPLY 4 ( select benefits 5 from DEPT_BENEFITS d 6 where d.deptno = e.deptno 7 ) b 8 order by 1,3; EMPNO DEPTNO BENEFITS ---------- ---------- ---------- 7369 20 10 7369 20 20 7499 30 10 ... ...
  • 173. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "big deal" 173
  • 174. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select e.empno, d.deptno, b.benefits 2 from emp e, 3 ( select benefits 4 from DEPT_BENEFITS d 5 6 ) b 7 8 order by 1,3; where d.deptno = e.deptno 174
  • 175. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "best benefit for each employee" 175
  • 176. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select e.empno, e.deptno, b.benefits 2 from emp e 3 CROSS APPLY 4 ( select benefits 5 from DEPT_BENEFITS d 6 where d.deptno = e.deptno 7 order by benefits desc 8 fetch first 1 rows only 9 ) b 10 order by 1,3; EMPNO DEPTNO BENEFITS ---------- ---------- ---------- 7369 20 20 7499 30 20 7521 30 20 7566 20 20 7654 30 20 ... 176
  • 177. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Favourite: DML error logging 177
  • 178. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> insert /*+ APPEND */ into MY_TABLE 2 select * 3 from MY_WHOPPING_GREAT_FAT_TABLE; 178 MY_WHOPPING_GREAT_FAT_TABLE;
  • 179. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 179
  • 180. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 180
  • 181. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 181
  • 182. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 182
  • 183. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 183
  • 184. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> insert /*+ APPEND */ into MY_TABLE 2 select * 3 from MY_WHOPPING_GREAT_FAT_TABLE; Elapsed: 06:12:34.00 184
  • 185. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> insert /*+ APPEND */ into MY_TABLE 2 select * 3 from MY_WHOPPING_GREAT_FAT_TABLE; Elapsed: 06:12:34.00 ERROR at line 1: ORA-00001: unique constraint (DEMO.WHOPPER_PK) violated 185
  • 186. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select count(*) from MY_TABLE; COUNT(*) ---------- 0 186
  • 187. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle what we want 187
  • 188. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle keep successful rows 188
  • 189. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle skip / bypass bad rows 189
  • 190. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> insert /*+ APPEND */ into MY_TABLE 2 select * 3 from MY_WHOPPING_GREAT_FAT_TABLE 4 where "not a duplicate" 5 and "datatypes are ok" 6 and "foreign keys are ok" 7 and "check constraints are ok" 190
  • 191. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> exec DBMS_ERRLOG.CREATE_ERROR_LOG('EMP') 191
  • 192. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ERR$_EMP 192
  • 193. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle DBMS_ERRLOG.CREATE_ERROR_LOG ( dml_table_name IN VARCHAR2, err_log_table_name IN VARCHAR2 := NULL, err_log_table_owner IN VARCHAR2 := NULL, ... 193
  • 194. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> desc ERR$_EMP Name Null? Type ----------------------------- -------- ---------------- ORA_ERR_NUMBER$ NUMBER ORA_ERR_MESG$ VARCHAR2(2000) ORA_ERR_ROWID$ ROWID ORA_ERR_OPTYP$ VARCHAR2(2) ORA_ERR_TAG$ VARCHAR2(2000) EMPNO VARCHAR2(4000) ENAME VARCHAR2(4000) JOB VARCHAR2(4000) MGR VARCHAR2(4000) HIREDATE VARCHAR2(4000) SAL VARCHAR2(4000) COMM VARCHAR2(4000) DEPTNO VARCHAR2(4000) 194
  • 195. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 195
  • 196. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle demo 196
  • 197. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * from NEW_DATA; EMPNO SAL DEPTNO ---------- ---------- ---------- 1000 5000 20 100X 3550 10 2000 2500 50 7934 4000 20 197 non-numeric no dept 50 duplicate
  • 198. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> exec dbms_errlog.create_error_log( 'EMP' ); PL/SQL procedure successfully completed. SQL> insert into EMP (empno,sal,deptno) 2 select empno,sal,deptno 3 from NEW_DATA 4 LOG ERRORS REJECT LIMIT UNLIMITED; 1 row created. 198 50
  • 199. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select ORA_ERR_OPTYP$ op, ORA_ERR_MESG$, EMPNO 2 from ERR$_EMP OP ORA_ERR_MESG$ EMPNO -- ------------------------------------------------------------ ----- I ORA-01722: invalid number 100X I ORA-02291: integrity constraint (SCOTT.FK_DEPTNO) violated 2000 I ORA-00001: unique constraint (SCOTT.PK_EMP) violated 7934 199
  • 200. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle favourite: query blocks 200
  • 201. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle201 C# application
  • 202. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle202
  • 203. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle C#, C++ 203
  • 204. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle C#, C++ PL/SQL 204
  • 205. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle No comments 205
  • 206. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 206
  • 207. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "C# is self-documenting" 207
  • 208. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle good code in any language ... 208
  • 209. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ... should self document 209
  • 210. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL is no different 210
  • 211. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle select emp.* from emp, ( select trunc(hiredate,'YYYY'), max(empno) empno from emp where empno > 0 group by trunc(hiredate,'YYYY') ) x, ( select deptno, avg(sal) from emp group by deptno ) y where x.empno = emp.empno and y.deptno = emp.deptno
  • 212. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Explain plan
  • 213. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Id | Operation | Name | ----------------------------------------------| 0 | SELECT STATEMENT | | 1 | HASH JOIN | | 2 | TABLE ACCESS BY INDEX ROWID | EMP | 3 | NESTED LOOPS | | 4 | VIEW | | 5 | SORT GROUP BY | | 6 | TABLE ACCESS BY INDEX ROWID| EMP | 7 | INDEX FULL SCAN | E2 | 8 | INDEX RANGE SCAN | E1 | 9 | VIEW | | 10 | SORT GROUP BY | | 11 | TABLE ACCESS BY INDEX ROWID | EMP | 12 | INDEX RANGE SCAN | E2 |
  • 214. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle
  • 215. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle explain plan for select emp.* from emp, ( select /*+ QB_NAME(lastemp) */ trunc(hiredate,'YYYY'), max(empno) empno from emp where empno > 0 group by trunc(hiredate,'YYYY') ) x, ( select /*+ QB_NAME(avgsal) */ deptno, avg(sal) from emp group by deptno ) y where x.empno = emp.empno and y.deptno = emp.deptno explain plan for select emp.* from emp, ( select /*+ QB_NAME(lastemp) */ trunc(hiredate,'YYYY'), max(empno) empno from emp where empno > 0 group by trunc(hiredate,'YYYY') ) x, ( select /*+ QB_NAME(avgsal) */ deptno, avg(sal) from emp group by deptno ) y where x.empno = emp.empno and y.deptno = emp.deptno
  • 216. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle explain plan for select emp.* from emp, ( select /*+ QB_NAME(lastemp) */ trunc(hiredate,'YYYY'), max(empno) empno from emp where empno > 0 group by trunc(hiredate,'YYYY') ) x, ( select /*+ QB_NAME(avgsal) */ deptno, avg(sal) from emp group by deptno ) y where x.empno = emp.empno and y.deptno = emp.deptno
  • 217. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Id | Operation | Name | ----------------------------------------------| 0 | SELECT STATEMENT | | 1 | HASH JOIN | | 2 | TABLE ACCESS BY INDEX ROWID | EMP | 3 | NESTED LOOPS | | 4 | VIEW | | 5 | SORT GROUP BY | | 6 | TABLE ACCESS BY INDEX ROWID| EMP | 7 | INDEX FULL SCAN | E2 | 8 | INDEX RANGE SCAN | E1 | 9 | VIEW | | 10 | SORT GROUP BY | | 11 | TABLE ACCESS BY INDEX ROWID | EMP | 12 | INDEX RANGE SCAN | E2 | Query Block Name / Alias (identified by operation id): --------------------------------------------------------- 1 - SEL$1 3 - AVGSAL / Y@SEL$1 4 - AVGSAL 5 - AVGSAL / EMP@AVGSAL 6 - SEL$1 / EMP@SEL$1 7 - LASTEMP / X@SEL$1 8 - LASTEMP 9 - LASTEMP / EMP@LASTEMP
  • 218. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle query PLAN_TABLE
  • 219. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Id | Operation | Name | Query Block ----------------------------------------------|-------------- 0 | SELECT STATEMENT | | 1 | HASH JOIN | | 2 | TABLE ACCESS BY INDEX ROWID | EMP | 3 | NESTED LOOPS | | 4 | VIEW | | 5 | SORT GROUP BY | | 6 | TABLE ACCESS BY INDEX ROWID| EMP | 7 | INDEX FULL SCAN | E2 | 8 | INDEX RANGE SCAN | E1 | 9 | VIEW | | 10 | SORT GROUP BY | | 11 | TABLE ACCESS BY INDEX ROWID | EMP | 12 | INDEX RANGE SCAN | E2 | SEL$4ADCCA61 SEL$4ADCCA61 AVGSAL AVGSAL AVGSAL AVGSAL SEL$4ADCCA61 LASTEMP LASTEMP LASTEMP LASTEMP
  • 220. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Runtime statistics as well
  • 221. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select /*+ gather_plan_statistics */ 2 emp.* 3 from emp, 4 ( select /*+ QB_NAME(lastemp) */ 5 trunc(hiredate,'YYYY'), max(empno) empno 6 from emp 7 where empno > 0 8 group by trunc(hiredate,'YYYY') ) x, 9 ( select /*+ QB_NAME(avgsal) */ 10 deptno, avg(sal) 11 from emp 12 group by deptno ) y 13 where x.empno = emp.empno 14 and y.deptno = emp.deptno 15 /
  • 222. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * from 2 table(dbms_xplan.display_cursor(null,null,'IOSTATS LAST +ALIAS')); ----------------------------------------------------------------------------------- |Id | Operation | Name |Starts | E-Rows | A-Rows |A-Time | Buffers | ----------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 4 |00:00.01 | 21 | | 1 | HASH JOIN | | 1 | 13 | 4 |00:00.01 | 21 | | 2 | HASH JOIN | | 1 | 14 | 14 |00:00.01 | 14 | | 3 | VIEW | | 1 | 3 | 3 |00:00.01 | 7 | | 4 | HASH GROUP BY | | 1 | 3 | 3 |00:00.01 | 7 | | 5 | TABLE ACCESS FULL| EMP | 1 | 14 | 14 |00:00.01 | 7 | | 6 | TABLE ACCESS FULL | EMP | 1 | 14 | 14 |00:00.01 | 7 | | 7 | VIEW | | 1 | 13 | 4 |00:00.01 | 7 | | 8 | HASH GROUP BY | | 1 | 13 | 4 |00:00.01 | 7 | | 9 | TABLE ACCESS FULL | EMP | 1 | 14 | 14 |00:00.01 | 7 | ----------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 3 - AVGSAL / Y@SEL$1 4 - AVGSAL 5 - AVGSAL / EMP@AVGSAL 6 - SEL$1 / EMP@SEL$1 7 - LASTEMP / X@SEL$1 8 - LASTEMP 9 - LASTEMP / EMP@LASTEMP
  • 223. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> alter session set 2 events = '10053 trace name context forever, level 1'; Session altered. 223
  • 224. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle ************************** Query transformations (QT) ************************** CBQT: Validity checks passed for 7jpzpr2475cqw. CSE: Sub-expression elimination in query block SEL$1 (#0) ************************* Common Subexpression elimination (CSE) ************************* CSE: CSE not performed on query block LAST_EMP(#0). CSE: Sub-expression elimination in query block AVG_SAL (#0) CSE: CSE not performed on query block AV_SAL (#0). CSE: CSE not performed on query block SEL$1 (#0). *************************** Order-by elimination (OBYE) *************************** OBYE: Considering Order-by Elimination from view SEL$1 (#0) 224
  • 225. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle assist with hints 225
  • 226. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle select /*+ QB_NAME(top) INDEX(@yr_hire emp (empno)) FULL(@av_sal emp) */ emp.* from emp, ( select /*+ QB_NAME(YR_HIRE) */ trunc(hiredate,'YYYY'), max(empno) empno from emp where empno > 0 group by trunc(hiredate,'YYYY') ) x, ( select /*+ QB_NAME(AV_SAL) */ deptno, avg(sal) from emp group by deptno ) y where x.empno = emp.empno and y.deptno = emp.deptno 226
  • 227. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Help the next person
  • 228. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle It’s probably you
  • 229. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Favourite: subquery factoring 229 part 2
  • 230. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle first principles 230
  • 231. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select rpad(' ',level)||ename, 2 from emp 3 start with mgr is null 4 connect by prior empno = mgr ENAME --------------------------- KING BLAKE JAMES ALLEN WARD CLARK MILLER 231
  • 232. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select empno, ename, mgr 2 from emp 3 where mgr is null; EMPNO ENAME MGR ---------- -------------------- ---------- 7839 KING 232
  • 233. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select e2.empno, e2.ename, e2.mgr 2 from emp e2, 3 ( select empno, mgr 4 from emp 5 where mgr is null ) inner 6 where e2.mgr = inner.empno; EMPNO ENAME MGR ---------- -------------------- ---------- 7566 JONES 7839 7698 BLAKE 7839 7782 CLARK 7839 233
  • 234. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select e3.empno, e3.ename, e3.mgr 2 from emp e3, 3 ( select e2.empno, e2.ename, e2.mgr 4 from emp e2, 5 ( select empno, mgr 6 from emp 7 where mgr is null ) inner 8 where e2.mgr = inner.empno ) inner 9 where e3.mgr = inner.empno; EMPNO ENAME MGR ---------- -------------------- ---------- 7902 FORD 7566 7788 SCOTT 7566 7900 JAMES 7698 7844 TURNER 7698 7654 MARTIN 7698 7521 WARD 7698 7934 MILLER 7782 234
  • 235. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select e4.empno, e4.ename, e4.mgr 2 from emp e4, 3 ( select e3.empno, e3.ename, e3.mgr 4 from emp e3, 5 ( select e2.empno, e2.ename, e2.mgr 6 from emp e2, 7 ( select empno, mgr 8 from emp 9 where mgr is null ) inner 10 where e2.mgr = inner.empno ) inner 11 where e3.mgr = inner.empno ) inner 12 where e4.mgr = inner.empno; EMPNO ENAME MGR ---------- -------------------- ---------- 7876 ADAMS 7788 recursive... 235
  • 236. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 236
  • 237. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle WITH can be recursive 237
  • 238. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> with EACH_LEVEL (empno, name, mgr) as 2 ( -- 3 -- start with 4 -- 5 select empno, ename, mgr 6 from emp 7 where mgr is null 8 -- 9 -- connect by 10 -- 11 union all 12 select emp.empno, emp.ename, emp.mgr 13 from emp, EACH_LEVEL 14 where emp.mgr = each_level.empno 15 ) 16 select * 17 from each_level; 238
  • 239. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle EMPNO NAME MGR ---------- --------------- ---------- 7839 KING 7566 JONES 7839 7698 BLAKE 7839 7782 CLARK 7839 7499 ALLEN 7698 7521 WARD 7698 7654 MARTIN 7698 7788 SCOTT 7566 7844 TURNER 7698 7900 JAMES 7698 7902 FORD 7566 7934 MILLER 7782 7369 SMITH 7902 7876 ADAMS 7788 239
  • 240. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle two part structure 240
  • 241. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle with RECURSIVE_WITH (c1,c2,c3) as ( <starting/entry point> union all <recursive relationship> ) select ... from RECURSIVE_WITH 241
  • 242. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle you control pseudo-functions 242
  • 243. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> with each_level (empno, name, mgr, rlevel) as 2 ( select empno, ename, mgr, 1 rlevel 3 from emp 4 where mgr is null 5 union all 6 select emp.empno, emp.ename, emp.mgr, rlevel+1 7 from emp, each_level 8 where emp.mgr = each_level.empno 9 ) 10 select * from each_level; EMPNO NAME MGR RLEVEL ---------- --------------- ---------- ---------- 7839 KING 1 7566 JONES 7839 2 7698 BLAKE 7839 2 7782 CLARK 7839 2 7499 ALLEN 7698 3 <etc> 243
  • 244. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> with each_level (empno, name, mgr, level) as 2 ( select empno, ename, mgr, 1 level 3 from emp 4 where mgr is null 5 union all 6 select emp.empno, emp.ename, emp.mgr, level+1 7 from emp, each_level 8 where emp.mgr = each_level.empno 9 ) 10 select empno, name, mgr, level from each_level; with each_level (empno, name, mgr, level) as * ERROR at line 1: ORA-00904: : invalid identifier 244
  • 245. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> with each_level (empno, name, mgr, rlevel) as 2 ( select empno, ename, mgr, 1 rlevel 3 from emp 4 where mgr is null 5 union all 6 select emp.empno, emp.ename, emp.mgr, rlevel+1 7 from emp, each_level 8 where emp.mgr = each_level.empno 9 ) 10 select empno, name, mgr, rlevel as "LEVEL" 11 from each_level; 245
  • 246. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> with each_level (empno, name, mgr, padding) as 2 ( select empno, ename, mgr, '' padding 3 from emp 4 where mgr is null 5 union all 6 select e.empno, e.ename, e.mgr, padding || ' ' 7 from emp e, each_level 8 where e.mgr = each_level.empno 9 ) 10 select empno, padding||name name 11 from each_level; ERROR: ORA-01489: result of string concatenation is too long 246
  • 247. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> with each_level (empno, name, mgr, padding) as 2 ( select empno, ename, mgr, 3 cast('' as varchar2(100)) padding 4 from emp 5 where mgr is null 6 union all 7 select e.empno, e.ename, e.mgr, padding || ' ' 8 from emp e, each_level 9 where e.mgr = each_level.empno 10 ) 11 select empno, padding||name name 12 from each_level; EMPNO NAME ---------- -------------------------------- 7839 KING 7566 JONES ... 247
  • 248. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> with each_level (empno, name) as 2 ( select empno, ename from emp 3 where mgr is null 4 union all 5 select e.empno, 6 each_level.name||'-'||e.ename 7 from emp e, each_level 8 where e.mgr = each_level.empno 9 ) 10 select empno, name from each_level; EMPNO NAME ---------- -------------------------------- 7839 KING 7566 KING-JONES 7698 KING-BLAKE 7782 KING-CLARK 7499 KING-BLAKE-ALLEN 7521 KING-BLAKE-WARD <etc> 248
  • 249. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle some nice touches... 249
  • 250. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> with each_level (empno, name, hiredate, mgr) as 2 ( ... ) 9 SEARCH BREADTH FIRST BY HIREDATE SET IDX 10 select name, hiredate, idx from each_level; NAME HIREDATE IDX -------------------------------- --------- ---------- KING 17-NOV-81 1 KING-JONES 02-APR-81 2 KING-BLAKE 01-MAY-81 3 KING-CLARK 09-JUN-81 4 KING-BLAKE-ALLEN 20-FEB-81 5 KING-BLAKE-WARD 22-FEB-81 6 [snip] KING-JONES-FORD-SMITH 17-DEC-80 13 KING-JONES-SCOTT-ADAMS 23-MAY-87 14 250
  • 251. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> with each_level (empno, name, hiredate, mgr) as 2 ( ... ) 9 SEARCH DEPTH FIRST BY HIREDATE SET IDX 10 select name, hiredate, idx from each_level; NAME HIREDATE IDX -------------------------------- --------- ---------- KING 17-NOV-81 1 KING-JONES 02-APR-81 2 KING-JONES-FORD 03-DEC-81 3 KING-JONES-FORD-SMITH 17-DEC-80 4 KING-JONES-SCOTT 19-APR-87 5 KING-JONES-SCOTT-ADAMS 23-MAY-87 6 KING-BLAKE 01-MAY-81 7 KING-BLAKE-ALLEN 20-FEB-81 8 etc 251
  • 252. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle get used to it ..... ANSI 252
  • 253. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Favourite: sql transposition 253
  • 254. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle rows to columns, colums to rows 254
  • 255. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "I need sales by product for each quarter....now" 255
  • 256. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select product, 2 trunc(txn_date,'Q') mth, sum(quantity) total 3 from SALES 4 group by product,trunc(txn_date,'Q') 5 order by 1,2; PRODUCT MTH TOTAL -------------------- --- ---------- CHAINSAW JAN 251473 CHAINSAW APR 254830 CHAINSAW JUL 251994 CHAINSAW OCT 243748 HAMMER JAN 249889 HAMMER APR 256566 HAMMER JUL 252992 HAMMER OCT 249104 SCREW DRIVER JAN 245988 SCREW DRIVER APR 249219 SCREW DRIVER JUL 252128 256
  • 257. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "That’s junk...surely you know I wanted it ACROSS the page" 257
  • 258. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 258
  • 259. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 259
  • 260. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle PIVOT clause 260
  • 261. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * 2 from (select product, 3 trunc(txn_date,'Q') mth, 4 quantity 5 from sales ) 6 pivot( sum(quantity) for mth in 7 ( 'JAN','APR','JUL','OCT' ) ) 11 order by 1 12 / PRODUCT 'JAN' 'APR' 'JUL' 'OCT' -------------------- ---------- ---------- ---------- ---------- CHAINSAW 251473 254830 251994 243748 HAMMER 249889 256566 252992 249104 SCREW DRIVER 245988 249219 252128 244721 SPADE 242434 254090 259613 248428 WHEEL BARROW 243899 249327 252296 254137 261
  • 262. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle "nah...make it go DOWN the page 262
  • 263. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> create table PIVOTED_SALES as select * 2 from (select product, 3 trunc(txn_date,'Q') mth, 4 quantity 5 from sales ) 6 pivot( sum(quantity) for mth in 7 ( 'JAN', 8 'APR', 9 'JUL', 10 'OCT') ) 11 order by 1 12 / Table created. 263
  • 264. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle UNPIVOT clause 264
  • 265. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> desc PIVOTED_SALES Name Null? Type ----------------------------- -------- ------------- PRODUCT VARCHAR2(20) Q1 NUMBER Q2 NUMBER Q3 NUMBER Q4 NUMBER 265
  • 266. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL> select * 2 from PIVOTED_SALES 3 UNPIVOT 4 ( quantity for quarter in (Q1,Q2,Q3,Q4) ) 5 / PRODUCT QUARTER QUANTITY -------------------- ------- ---------- CHAINSAW Q1 251473 CHAINSAW Q2 254830 CHAINSAW Q3 251994 CHAINSAW Q4 243748 HAMMER Q1 249889 HAMMER Q2 256566 HAMMER Q3 252992 HAMMER Q4 249104 SCREW DRIVER Q1 245988 SCREW DRIVER Q2 249219 SCREW DRIVER Q3 252128 ... column values become "quantity" column names become "quarter" 266
  • 267. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle elements must be known in advance 267
  • 268. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 268 Wrap up
  • 269. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 269 lots not covered today
  • 270. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle why talk about SQL (reason 4) 270
  • 271. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Life is too short 271 (look away now if you are squeamish)
  • 272. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 272
  • 273. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 273 import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.accessibility.*; import com.sun.java.accessibility.util.*; public AssistiveExample extends JPanel implements MouseMotionListener, ActionListener, GUIInitializedListener { Timer timer; static JFrame frame; JLabel nameLabel = new JLabel(); JLabel descriptionLabel = new JLabel(); JLabel tableLabel = new JLabel(); JCheckBox selectionCheckBox = new JCheckBox("Selection", false); JCheckBox textCheckBox = new JCheckBox("Text", false); JCheckBox valueCheckBox = new JCheckBox("Value", false); JCheckBox componentCheckBox = new JCheckBox("Component", false); JCheckBox actionCheckBox = new JCheckBox("Action", false); JCheckBox hypertextCheckBox = new JCheckBox("Hypertext", false); JCheckBox iconCheckBox = new JCheckBox("Icon", false); JCheckBox tableCheckBox = new JCheckBox("Table", false); JCheckBox editableTextCheckBox = new JCheckBox("EditableText", false); JLabel classLabel = new JLabel(); JLabel parentLabel = new JLabel(); JLabel relationLabel = new JLabel();
  • 274. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL is faster 274
  • 275. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL is easier 275
  • 276. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle 276
  • 277. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle SQL is more exciting 277
  • 278. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle278 Connor McDonaldORA-03113
  • 279. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | @connor_mc_dwww.youtube.com/c/ConnorMcDonaldOracle Creative Commons Image Resources https://commons.wikimedia.org/wiki/File:Horse_Race_Finish_Line_(11888565543).jpg https://pixabay.com/en/iphone-iphone-6-apple-flat-762044/ https://pixabay.com/en/curve-return-pass-road-384406/ https://pixabay.com/en/high-five-figure-man-blue-150911/ https://pixabay.com/en/joker-jester-card-playing-card-164030/ https://commons.wikimedia.org/wiki/File:2008-08-19_Flat_tire.jpg https://upload.wikimedia.org/wikipedia/commons/4/4d/3DCrystal_ball.png