Академический Документы
Профессиональный Документы
Культура Документы
1
12/18/2015
2
12/18/2015
3
12/18/2015
bio
4
12/18/2015
SQL-lectric !!!
Connor McDonald
Developer Advocate for SQL
2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal/Restricted/Highly Restricted
5
12/18/2015
6
12/18/2015
https://www.linkedin.com/groups/Find-out-why-Google-decided-4434815.S.273792742 http://tdwi.org/articles/2013/05/06/facebooks-relational-platform.aspx
7
12/18/2015
8
12/18/2015
....technically
9
12/18/2015
10
12/18/2015
wha ?
11
12/18/2015
shopping
12
12/18/2015
drive to shop;
pick up items;
drive home;
efficient
drive to shop;
pick up items;
drive home;
13
12/18/2015
efficient
drive to shop;
pick up items;
drive home;
efficient
drive to shop;
pick up items;
drive home;
value add
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 27
14
12/18/2015
Shopping v1.0
subroutine PURCHASE_ITEM(item_id)
- drive to shop
- obtain item
- pay for item
- drive home
15
12/18/2015
Shopping v1.0
subroutine PURCHASE_ITEM(item_id)
- drive to shop
- obtain item
- pay for item
- drive home Shopping v2.0
for each_item in LIST_OF_ITEMS
do
purchase_item;
end loop;
Shopping v1.0
subroutine PURCHASE_ITEM(item_id)
- drive to shop
- obtain item
- pay for item
- drive home Shopping v2.0
for each_item in LIST_OF_ITEMS
do
purchase_item;
Shopping v2.1
end loop;
16
12/18/2015
business analysts...
procedural analysis
technical analysts...
procedural specifications
17
12/18/2015
programmers
procedural programs
18
12/18/2015
this session
my favourites
19
12/18/2015
Favourite:
subquery factoring
WITH clause
20
12/18/2015
DEPTNO MAX(HIRED
---------- ---------
30 03-DEC-81
20 12-JAN-83
10 23-JAN-82
"gee.......wow"
21
12/18/2015
why is it cool ?
22
12/18/2015
23
12/18/2015
24
12/18/2015
procedural approach....
25
12/18/2015
things to note...
26
12/18/2015
execution plan
two possibilities
27
12/18/2015
temporary storage
----------------------------------------------------------------------
| 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 |
----------------------------------------------------------------------
28
12/18/2015
Session altered.
Session altered.
END OF STMT
29
12/18/2015
no temporary storage
------------------------------------------------------
| 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 |
------------------------------------------------------
30
12/18/2015
explicit control
31
12/18/2015
32
12/18/2015
33
12/18/2015
Favourite:
temporal validity
34
12/18/2015
Huh ?
very common
35
12/18/2015
Table created.
36
12/18/2015
Table created.
37
12/18/2015
examples
38
12/18/2015
so what's happening ?
39
12/18/2015
a slight digression
Favourite:
query expansion
40
12/18/2015
Statistics
------------------------------------------
651 recursive calls
0 db block gets
2243 consistent gets
24 physical reads
SQL> begin
2 dbms_utility.expand_sql_text
3 ( 'select * from MY_STUFF'||
4 'where created > sysdate',:c);
5 end;
6 /
SQL> print c
41
12/18/2015
View created.
42
12/18/2015
"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. | 82
DECODE("A4"."BUFFER_POOL_ID",1,'KEEP',2,'RECYCLE','DEFAULT') "BUFFER_POOL",
"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"
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 83
."GROUPS",0,1,
"A195"."GROUPS")) "FREELIST_GROUPS",
43
12/18/2015
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. | 84
"A206"."TYPE#"=7 OR
44
12/18/2015
"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. | 87
"A186"."GROUPS")) "FREELIST_GROUPS",
45
12/18/2015
"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. | 88
ODE("A182"."LISTS",0,1,
"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. | 89
46
12/18/2015
16 ...
more
pages
47
12/18/2015
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 /
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"
48
12/18/2015
existing tables
Table altered.
49
12/18/2015
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
50
12/18/2015
Table altered.
Table altered.
51
12/18/2015
room to grow
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 100
no temporal constraints
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 101
52
12/18/2015
Table altered.
1 row created.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 102
53
12/18/2015
no temporal validation
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 104
1 row created.
1 row created.
54
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 106
107
55
12/18/2015
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.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 108
take note ..
56
12/18/2015
57
12/18/2015
flashback temporal
data archive validity
112
SQL> begin
2 DBMS_FLASHBACK_ARCHIVE.ENABLE_AT_VALID_TIME (
3 level=>'ASOF',
4 query_time=>systimestamp+10);
5 end;
6 /
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 113
58
12/18/2015
flashback temporal
data archive validity
flashback
data archive
temporal
validity
59
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 115
Favourite:
top-n simplifications
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 116
60
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 117
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 118
61
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 118
inline view
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 119
62
12/18/2015
SQL> select *
2 from (
3 select empno, ename, hiredate
4 from emp
5 order by hiredate desc
6 )
7 where rownum <= 5;
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 120
------------------------------------------------
| 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 |
------------------------------------------------
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 121
63
12/18/2015
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;
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 122
-------------------------------------------------
| Id | Operation | Name | Rows |
-------------------------------------------------
| 0 | SELECT STATEMENT | | 14 |
|* 1 | VIEW | | 14 |
|* 2 | WINDOW SORT PUSHED RANK| | 14 |
| 3 | TABLE ACCESS FULL | EMP | 14 |
-------------------------------------------------
1 - filter("RN"<=5)
2 - filter(ROW_NUMBER() OVER
( ORDER BY HIREDATE") DESC )<=5)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 123
64
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 124
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 125
65
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 126
-------------------------------------------------
| Id | Operation | Name | Rows |
-------------------------------------------------
| 0 | SELECT STATEMENT | | 14 |
|* 1 | VIEW | | 14 |
|* 2 | WINDOW SORT PUSHED RANK| | 14 |
| 3 | TABLE ACCESS FULL | EMP | 14 |
-------------------------------------------------
1 - filter("from$_subquery$_002".
"rowlimit_$$_rownumber"<=5)
2 - filter(ROW_NUMBER() OVER
( ORDER BY HIREDATE") DESC )<=5)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 127
66
12/18/2015
variations
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 128
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 129
67
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 130
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 131
68
12/18/2015
pagination
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 132
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 133
69
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 134
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 135
70
12/18/2015
-----------------------------------------------
| 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
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 136
things to note
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 137
71
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 138
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;
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 139
72
12/18/2015
or ...
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 140
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 141
73
12/18/2015
----------------------------------------------
| 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 |
----------------------------------------------
ugh
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 142
no percent pagination
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 143
74
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 144
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 145
75
12/18/2015
PL/SQL quirk
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 146
76
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 148
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
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 149
77
12/18/2015
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 /
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 150
Favourite:
pattern matching
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 151
78
12/18/2015
median
top n
etc
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 152
"analysis"
often
"patterns"
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 153
79
12/18/2015
real example
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 154
AML
anti-money laundering
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 156
80
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 157
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 158
81
12/18/2015
hard...
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 159
pattern matching
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 160
82
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 161
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 162
83
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 163
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 164
84
12/18/2015
ACCT CEIL(MAX(FINISHED_LOSING-STARTED_LOSING))
---------- -----------------------------------------
66 3
184 7
280 2
416 1
814 3
908 5
1083 2
1142 3
1256 1
1260 1
1282 15
1676 2
1794 1
2085 12
2133 4
...
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 166
85
12/18/2015
Favourite:
join enhancements
11.2
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 168
86
12/18/2015
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 /
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 169
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 170
87
12/18/2015
12c
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 171
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 /
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 172
88
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 173
Table created.
4 rows created.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 174
89
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 175
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 176
90
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 177
CROSS APPLY
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 178
91
12/18/2015
"big deal"
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 180
92
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 181
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 181
93
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 182
94
12/18/2015
Favourite:
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 184
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 185
95
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 185
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 186
96
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 187
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 188
97
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 189
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 190
98
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 191
Elapsed: 06:12:34.00
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 191
99
12/18/2015
Elapsed: 06:12:34.00
ERROR at line 1:
ORA-00001: unique constraint (DEMO.WHOPPER_PK) violated
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 192
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 192
100
12/18/2015
COUNT(*)
----------
0
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 193
what we want
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 194
101
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 195
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 196
102
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 197
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 197
103
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 198
ERR$_EMP
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 199
104
12/18/2015
DBMS_ERRLOG.CREATE_ERROR_LOG (
dml_table_name IN VARCHAR2,
err_log_table_name IN VARCHAR2 := NULL,
err_log_table_owner IN VARCHAR2 := NULL,
...
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 200
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 201
105
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 201
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 201
106
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 201
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 202
107
12/18/2015
demo
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 203
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 204
108
12/18/2015
non-numeric
SQL> select * from NEW_DATA;
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 204
non-numeric
SQL> select * from NEW_DATA;
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 204
109
12/18/2015
no dept 50
non-numeric
SQL> select * from NEW_DATA;
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 204
no dept 50
non-numeric
SQL> select * from NEW_DATA;
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 204
110
12/18/2015
no dept 50
non-numeric
SQL> select * from NEW_DATA;
duplicate
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 204
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 205
111
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 205
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 205
112
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 205
1 row created.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 205
113
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 206
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
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 206
114
12/18/2015
favourite:
query blocks
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 207
C# application
208 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
115
12/18/2015
209 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
C#, C++
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 210
116
12/18/2015
C#, C++
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 210
C#, C++
PL/SQL
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 211
117
12/18/2015
No comments
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 212
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 213
118
12/18/2015
"C# is self-documenting"
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 214
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 215
119
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 216
SQL is no different
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 217
120
12/18/2015
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
Explain plan
121
12/18/2015
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. |
122
12/18/2015
123
12/18/2015
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 |
124
12/18/2015
Id | Operation | Name |
----------------------------------------------|
0 | SELECT STATEMENT | |
1 | HASH JOIN | |
2 | TABLE ACCESS BY INDEX ROWID | EMP |
3 | Query
NESTED LOOPS
Block | by operation
Name / Alias (identified | id):
4 | ---------------------------------------------------------
VIEW | |
5 | 1 SORT
- SEL$1
GROUP BY | |
6 | 3 -TABLE
AVGSAL
ACCESS/ Y@SEL$1
BY INDEX ROWID| EMP |
7 | 4 - INDEX
AVGSALFULL SCAN | E2 |
8 | 5 - AVGSAL
INDEX RANGE SCAN/ EMP@AVGSAL | E1 |
6 - SEL$1 / EMP@SEL$1
9 | VIEW | |
7 - LASTEMP / X@SEL$1
10 | SORT GROUP BY
8 - LASTEMP
| |
11 | TABLE ACCESS
9 - LASTEMP BY INDEX ROWID
/ EMP@LASTEMP | EMP |
12 | INDEX RANGE SCAN | E2 |
query PLAN_TABLE
125
12/18/2015
126
12/18/2015
127
12/18/2015
-----------------------------------------------------------------------------------
|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 |
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
|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 JOINBlock Name |/ Object
Query | 1 | (identified
Alias 14 | 14
by |00:00.01
operation| id): 14 |
| 3 | VIEW | | 1 | 3 | 3 |00:00.01 | 7 |
-------------------------------------------------------------
| 4 | HASH GROUP BY | | 1 | 3 | 3 |00:00.01 | 7 |
| 5 |
1 - SEL$1
TABLE ACCESS FULL| EMP | 1 | 14 | 14 |00:00.01 | 7 |
| 6 | 3 ACCESS
TABLE - AVGSALFULL |/ EMP
Y@SEL$1
| 1 | 14 | 14 |00:00.01 | 7 |
| 7 | VIEW 4 - AVGSAL | | 1 | 13 | 4 |00:00.01 | 7 |
| 8 | HASH5GROUP
- AVGSAL
BY |/ EMP@AVGSAL
| 1 | 13 | 4 |00:00.01 | 7 |
| 9 | 6 -ACCESS
TABLE SEL$1FULL |/ EMP
EMP@SEL$1
| 1 | 14 | 14 |00:00.01 | 7 |
-----------------------------------------------------------------------------------
7 - LASTEMP / X@SEL$1
8 - LASTEMP
9 - LASTEMP / EMP@LASTEMP
128
12/18/2015
Session altered.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 230
**************************
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)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 231
129
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 232
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
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 233
130
12/18/2015
131
12/18/2015
Favourite:
subquery factoring
part 2
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 236
first principles
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 237
132
12/18/2015
ENAME
---------------------------
KING
BLAKE
JAMES
ALLEN
WARD
CLARK
MILLER
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 238
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 239
133
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 240
134
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 242
recursive...
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 242
135
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 243
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 244
136
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 245
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 245
137
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 245
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 245
138
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 246
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 247
139
12/18/2015
union all
<recursive relationship>
)
select ...
from RECURSIVE_WITH
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 248
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 249
140
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 251
141
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 252
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 253
142
12/18/2015
ERROR:
ORA-01489: result of string concatenation is too long
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 253
EMPNO NAME
---------- --------------------------------
7839 KING
7566 JONES
...
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 254
143
12/18/2015
EMPNO NAME
---------- --------------------------------
7839 KING
7566 KING-JONES
7698 KING-BLAKE
7782 KING-CLARK
7499 KING-BLAKE-ALLEN
7521 KING-BLAKE-WARD
<etc>
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 255
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 256
144
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 257
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 258
145
12/18/2015
ANSI
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 259
Favourite:
sql transposition
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 260
146
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 261
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 262
147
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 263
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 264
148
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 265
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 266
149
12/18/2015
PIVOT clause
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 267
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 /
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 268
150
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 269
Table created.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 270
151
12/18/2015
UNPIVOT clause
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 271
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 272
152
12/18/2015
SQL> select *
2 from PIVOTED_SALES
3 UNPIVOT
4 ( quantity for quarter in (Q1,Q2,Q3,Q4) )
5 /
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 273
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 273
153
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 273
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 273
154
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 274
Wrap up
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 275
155
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 276
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 277
156
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 278
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 279
157
12/18/2015
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.*;
Timer timer;
static JFrame frame;
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}
}
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 280
158
12/18/2015
SQL is faster
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 281
SQL is easier
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 282
159
12/18/2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 283
Connor McDonald
286 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
160
12/18/2015
ORA-03113
286 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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
161