oracle university sql masterclass rob van wijkjune 9 & 10, 2011, tallinn, estonia
TRANSCRIPT
![Page 1: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/1.jpg)
Oracle University SQL Masterclass
Rob van Wijk • June 9 & 10, 2011, Tallinn, Estonia
![Page 2: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/2.jpg)
About me
• Work with Oracle and SQL since 1995• From:
• Blog:
• Forums:
•
Utrecht, Netherlands
![Page 3: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/3.jpg)
Agenda
Day 1
Part One: Do More With SQL and Joining
Part Two: Analytic Functions
Part Three: Grouping & Aggregating
Part Four: SQL Model Clause
Day 2
Part Five: Recursive Subquery Factoring
Part Six: Regular Expressions
Part Seven: XML in SQL
Part Eight: Frequently Occuring SQL Problems
![Page 4: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/4.jpg)
Part 1a: Do More With SQL
![Page 5: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/5.jpg)
Goals
• As practical as possible
• As less regurgitating of documentation as possible
• Lots of example scripts
• Recognizable problems
• Do as much as possible in SQL and avoid shipping
records for processing to PL/SQL or even Java at a
middle tier.
![Page 6: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/6.jpg)
If you want to build a ship, don't drum up the men togather wood, divide the work and give orders.
Instead, teach them to yearn for the vast and endless sea.
– Antoine de Saint Exupéry
![Page 7: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/7.jpg)
![Page 8: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/8.jpg)
One SQL engine versus …
![Page 9: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/9.jpg)
… two engines.
procedural engine
SQL engine
context swtiches
dmws1.sql
![Page 10: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/10.jpg)
You risk wrong results because of different start times of queries with default READ COMMITTED isolation level
dmws2.sql
![Page 11: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/11.jpg)
Part 1b: ANSI joins and partitioned outer join
![Page 12: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/12.jpg)
ANSI joins: Comparison with Oracle-syntax
• CROSS JOIN
• INNER JOIN
• OUTER JOIN
• NATURAL JOIN
aj3.sql
aj2.sql
aj1.sql
aj4.sql
![Page 13: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/13.jpg)
ANSI joins: Full Outer Join
a FULL OUTER JOIN b ≡
a LEFT OUTER JOIN bUNION ALL
b WHERE NOT EXISTS a
• 11g: Native full outer join
• _optimizer_native_full_outer_join
• /*+ NATIVE_FULL_OUTER_JOIN */
• /*+ NO_NATIVE_FULL_OUTER_JOIN */
aj5.sql
aj6.sql
![Page 14: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/14.jpg)
ANSI joins: Partitioned Outer Join
• Outer join: NULL rows for missing values
• Partitioned outer join: NULL rows for missing values
per <column1>, …, <columnN>
aj7.sql
![Page 15: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/15.jpg)
ANSI joins
15 • Title of presentation
![Page 16: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/16.jpg)
Part 2: Analytic Functions
![Page 17: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/17.jpg)
Analytic Functions: Topics
• Introduction
• Mind set
• Evaluation order
• Main syntax
• Examples
• Window clause
![Page 18: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/18.jpg)
Analytic Functions: Introduction
Of every employee please show me:
• His name
• The department he’s working in
• His salary
• The cumulative salary per department
• Percentage of salary within the department
• Percentage of salary within the company
where employees are sorted by department and salary
af1c.sqlaf1b.sqlaf1a.sql
![Page 19: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/19.jpg)
Analytic Functions: Introduction
• Since 8.1.6 Enterprise Edition
• Look like well known aggregate functions like SUM,
COUNT and AVG
• … but they don’t aggregate
• Prevents self joins
• Have been extended with new functions and new
options in more recent versions
af2.sql
![Page 20: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/20.jpg)
Analytic Functions: Mind set
Don’t think “rows” …
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO---------- ---------- --------- ---------- -------- ---------- ---------- ---------- 7782 CLARK MANAGER 7839 09-06-81 2450 10 7839 KING PRESIDENT 17-11-81 5000 10 7934 MILLER CLERK 7782 23-01-82 1300 10 7876 ADAMS CLERK 7788 23-05-87 1100 20
7902 FORD ANALYST 7566 03-12-81 3000 20
7566 JONES MANAGER 7839 02-04-81 2975 20 7788 SCOTT ANALYST 7566 19-04-87 3000 20 7369 SMITH CLERK 7902 17-12-80 800 20 7499 ALLEN SALESMAN 7698 20-02-81 1600 300 30 7698 BLAKE MANAGER 7839 01-05-81 2850 30 7900 JAMES CLERK 7698 03-12-81 950 30 7654 MARTIN SALESMAN 7698 28-09-81 1250 1400 30 7844 TURNER SALESMAN 7698 08-09-81 1500 0 30 7521 WARD SALESMAN 7698 22-02-81 1250 500 30
7902 FORD ANALYST 7566 03-12-81 3000 20
![Page 21: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/21.jpg)
Analytic Functions: Mind set
… but think “sets” EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO---------- ---------- --------- ---------- -------- ---------- ---------- ----------
7782 CLARK MANAGER 7839 09-06-81 2450 10 7839 KING PRESIDENT 17-11-81 5000 10 7934 MILLER CLERK 7782 23-01-82 1300 10 7876 ADAMS CLERK 7788 23-05-87 1100 20 7902 FORD ANALYST 7566 03-12-81 3000 20 7566 JONES MANAGER 7839 02-04-81 2975 20 7788 SCOTT ANALYST 7566 19-04-87 3000 20 7369 SMITH CLERK 7902 17-12-80 800 20 7499 ALLEN SALESMAN 7698 20-02-81 1600 300 30 7698 BLAKE MANAGER 7839 01-05-81 2850 30 7900 JAMES CLERK 7698 03-12-81 950 30 7654 MARTIN SALESMAN 7698 28-09-81 1250 1400 30 7844 TURNER SALESMAN 7698 08-09-81 1500 0 30 7521 WARD SALESMAN 7698 22-02-81 1250 500 30
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO---------- ---------- --------- ---------- -------- ---------- ---------- ----------
7782 CLARK MANAGER 7839 09-06-81 2450 10 7839 KING PRESIDENT 17-11-81 5000 10 7934 MILLER CLERK 7782 23-01-82 1300 10
7876 ADAMS CLERK 7788 23-05-87 1100 20 7902 FORD ANALYST 7566 03-12-81 3000 20 7566 JONES MANAGER 7839 02-04-81 2975 20 7788 SCOTT ANALYST 7566 19-04-87 3000 20 7369 SMITH CLERK 7902 17-12-80 800 20
7499 ALLEN SALESMAN 7698 20-02-81 1600 300 30 7698 BLAKE MANAGER 7839 01-05-81 2850 30 7900 JAMES CLERK 7698 03-12-81 950 30 7654 MARTIN SALESMAN 7698 28-09-81 1250 1400 30 7844 TURNER SALESMAN 7698 08-09-81 1500 0 30 7521 WARD SALESMAN 7698 22-02-81 1250 500 30
![Page 22: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/22.jpg)
Analytic Functions: Evaluation order
• Last
• Even after evaluating HAVING clause
• And after ROWNUM has been assigned
• But before ORDER BY clause
• Filtering on outcome of analytic function: nest the
query using an inline view or use subquery factoring
af3b.sqlaf3a.sql
![Page 23: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/23.jpg)
Analytic Functions: Main syntax
<function> (<argument>, <argument>, …)
OVER
(<partition clause>
<order by clause>
<window clause>
)
![Page 24: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/24.jpg)
Analytic Functions: The functions
LAG FIRST / LAST PERCENT_RANK
LEAD COUNT PERCENTILE_DISC
FIRST_VALUE SUM PERCENTILE_CONT
LAST_VALUE MAX CORR
NTH_VALUE MIN COVAR_POP
RANK AVG VARIANCE
DENSE_RANK NTILE VAR_x (2 times)
RATIO_TO_REPORT CUME_DIST STDDEV_x (3 times)
ROW_NUMBER LISTAGG REGR_x (9 times)
![Page 25: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/25.jpg)
Analytic Functions: Partition clause
PARTITION BY <expression> [,<expression>]*
to let the analytic function operate on a subset of the rows with the same values for the
partition by expression values.
af4.sql
![Page 26: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/26.jpg)
Analytic Functions: Order By clause
ORDER BY <expression> [ASC|DESC] [NULLS
FIRST|NULLS LAST], …
Its presence changes the default window of an analytic function from the total set to a running
total.
af5.sql
![Page 27: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/27.jpg)
Analytic Functions: Example 1
Top N queries
What do I mean exactly with:
“Show me the top 3 earning employees per department”
• RANK
• DENSE_RANK
• ROW_NUMBER
af6.sql
![Page 28: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/28.jpg)
Analytic Functions: Example 2
1. David Zabriskie (USA) 0.58:31
2. Ivan Basso (ITA) + 0:17
3. Paolo Savoldelli (ITA) + 0:44
4. Marzio Bruseghin (ITA) + 0:48
5. Serguei Gonchar (UKR) z.t.
6. Vladimir Karpets (RUS) + 1:07
7. Markus Fothen (GER) + 1:15
8. Thomas Dekker (NLD) + 1:23
9. Jan Hruska (CZE) + 1:34
10. Danilo di Luca (ITA) z.t.
af7.sql
![Page 29: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/29.jpg)
Analytic Functions: Example 3
• Requirement: non-overlapping & consecutive periods
• Columns Startdate and maybe Enddate
• Optimize to retrieve current period
• Options:
1) No Enddate column and use correlated subquery
2) Enddate column and database trigger code to check
requirement
3) No Enddate column and use analytic function
af8.sql
![Page 30: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/30.jpg)
Analytic Functions: Example 4
• Bills can be of type “Prepayment” or “Settlement”
• Bill lines have an amount.
• Each customer pays a prepayment each month. The
bill contains one bill line with the amount.
• Each customer receives once a year a settlement bill.
• How to calculate the previous prepayment amount?
This is the amount before the last settlement bill.
af9.sql
![Page 31: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/31.jpg)
Analytic Functions: Example 5
TIME QUANTITY
-------- -----------
12:22:01 100
12:22:03 200
12:22:04 300
12:22:06 200
12:22:45 100
12:22:46 200
12:23:12 100
12:23:12 200
MIN(TIME) MAX(TIME) QUANTITY
--------- --------- -----------
12:22:01 12:22:06 800
12:22:45 12:22:46 300
12:23:12 12:23:12 300
af10.sql
![Page 32: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/32.jpg)
Analytic Functions: Window clause
• Total set: ROWS BETWEEN UNBOUNDED
PRECEDING AND UNBOUNDED FOLLOWING
• Anchored set / running aggregate: ROWS BETWEEN
UNBOUNDED PRECEDING AND CURRENT ROW
• ROW / RANGE
af13.sql
af11.sql
af12.sql
![Page 33: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/33.jpg)
Analytic Functions
33 • Title of presentation
![Page 34: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/34.jpg)
Part 3: Grouping & Aggregating
![Page 35: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/35.jpg)
aog1.sql
![Page 36: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/36.jpg)
Grouping & Aggregating: Topics
• Introduction
• GROUPING SETS
• ROLLUP
• CUBE
• Combining and calculating
• Supporting functions
• Inner workings
• MIN/MAX … KEEP … (DENSE_RANK FIRST/LAST … )
![Page 37: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/37.jpg)
Grouping & Aggregating: Grouping Sets (1)
GROUP BY expr1, …, exprn
≡
GROUP BY GROUPING SETS
( (expr1, …, exprn) )
aog2.sql
![Page 38: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/38.jpg)
Grouping & Aggregating: Grouping Sets (2)
GROUP BY GROUPING SETS
( (expr11, …, expr1n), …, (exprx1, …, exprxm) )
≡
GROUP BY expr11, … expr1n
UNION ALL
…
UNION ALL
GROUP BY exprx1, …, exprxm
aog3.sql
![Page 39: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/39.jpg)
Grouping & Aggregating: ROLLUP (1)
GROUP BY ROLLUP ( set1, …, setn )
≡
GROUP BY GROUPING SETS
( (set1, …, setn), (set1, …, setn-1), …, set1, () )
![Page 40: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/40.jpg)
Grouping & Aggregating: ROLLUP (2)
ROLLUP (set1, …, setN)
with N ≥ 1
leads to N+1 GROUPING SETS
![Page 41: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/41.jpg)
Grouping & Aggregating: ROLLUP (3)
Example:
GROUP BY ROLLUP ( (deptno), (job,mgr), (empno) )
≡
GROUP BY GROUPING SETS
( (deptno,job,mgr,empno)
, (deptno,job,mgr)
, (deptno)
, () )
aog4.sql
![Page 42: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/42.jpg)
Grouping & Aggregating: CUBE (1)
GROUP BY CUBE ( set1, …, setn )≡
GROUP BY GROUPING SETS(all possible combinations between () and (set1, …, setn) )
![Page 43: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/43.jpg)
Grouping & Aggregating: CUBE (2)
CUBE (set1, …, setN)
with N ≥ 1
leads to 2N GROUPING SETS
![Page 44: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/44.jpg)
Grouping & Aggregating: CUBE (3)
Follows Pascal’s triangle
0 sets X
1 set
2 sets
3 sets
4 sets
![Page 45: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/45.jpg)
Grouping & Aggregating: CUBE (4)
Example:
GROUP BY CUBE ( (deptno), (job,mgr), (empno) )
≡
GROUP BY GROUPING SETS
( (deptno,job,mgr,empno)
, (deptno,job,mgr), (deptno,empno), (job,mgr,empno)
, (deptno), (job,mgr), (empno)
, () )
aog5.sql
![Page 46: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/46.jpg)
Grouping & Aggregating: Calculating (1)
GROUP BY deptno, ROLLUP(empno)
?
![Page 47: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/47.jpg)
Grouping & Aggregating: Calculating (2)
GROUP BY deptno, ROLLUP(empno)
≡
GROUP BY GROUPING SETS (deptno)
, GROUPING SETS ( empno, () )
![Page 48: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/48.jpg)
Grouping & Aggregating: Calculating (3)
Cartesian product !
GROUP BY deptno, ROLLUP(empno)
≡
GROUP BY GROUPING SETS (deptno)
, GROUPING SETS ( (empno), () )
≡
GROUP BY GROUPING SETS
( (deptno,empno), (deptno) )
aog6.sql
![Page 49: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/49.jpg)
Grouping & Aggregating: Calculating (4)
Question:
How many grouping sets does the clause below yield?
GROUP BY ROLLUP(deptno,job)
, CUBE(mgr,hiredate)
aog7.sql
![Page 50: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/50.jpg)
Grouping & Aggregating: Functions
GROUPING
GROUPING_ID
GROUP_ID
aog8.sql
![Page 51: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/51.jpg)
Grouping & Aggregating: Inner working (1)
SORT GROUP BY
Versus
HASH GROUP BY
![Page 52: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/52.jpg)
Grouping & Aggregating: Inner working (2)
1077822450
1078395000
1079341300
207369800
2075662975
2077883000
2078761100
2079023000
3074991600
3075211250
3076541250
3076982850
3078441500
307900950
10NULL8750
20NULL10875
30NULL9400+
+NULLNULL29025
incoming set
grouping set ( (deptno,empno) )
grouping set ( () )
grouping set ( (deptno) )
SORT GROUP BY
SORT GROUP BY
SORT GROUP BY
ROLLUP (DEPTNO,EMPNO)
aog9.sql
![Page 53: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/53.jpg)
Grouping & Aggregating: Inner working (3)
SORT GROUP BY (deptno,job)
GENERATE CUBE
SORT GROUP BY (deptno,job)
incoming set 14 rows
9 rows
36
rows
18 rows
CUBE (DEPTNO,JOB)
aog10.sql
deptno null & job null
deptno not null & job not null deptno not null & job null
deptno null & job not null
![Page 54: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/54.jpg)
Grouping & Aggregating: Inner working (4)
LOAD AS SELECT (into input table)
TABLE ACCESS FULL (EMP)
TEMP TABLE TRANSFORMATION
VIEW
TABLE ACCESS FULL (output table)
temporaryinput table
SYS_TEMP_...
temporaryoutput table
SYS_TEMP_...
LOAD AS SELECT (into outputtable)
HASH GROUP BY
TABLE ACCESS FULL (input table)
iterate as much times as
there are grouping sets
aog11.sql
![Page 55: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/55.jpg)
Grouping & Aggregating: Inner working (5)
Optimize towards a ROLLUP or CUBE execution,if possible?
aog12.sql
![Page 56: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/56.jpg)
Grouping & Aggregating: Agg. Functions (1)
• COUNT
• SUM
• AVG
• MAX
• MIN
• STDDEV
• VARIANCE
• LISTAGG
aog13.sql
![Page 57: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/57.jpg)
Grouping & Aggregating: Agg. Functions (2)
• MAX(…) KEEP (DENSE_RANK FIRST ORDER BY …)
• MAX(…) KEEP (DENSE_RANK LAST ORDER BY …)
• MIN(…) KEEP (DENSE_RANK FIRST ORDER BY …)
• MIN(…) KEEP (DENSE_RANK LAST ORDER BY …)
aog14.sql
![Page 58: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/58.jpg)
Grouping & Aggregating
58 • Title of presentation
![Page 59: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/59.jpg)
Part 4: SQL Model Clause
![Page 60: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/60.jpg)
SQL Model Clause: Topics
• Introduction
• Syntax
• Examples
• Performance
• Alternatives
• Conclusion
![Page 61: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/61.jpg)
SQL Model Clause: Introduction
• Treat data as multidimensional arrays
• Complex calculations across rows
• Syntax which resembles logic programming (Prolog)
• Can prevent exporting data to external applications
like Excel/Numbers
• No more several copies of data on several PC’s
anymore
![Page 62: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/62.jpg)
SQL Model Clause: Syntax (1)
• Divide columns in three groups: PARTITION,
DIMENSION and MEASURES
• Every partition is a separate array
• Dimensions identify a cell in every partition
• Measures are the columns you want to (re-)calculate
• The rules tell you how the data is to be manipulated
![Page 63: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/63.jpg)
SQL Model Clause: Examples
• A model clause that does nothing
• Adding an extra row to the result set
• RETURN UPDATED ROWS
• The difference between MEASURES and PARTITION
mc4.sql
mc3.sql
mc2.sql
mc1.sql
![Page 64: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/64.jpg)
SQL Model Clause: Example from the doc
mc5.sql
![Page 65: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/65.jpg)
SQL Model Clause: More examples
• ANY
• CV()
• FOR
• Iterating
• Reference models
• Difference between NULL and NAV
• IS PRESENT, PRESENTV and PRESENTNNV
mc11.sql
mc10.sql
mc9.sql
mc8.sql
mc7.sql
mc6.sql
mc12.sql
![Page 66: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/66.jpg)
SQL Model Clause: Complete syntax
MODEL[<global reference options>][<reference models>][MAIN <main-name>] [PARTITION BY (<cols>)] DIMENSION BY (<cols>) MEASURES (<cols>) [<reference options>] [RULES] <rule options> (<rule>, <rule>,.., <rule>)
<global reference options> ::= <reference options> <ret-opt> <ret-opt> ::= RETURN {ALL|UPDATED} ROWS <reference options> ::= [IGNORE NAV | [KEEP NAV] [UNIQUE DIMENSION | UNIQUE SINGLE REFERENCE] <rule options> ::= [UPDATE | UPSERT | UPSERT ALL] [AUTOMATIC ORDER | SEQUENTIAL ORDER] [ITERATE (<number>) [UNTIL <condition>]] <reference models> ::= REFERENCE ON <ref-name> ON (<query>) DIMENSION BY (<cols>) MEASURES (<cols>) <reference options>
![Page 67: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/67.jpg)
SQL Model Clause: Examples
• Financial spreadsheet
• Fibonacci
• OTN-question
• Interest and rates
mc13.sql
mc14.sql
mc15.sql
mc16.sql
![Page 68: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/68.jpg)
SQL Model Clause: Performance
• Internal hash-tables in PGA
• Sequential Order SQL MODEL ORDERED [FAST]
• Automatic Order SQL MODEL [A]CYCLIC
• FAST left side cell references are single cell
references and aggregates at right side -if any- are
simple arithmetic non-distinct aggregates, like SUM,
COUNT, AVG and so on.
mc17.sql
![Page 69: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/69.jpg)
SQL Model Clause: Advanced examples
• Calculating die probabilities
• Exponential Moving Average
X = (K * (C - P)) + P
Where:
X = Current EMA (i.e. EMA to be calculated)
C = Current original data value
K = Smoothing Constant
P = Previous EMA
• Sudoku solver
mc18.sql
mc19.sql
mc20.sql
![Page 70: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/70.jpg)
SQL Model Clause
70 • Title of presentation
![Page 71: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/71.jpg)
Part 5: Recursive Subquery Factoring
![Page 72: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/72.jpg)
Recursive Subquery Factoring: Topics
• Subquery Factoring
• Concepts
• Recursive Examples
• Simulating Connect By
• Performance
• More recursive examples
![Page 73: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/73.jpg)
Subquery Factoring
• Since version 9
• Let’s you assign a name to a subquery block
• Modular Programming in SQL
• Also known as “WITH clause” or “Common Table
Expressions”
• Second to last factored subquery: comma instead of
“WITH”
• /*+ MATERIALIZE */ and /*+ INLINE */
• Must use each factored subquery?
rsf1.sql
rsf2.sql
rsf3.sql
![Page 74: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/74.jpg)
Recursive Subquery Factoring: Concepts
• Since version 11.2
• Let’s you query hierarchical data
• More powerful than CONNECT BY
• Anchor member UNION ALL recursive member
• Recursive member cannot contain: DISTINCT, Model
clause, aggregate functions and analytic functions
• SEARCH DEPTH / BREADTH FIRST
• CYCLE
rsf4.sql
rsf5.sql
rsf6.sql
![Page 75: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/75.jpg)
Recursive Subquery Factoring: Examples
• Fibonacci
• fib(0) = 0
• fib(1) = 1
• fib(n+2) = fib(n+1) + fib(n)
• Interest and rates
rsf7.sql
rsf8.sql
![Page 76: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/76.jpg)
Simulating Connect By
• LEVEL
• SYS_CONNECT_BY_PATH
• CONNECT_BY_ROOT
• CONNECT_BY_ISCYCLE
• CONNECT_BY_ISLEAF
rsf9.sql
rsf10.sql
rsf11.sql
rsf12.sql
rsf13.sql
![Page 77: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/77.jpg)
Recursive Subquery Factoring: Performance
• /*+ CONNECT_BY_FILTERING */
• /*+ NO_CONNECT_BY_FILTERING */
rsf14.sql
![Page 78: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/78.jpg)
More Recursive Examples
• Calculating die probabilities
• Exponential Moving Average
X = (K * (C - P)) + P
Where:
X = Current EMA (i.e. EMA to be calculated)
C = Current original data value
K = Smoothing Constant
P = Previous EMA
• Sudoku solver
rsf15.sql
rsf16.sql
rsf17.sql
![Page 79: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/79.jpg)
Recursive Subquery Factoring
79 • Title of presentation
![Page 80: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/80.jpg)
Part 6: Regular Expressions
![Page 81: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/81.jpg)
![Page 82: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/82.jpg)
Regular Expressions: Topics
• Introduction
• Metacharacters
• POSIX
• Perl-based extensions
• More examples
![Page 83: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/83.jpg)
Regular Expressions: Introduction
• A regular expression is a search pattern
• Since version 10:
• REGEXP_INSTR
• REGEXP_SUBSTR
• REGEXP_REPLACE
• REGEXP_LIKE
• Since version 11:
• REGEXP_COUNT
re1.sql
re2.sql
re3.sql
re4.sql
re5.sql
![Page 84: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/84.jpg)
Regular Expressions: Metacharacters
• Consists of metacharacters and character literals
• IEEE Portable Operating System Interface (POSIX)
• Oracle SQL Multilingual Extensions
• Oracle SQL Perl-influenced Extensions
![Page 85: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/85.jpg)
Regular Expressions: POSIX
Syntax Name
. Any character
+ One or more
* Zero or more
? Zero or one
{m} Exact count
{m,} At least count
{m,n} Between count
[char…] Matching character list
[^char…] Non-matching char. list
Syntax Name
[a|b] Or
(expr) Grouping
\n Back Reference
\ Escape character
^ Beginning-of-line anchor
$ End-of-line anchor
[:class:] POSIX character class
[.element.] Collating Element Operator
[=char=] Character Equivalence Class
re6.sql
![Page 86: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/86.jpg)
Regular Expressions: Perl-based extensions
re8.sql
Syntax Description Equivalent to
\d Matches a digit character [[:digit:]]
\D Matches a non-digit character [^[:digit:]]
\w Matches a word character (alphanumeric or _) [[:alnum:]_]
\W Matches a non-word character [^[alnum:]_]
\s Matches a whitespace character [[:space:]]
\S Matches a non-whitespace character [^[:space:]]
\A Matches beginning of string (multiline mode)
\Z Matches end of string (multiline mode)
\z Matches end of string (multiline mode)
![Page 87: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/87.jpg)
Regular Expressions: Perl-based extensions
re9.sql
Syntax Description
+? Matches one or more occurences of preceding expression non-greedy
*? Matches zero or more occurences of preceding expression non-greedy
?? Matches zero or one occurences of preceding expression non-greedy
{m}? Matches exactly m occurences of preceding expression non-greedy
{m,}? Matches at least m occurences of preceding expression non-greedy
{m,n}? Matches between m and n occurences of preceding expr. non-greedy
![Page 88: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/88.jpg)
Regular Expressions: Examples
• Formatting phone numbers
• Formatting names
• Retrieving information from large text
• More examples
re12.sql
re11.sql
re10.sql
re13.sql
![Page 89: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/89.jpg)
Regular Expressions
89 • Title of presentation
![Page 90: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/90.jpg)
Part 7: XML in SQL
![Page 91: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/91.jpg)
XML in SQL: An opinion
<SEQ> <SEQDetail> <SequenceInformation> <SequencePositionIdentifier>19</SequencePositionIdentifier> </SequenceInformation> </SEQDetail> <Quantity> <QuantityDetail> <QuantityDetails> <QuantityQualifier>136</QuantityQualifier> <QuantityValue>0</QuantityValue> </QuantityDetails> </QuantityDetail> <Status> <StatusCategory> <StatusCategoryCode>8</StatusCategoryCode> </StatusCategory> <StatusDetail> <StatusDescriptionCode>56</StatusDescriptionCode> </StatusDetail> </Status> <Status> <StatusCategory> <StatusCategoryCode>Z02</StatusCategoryCode> </StatusCategory> <StatusDetail> <StatusDescriptionCode>E06</StatusDescriptionCode> <CodeListResponsibleAgencyCode>260</CodeListResponsibleAgencyCode> </StatusDetail> </Status> </Quantity></SEQ>
![Page 92: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/92.jpg)
XML in SQL: Topics
• Composing XML from relational table data
• Shredding XML into relational format
• Some more possibilities
![Page 93: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/93.jpg)
XML in SQL: Relational XML
• The most important functions:
• XMLElement
• XMLForest
• XMLAgg
• XMLAttributes
xis1.sql
xis2.sql
xis3.sql
xis4.sql
![Page 94: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/94.jpg)
XML in SQL: Relational XML
• Other functions:
• XMLCast
• XMLCData
• XMLColAttVal
• XMLComment
• XMLConcat
• XMLDiff
• XMLExists
• XMLIsValid
xis5.sql
![Page 95: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/95.jpg)
XML in SQL: Relational XML
• Other functions:
• XMLParse
• XMLPatch
• XMLPi
• XMLQuery
• XMLRoot
• XMLSerialize
• XMLTransform
xis6.sql
![Page 96: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/96.jpg)
XML in SQL: XML Relational
• XMLSequence
• XMLTable
xis7.sql
xis8.sql
![Page 97: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/97.jpg)
XML in SQL: More possibilities
• Dynamically evaluating expressions
• String aggregation
• XQuery expressions
• FLOWR (for, let, order by, where, return)
xis9.sql
xis10.sql
xis11.sql
![Page 98: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/98.jpg)
XML in SQL
98 • Title of presentation
![Page 99: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/99.jpg)
Part 8: Frequently Occuring Problems
![Page 100: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/100.jpg)
Frequently Occuring Problems
• Row / Number Generation
• Interval Based Row Generation
• Splitting Comma Separated Strings
• String Aggregation
• Pivoting
• Unpivoting
• Tabibitosan
![Page 101: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/101.jpg)
Row / Number Generation
fop1.sql
![Page 102: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/102.jpg)
Interval Based Row Generation
fop2.sql
![Page 103: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/103.jpg)
Splitting Comma Separated Strings
→
fop3.sql
![Page 104: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/104.jpg)
String Aggregation
→
fop4.sql
![Page 105: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/105.jpg)
Pivoting
fop5.sql
![Page 106: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/106.jpg)
Unpivoting
fop6.sql
![Page 107: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/107.jpg)
Tabibitosan
fop7.sql
![Page 108: Oracle University SQL Masterclass Rob van WijkJune 9 & 10, 2011, Tallinn, Estonia](https://reader038.vdocument.in/reader038/viewer/2022103101/56649eca5503460f94bd8a47/html5/thumbnails/108.jpg)
Thank you for your attention
108
• Title of presentation