SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
Patrick.Barel@AMIS.nl
technology.amis.nl
blog.bar-solutions.com
About me…
• Patrick Barel
• Working with Oracle since 1997
• Working with PL/SQL since 1999
• Playing with APEX since 2003 (mod_plsql)
• ACE since 2011
• OCA since December 20th 2012
Read me…
http://blog.bar-solutions.com
http://technology.amis.nl
http://allthingsoracle.com
Download me…
Plugins for PL/SQL Developer
http://bar-solutions.com
Plugins for Apex
http://apex-plugin.com
Watch me…
Patrick.Barel@GMail.com
Contact me…
@patch72 patrick@bar-solutions.com
Patrick.Barel@AMIS.nl
Patrick.Barel@GMail.com
3029156
40338721
Patrick Barel
Patrick Barel, AMIS Mai 28th 2013
Table Functions
PL/SQL in SQL
Overview ofTable Functions
Table Function Concepts
Using Table Functions
Table functions
Table functions are functions that produce a
collection of rows (either a nested table or a
varray) that can be queried like a physical
database table.You use a table function like the
name of a database table, in the FROM clause of
a query.
Overview of table functions
Define Record Type
Define NestedTable type
Define function returning NestedTable type
Query function using the TABLE() operator
Table function concepts
• Defined as an object table of a collection
– First an object type
SQL> CREATE TYPE now_t AS OBJECT
2 (now VARCHAR2(8));
3 /
Type created.
Table function concepts, result set
• Defined as an object table of a collection
– Second; the collection type
SQL> CREATE TYPE now_tt AS
2 TABLE OF now_t;
3 /
Type created.
Table function concepts, result set
• Return type is the object table
CREATE OR REPLACE FUNCTION now
RETURN now_tt AS
l_returnvalue now_tt := now_tt();
…
BEGIN
…
RETURN l_returnvalue;
END;
Table function concepts, function
• Queried with the TABLE function
SELECT *
FROM TABLE(now);
Table function concepts, function
CREATE OR REPLACE FUNCTION now RETURN now_tt AS
l_returnvalue now_tt := now_tt();
l_now VARCHAR2(8);
BEGIN
FOR counter IN 1 .. 4 LOOP
l_now := to_char(SYSDATE, 'HH24:MI:SS');
dbms_lock.sleep(1);
l_returnvalue.extend;
l_returnvalue(l_returnvalue.last) := now_t(l_now);
END LOOP;
RETURN l_returnvalue;
END;
Table function concepts, simple function
SQL> SELECT *
2 FROM TABLE(now)
3 /
NOW
--------
16:54:21
16:54:22
16:54:23
16:54:24
4 rows selected.
Table function concepts, simple function
• Query results passed as a parameter
– Parameter type is REF CURSOR
– SYS_REFCURSOR can be used
for weakly typed option
CREATE OR REPLACE FUNCTION now_and_then
(cursor_in SYS_REFCURSOR )
RETURN now_and_then_tt AS
Table function concepts, nesting functions
• CURSOR keyword denotes value passed
within query
SELECT *
FROM TABLE(now_and_then( CURSOR ( SELECT *
FROM TABLE(now))))
/
Table function concepts, nesting functions
CREATE OR REPLACE FUNCTION now_and_then
(cursor_in SYS_REFCURSOR)
RETURN now_and_then_tt AS
l_returnvalue now_and_then_tt := now_and_then_tt();
l_now VARCHAR2(8);
l_then VARCHAR2(8);
BEGIN
LOOP
FETCH cursor_in
INTO l_now;
EXIT WHEN cursor_in%NOTFOUND;
l_then := to_char(SYSDATE, 'HH24:MI:SS');
l_returnvalue.extend;
l_returnvalue(l_returnvalue.last) :=
now_and_then_t(l_now, l_then);
END LOOP;
RETURN l_returnvalue;
END;
Table function concepts, nested function
SQL> SELECT *
2 FROM TABLE ( now_and_then( CURSOR( SELECT *
3 FROM TABLE ( now ))))
4 /
NOW AND_THEN
-------- --------
16:58:51 16:58:55
16:58:52 16:58:55
16:58:53 16:58:55
16:58:54 16:58:55
4 rows selected.
Table function concepts, nested function
• Function can be pipelined
• Produce results as they are created
– Returning results one record at a time
Pipelined table functions
• Adding PIPELINED keyword to function
specification
• Actual return datatype is collection
• PIPE ROW function returns single record to
calling process and then continues processing
• Return is still required
CREATE OR REPLACE FUNCTION now
RETURN now_t
PIPELINED AS
l_returnvalue single_time_t;
BEGIN
loop
...
PIPE ROW(l_returnvalue);
...
end loop;
RETURN;
END;
Pipelining : syntax
CREATE OR REPLACE FUNCTION now
RETURN now_tt
PIPELINED AS
l_returnvalue now_t;
l_now VARCHAR2(8);
BEGIN
FOR counter IN 1 .. 4 LOOP
dbms_lock.sleep(2);
l_now := to_char(SYSDATE, 'HH24:MI:SS');
l_returnvalue := now_t(l_now);
PIPE ROW (l_returnvalue);
END LOOP;
RETURN;
END;
Pipelined function
SQL> SELECT *
2 FROM TABLE(now_and_then(CURSOR(SELECT *
3 FROM TABLE(now))))
4 /
NOW AND_THEN
-------- --------
19:54:15 19:54:15
19:54:17 19:54:17
19:54:19 19:54:19
3 rows selected.
Pipelined function
Without pipelining
it would be:
NOW AND_THEN
-------- --------
19:54:15 19:54:19
19:54:17 19:54:19
19:54:19 19:54:19
now_and_then.sql
• Functions can be parallelized
• If the source data can be processed in
parallel, the functions can be processed
in parallel
Parallel table functions
Typical data processing
Stage 1
OLTP
F1 F2 Data
Warehouse
Stage 2 F3
Data goes through several transformations,
in table functions,
and then gets loaded into a database
Parallel & pipelined data processing
OLTP
F1 Data
Warehouse
F1
F1
F2
F2
F2
F3
F3
F3
Data goes through several transformations,
in table functions, in parallel (multiple
processes)
and then gets loaded into a database
• Prior to Oracle9i, calling a function
inside a SQL statement caused
serialization.
– The parallel query mechanism could not
be used.
• Now you can enable parallel execution
of a table function.
– This greatly increases the usability of
PL/SQL-enriched SQL in data warehouse
applications.
Parallel execution and table functions
parallel.sql
• The table function's parameter list must consist
only of a single strongly-typed REF CURSOR.
• Include the PARALLEL_ENABLE hint in the
program header.
– Choose a partition option that specifies how the
function's execution should be partitioned.
– "ANY" means that the results are independent of the
order in which the function receives the input rows
(through the REF CURSOR).
Enabling parallel execution
{[ORDER | CLUSTERORDER | CLUSTERORDER | CLUSTERORDER | CLUSTER] BY column_list}
PARALLEL_ENABLEPARALLEL_ENABLEPARALLEL_ENABLEPARALLEL_ENABLE ({PARTITIONPARTITIONPARTITIONPARTITION p BYBYBYBY
[ANY | (HASH | RANGE) column_list]} )
PARALLEL_ENABLE (
Partition p_input_rows BY ANY )
CREATE OR REPLACE FUNCTION Aggregate_Xform (
p_input_rows in My_Types.cur_t) RETURN
My_Types.dept_sals_tab
PIPELINED
CLUSTER P_INPUT_ROWS BY (dept)
PARALLEL_ENABLE
( PARTITION p_input_rows
BY HASH (dept) )
ORDER p_input_rows BY (c1, c2)
PARALLEL_ENABLE
( PARTITION p_input_rows
BY RANGE (c1) )
with
with
with
Simplest form, results don't
vary from order in which
function gets input rows.
All rows for a given department
must go to the same slave,
and rows are delivered
consecutively.
Rows are delivered to a
particular slave as directed by
partition... and will be locally
sorted by that slave.
Examples of parallelized functions
Serial execution
Scramble
alter table emp noparallel;
select *
from table
( scramble
( cursor ( select empno, ename from emp))
);
EMP
Parallel execution
Scramble
Scramble
Scramble
EMP
Scramble
alter table emp parallel 4;
select *
from table
( scramble
( cursor ( select empno, ename from emp))
);
- Using PL/SQL in SQL
- Create script based on the table data
Using the table function
• Using SQL
Create script based on the table data
DEPT
(table)
SQL
statement
insert into DEPT( LOC, DNAME, DEPTNO)
values ( 'NEW YORK', 'ACCOUNTING', 10);
insert into DEPT( LOC, DNAME, DEPTNO)
values ( 'DALLAS', 'RESEARCH', 20);
insert into DEPT( LOC, DNAME, DEPTNO)
values ( 'CHICAGO', 'SALES', 30);
insert into DEPT( LOC, DNAME, DEPTNO)
values ( 'BOSTON', 'OPERATIONS', 40);
SQL
statement
SELECT 'insert into DEPT( LOC, DNAME, DEPTNO) values
( '''||
LOC||''', '''||
DNAME||''', '||
DEPTNO||');' line
FROM DEPT;
• Using SQL
Create script based on the table data
SELECT *
FROM table(createinsertscriptfor('DEPT'));
SQL
statement
• Using table functions
Create script based on the table data
• Using table functions
• Hide complexity behind PL/SQL
interface
• Don’t worry about datatypes
Create script based on the table data
Overview of Table Functions
Table Function Concepts
Return collection, query like table
Pipelined
Parallel
UsingTable Functions
Use PL/SQL in SQL
Hide complexity
Table functions
tahiti.oracle.com
For all documentation online
Oracle PL/SQL Programming (the
book)
Especially chapter 17 (by Steven
Feuerstein) and chapter 21 (by
Steven Feuerstein with help from
Adrian Billington)
References
Table functions - Planboard Symposium 2013
Table functions - Planboard Symposium 2013

Más contenido relacionado

La actualidad más candente

YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions Yugabyte
 
Hive join optimizations
Hive join optimizationsHive join optimizations
Hive join optimizationsSzehon Ho
 
Common Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseCommon Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseDatabricks
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeAngel Boy
 
Strongly Consistent Global Indexes for Apache Phoenix
Strongly Consistent Global Indexes for Apache PhoenixStrongly Consistent Global Indexes for Apache Phoenix
Strongly Consistent Global Indexes for Apache PhoenixYugabyteDB
 
Smart Join Algorithms for Fighting Skew at Scale
Smart Join Algorithms for Fighting Skew at ScaleSmart Join Algorithms for Fighting Skew at Scale
Smart Join Algorithms for Fighting Skew at ScaleDatabricks
 
Fully Utilizing Spark for Data Validation
Fully Utilizing Spark for Data ValidationFully Utilizing Spark for Data Validation
Fully Utilizing Spark for Data ValidationDatabricks
 
Introducing Riak
Introducing RiakIntroducing Riak
Introducing RiakKevin Smith
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniqueAngel Boy
 
elasticsearch_적용 및 활용_정리
elasticsearch_적용 및 활용_정리elasticsearch_적용 및 활용_정리
elasticsearch_적용 및 활용_정리Junyi Song
 
Cost-based Query Optimization in Apache Phoenix using Apache Calcite
Cost-based Query Optimization in Apache Phoenix using Apache CalciteCost-based Query Optimization in Apache Phoenix using Apache Calcite
Cost-based Query Optimization in Apache Phoenix using Apache CalciteJulian Hyde
 
python 수학이해하기
python 수학이해하기python 수학이해하기
python 수학이해하기Yong Joon Moon
 
Time based CAPTCHA protected SQL injection through SOAP-webservice
Time based CAPTCHA protected SQL injection through SOAP-webserviceTime based CAPTCHA protected SQL injection through SOAP-webservice
Time based CAPTCHA protected SQL injection through SOAP-webserviceFrans Rosén
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms masterHossam Hassan
 
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourWAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourSoroush Dalili
 
Building Real-time Pipelines with FLaNK_ A Case Study with Transit Data
Building Real-time Pipelines with FLaNK_ A Case Study with Transit DataBuilding Real-time Pipelines with FLaNK_ A Case Study with Transit Data
Building Real-time Pipelines with FLaNK_ A Case Study with Transit DataTimothy Spann
 
Working with Skewed Data: The Iterative Broadcast with Fokko Driesprong Rob K...
Working with Skewed Data: The Iterative Broadcast with Fokko Driesprong Rob K...Working with Skewed Data: The Iterative Broadcast with Fokko Driesprong Rob K...
Working with Skewed Data: The Iterative Broadcast with Fokko Driesprong Rob K...Spark Summit
 

La actualidad más candente (20)

YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions
 
Hive join optimizations
Hive join optimizationsHive join optimizations
Hive join optimizations
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Sql joins
Sql joinsSql joins
Sql joins
 
Common Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseCommon Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta Lakehouse
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
 
Strongly Consistent Global Indexes for Apache Phoenix
Strongly Consistent Global Indexes for Apache PhoenixStrongly Consistent Global Indexes for Apache Phoenix
Strongly Consistent Global Indexes for Apache Phoenix
 
Smart Join Algorithms for Fighting Skew at Scale
Smart Join Algorithms for Fighting Skew at ScaleSmart Join Algorithms for Fighting Skew at Scale
Smart Join Algorithms for Fighting Skew at Scale
 
Fully Utilizing Spark for Data Validation
Fully Utilizing Spark for Data ValidationFully Utilizing Spark for Data Validation
Fully Utilizing Spark for Data Validation
 
Introducing Riak
Introducing RiakIntroducing Riak
Introducing Riak
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit Technique
 
elasticsearch_적용 및 활용_정리
elasticsearch_적용 및 활용_정리elasticsearch_적용 및 활용_정리
elasticsearch_적용 및 활용_정리
 
Cost-based Query Optimization in Apache Phoenix using Apache Calcite
Cost-based Query Optimization in Apache Phoenix using Apache CalciteCost-based Query Optimization in Apache Phoenix using Apache Calcite
Cost-based Query Optimization in Apache Phoenix using Apache Calcite
 
python 수학이해하기
python 수학이해하기python 수학이해하기
python 수학이해하기
 
Time based CAPTCHA protected SQL injection through SOAP-webservice
Time based CAPTCHA protected SQL injection through SOAP-webserviceTime based CAPTCHA protected SQL injection through SOAP-webservice
Time based CAPTCHA protected SQL injection through SOAP-webservice
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms master
 
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourWAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
 
Building Real-time Pipelines with FLaNK_ A Case Study with Transit Data
Building Real-time Pipelines with FLaNK_ A Case Study with Transit DataBuilding Real-time Pipelines with FLaNK_ A Case Study with Transit Data
Building Real-time Pipelines with FLaNK_ A Case Study with Transit Data
 
Working with Skewed Data: The Iterative Broadcast with Fokko Driesprong Rob K...
Working with Skewed Data: The Iterative Broadcast with Fokko Driesprong Rob K...Working with Skewed Data: The Iterative Broadcast with Fokko Driesprong Rob K...
Working with Skewed Data: The Iterative Broadcast with Fokko Driesprong Rob K...
 

Similar a Table functions - Planboard Symposium 2013

Sql interview questions
Sql interview questionsSql interview questions
Sql interview questionsnagesh Rao
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
Lecture 3. MS SQL. Cursors.
Lecture 3. MS SQL. Cursors.Lecture 3. MS SQL. Cursors.
Lecture 3. MS SQL. Cursors.Alexey Furmanov
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 functiondipumaliy
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsNirav Shah
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Dan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesDan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesEmbarcadero Technologies
 
Oracle Objects And Transactions
Oracle Objects And TransactionsOracle Objects And Transactions
Oracle Objects And Transactionstepsum
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Alex Zaballa
 
PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12Andrew Dunstan
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07AnusAhmad
 
Scaling Machine Learning Feature Engineering in Apache Spark at Facebook
Scaling Machine Learning Feature Engineering in Apache Spark at FacebookScaling Machine Learning Feature Engineering in Apache Spark at Facebook
Scaling Machine Learning Feature Engineering in Apache Spark at FacebookDatabricks
 

Similar a Table functions - Planboard Symposium 2013 (20)

Etl2
Etl2Etl2
Etl2
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Erik_van_Roon.pdf
Erik_van_Roon.pdfErik_van_Roon.pdf
Erik_van_Roon.pdf
 
Sql interview questions
Sql interview questionsSql interview questions
Sql interview questions
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
Lecture 3. MS SQL. Cursors.
Lecture 3. MS SQL. Cursors.Lecture 3. MS SQL. Cursors.
Lecture 3. MS SQL. Cursors.
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Dan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesDan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New Features
 
Oracle Objects And Transactions
Oracle Objects And TransactionsOracle Objects And Transactions
Oracle Objects And Transactions
 
Modern sql
Modern sqlModern sql
Modern sql
 
Sql functions
Sql functionsSql functions
Sql functions
 
Overview of Oracle database12c for developers
Overview of Oracle database12c for developersOverview of Oracle database12c for developers
Overview of Oracle database12c for developers
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
 
PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
 
Scaling Machine Learning Feature Engineering in Apache Spark at Facebook
Scaling Machine Learning Feature Engineering in Apache Spark at FacebookScaling Machine Learning Feature Engineering in Apache Spark at Facebook
Scaling Machine Learning Feature Engineering in Apache Spark at Facebook
 

Más de Getting value from IoT, Integration and Data Analytics

Más de Getting value from IoT, Integration and Data Analytics (20)

AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...
AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...
AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaS
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaSAMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaS
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaS
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: DataAMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure
 
10 tips voor verbetering in je Linkedin profiel
10 tips voor verbetering in je Linkedin profiel10 tips voor verbetering in je Linkedin profiel
10 tips voor verbetering in je Linkedin profiel
 
Iot in de zorg the next step - fit for purpose
Iot in de zorg   the next step - fit for purpose Iot in de zorg   the next step - fit for purpose
Iot in de zorg the next step - fit for purpose
 
Iot overview .. Best practices and lessons learned by Conclusion Conenct
Iot overview .. Best practices and lessons learned by Conclusion Conenct Iot overview .. Best practices and lessons learned by Conclusion Conenct
Iot overview .. Best practices and lessons learned by Conclusion Conenct
 
IoT Fit for purpose - how to be successful in IOT Conclusion Connect
IoT Fit for purpose - how to be successful in IOT Conclusion Connect IoT Fit for purpose - how to be successful in IOT Conclusion Connect
IoT Fit for purpose - how to be successful in IOT Conclusion Connect
 
Industry and IOT Overview of protocols and best practices Conclusion Connect
Industry and IOT Overview of protocols and best practices  Conclusion ConnectIndustry and IOT Overview of protocols and best practices  Conclusion Connect
Industry and IOT Overview of protocols and best practices Conclusion Connect
 
IoT practical case using the people counter sensing traffic density build usi...
IoT practical case using the people counter sensing traffic density build usi...IoT practical case using the people counter sensing traffic density build usi...
IoT practical case using the people counter sensing traffic density build usi...
 
R introduction decision_trees
R introduction decision_treesR introduction decision_trees
R introduction decision_trees
 
Introduction overviewmachinelearning sig Door Lucas Jellema
Introduction overviewmachinelearning sig Door Lucas JellemaIntroduction overviewmachinelearning sig Door Lucas Jellema
Introduction overviewmachinelearning sig Door Lucas Jellema
 
IoT and the Future of work
IoT and the Future of work IoT and the Future of work
IoT and the Future of work
 
Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)
Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)
Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)
 
Ethereum smart contracts - door Peter Reitsma
Ethereum smart contracts - door Peter ReitsmaEthereum smart contracts - door Peter Reitsma
Ethereum smart contracts - door Peter Reitsma
 
Blockchain - Techniek en usecases door Robert van Molken - AMIS - Conclusion
Blockchain - Techniek en usecases door Robert van Molken - AMIS - ConclusionBlockchain - Techniek en usecases door Robert van Molken - AMIS - Conclusion
Blockchain - Techniek en usecases door Robert van Molken - AMIS - Conclusion
 
kennissessie blockchain - Wat is Blockchain en smart contracts @Conclusion
kennissessie blockchain -  Wat is Blockchain en smart contracts @Conclusion kennissessie blockchain -  Wat is Blockchain en smart contracts @Conclusion
kennissessie blockchain - Wat is Blockchain en smart contracts @Conclusion
 
Internet of Things propositie - Enterprise IOT - AMIS - Conclusion
Internet of Things propositie - Enterprise IOT - AMIS - Conclusion Internet of Things propositie - Enterprise IOT - AMIS - Conclusion
Internet of Things propositie - Enterprise IOT - AMIS - Conclusion
 
Omc AMIS evenement 26012017 Dennis van Soest
Omc AMIS evenement 26012017 Dennis van SoestOmc AMIS evenement 26012017 Dennis van Soest
Omc AMIS evenement 26012017 Dennis van Soest
 

Último

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Último (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

Table functions - Planboard Symposium 2013

  • 2. About me… • Patrick Barel • Working with Oracle since 1997 • Working with PL/SQL since 1999 • Playing with APEX since 2003 (mod_plsql) • ACE since 2011 • OCA since December 20th 2012
  • 4. Download me… Plugins for PL/SQL Developer http://bar-solutions.com Plugins for Apex http://apex-plugin.com
  • 7. Patrick Barel, AMIS Mai 28th 2013 Table Functions PL/SQL in SQL
  • 8.
  • 9. Overview ofTable Functions Table Function Concepts Using Table Functions Table functions
  • 10. Table functions are functions that produce a collection of rows (either a nested table or a varray) that can be queried like a physical database table.You use a table function like the name of a database table, in the FROM clause of a query. Overview of table functions
  • 11. Define Record Type Define NestedTable type Define function returning NestedTable type Query function using the TABLE() operator Table function concepts
  • 12. • Defined as an object table of a collection – First an object type SQL> CREATE TYPE now_t AS OBJECT 2 (now VARCHAR2(8)); 3 / Type created. Table function concepts, result set
  • 13. • Defined as an object table of a collection – Second; the collection type SQL> CREATE TYPE now_tt AS 2 TABLE OF now_t; 3 / Type created. Table function concepts, result set
  • 14. • Return type is the object table CREATE OR REPLACE FUNCTION now RETURN now_tt AS l_returnvalue now_tt := now_tt(); … BEGIN … RETURN l_returnvalue; END; Table function concepts, function
  • 15. • Queried with the TABLE function SELECT * FROM TABLE(now); Table function concepts, function
  • 16. CREATE OR REPLACE FUNCTION now RETURN now_tt AS l_returnvalue now_tt := now_tt(); l_now VARCHAR2(8); BEGIN FOR counter IN 1 .. 4 LOOP l_now := to_char(SYSDATE, 'HH24:MI:SS'); dbms_lock.sleep(1); l_returnvalue.extend; l_returnvalue(l_returnvalue.last) := now_t(l_now); END LOOP; RETURN l_returnvalue; END; Table function concepts, simple function
  • 17. SQL> SELECT * 2 FROM TABLE(now) 3 / NOW -------- 16:54:21 16:54:22 16:54:23 16:54:24 4 rows selected. Table function concepts, simple function
  • 18. • Query results passed as a parameter – Parameter type is REF CURSOR – SYS_REFCURSOR can be used for weakly typed option CREATE OR REPLACE FUNCTION now_and_then (cursor_in SYS_REFCURSOR ) RETURN now_and_then_tt AS Table function concepts, nesting functions
  • 19. • CURSOR keyword denotes value passed within query SELECT * FROM TABLE(now_and_then( CURSOR ( SELECT * FROM TABLE(now)))) / Table function concepts, nesting functions
  • 20. CREATE OR REPLACE FUNCTION now_and_then (cursor_in SYS_REFCURSOR) RETURN now_and_then_tt AS l_returnvalue now_and_then_tt := now_and_then_tt(); l_now VARCHAR2(8); l_then VARCHAR2(8); BEGIN LOOP FETCH cursor_in INTO l_now; EXIT WHEN cursor_in%NOTFOUND; l_then := to_char(SYSDATE, 'HH24:MI:SS'); l_returnvalue.extend; l_returnvalue(l_returnvalue.last) := now_and_then_t(l_now, l_then); END LOOP; RETURN l_returnvalue; END; Table function concepts, nested function
  • 21. SQL> SELECT * 2 FROM TABLE ( now_and_then( CURSOR( SELECT * 3 FROM TABLE ( now )))) 4 / NOW AND_THEN -------- -------- 16:58:51 16:58:55 16:58:52 16:58:55 16:58:53 16:58:55 16:58:54 16:58:55 4 rows selected. Table function concepts, nested function
  • 22. • Function can be pipelined • Produce results as they are created – Returning results one record at a time Pipelined table functions
  • 23. • Adding PIPELINED keyword to function specification • Actual return datatype is collection • PIPE ROW function returns single record to calling process and then continues processing • Return is still required CREATE OR REPLACE FUNCTION now RETURN now_t PIPELINED AS l_returnvalue single_time_t; BEGIN loop ... PIPE ROW(l_returnvalue); ... end loop; RETURN; END; Pipelining : syntax
  • 24. CREATE OR REPLACE FUNCTION now RETURN now_tt PIPELINED AS l_returnvalue now_t; l_now VARCHAR2(8); BEGIN FOR counter IN 1 .. 4 LOOP dbms_lock.sleep(2); l_now := to_char(SYSDATE, 'HH24:MI:SS'); l_returnvalue := now_t(l_now); PIPE ROW (l_returnvalue); END LOOP; RETURN; END; Pipelined function
  • 25. SQL> SELECT * 2 FROM TABLE(now_and_then(CURSOR(SELECT * 3 FROM TABLE(now)))) 4 / NOW AND_THEN -------- -------- 19:54:15 19:54:15 19:54:17 19:54:17 19:54:19 19:54:19 3 rows selected. Pipelined function Without pipelining it would be: NOW AND_THEN -------- -------- 19:54:15 19:54:19 19:54:17 19:54:19 19:54:19 19:54:19 now_and_then.sql
  • 26. • Functions can be parallelized • If the source data can be processed in parallel, the functions can be processed in parallel Parallel table functions
  • 27. Typical data processing Stage 1 OLTP F1 F2 Data Warehouse Stage 2 F3 Data goes through several transformations, in table functions, and then gets loaded into a database
  • 28. Parallel & pipelined data processing OLTP F1 Data Warehouse F1 F1 F2 F2 F2 F3 F3 F3 Data goes through several transformations, in table functions, in parallel (multiple processes) and then gets loaded into a database
  • 29. • Prior to Oracle9i, calling a function inside a SQL statement caused serialization. – The parallel query mechanism could not be used. • Now you can enable parallel execution of a table function. – This greatly increases the usability of PL/SQL-enriched SQL in data warehouse applications. Parallel execution and table functions parallel.sql
  • 30. • The table function's parameter list must consist only of a single strongly-typed REF CURSOR. • Include the PARALLEL_ENABLE hint in the program header. – Choose a partition option that specifies how the function's execution should be partitioned. – "ANY" means that the results are independent of the order in which the function receives the input rows (through the REF CURSOR). Enabling parallel execution {[ORDER | CLUSTERORDER | CLUSTERORDER | CLUSTERORDER | CLUSTER] BY column_list} PARALLEL_ENABLEPARALLEL_ENABLEPARALLEL_ENABLEPARALLEL_ENABLE ({PARTITIONPARTITIONPARTITIONPARTITION p BYBYBYBY [ANY | (HASH | RANGE) column_list]} )
  • 31. PARALLEL_ENABLE ( Partition p_input_rows BY ANY ) CREATE OR REPLACE FUNCTION Aggregate_Xform ( p_input_rows in My_Types.cur_t) RETURN My_Types.dept_sals_tab PIPELINED CLUSTER P_INPUT_ROWS BY (dept) PARALLEL_ENABLE ( PARTITION p_input_rows BY HASH (dept) ) ORDER p_input_rows BY (c1, c2) PARALLEL_ENABLE ( PARTITION p_input_rows BY RANGE (c1) ) with with with Simplest form, results don't vary from order in which function gets input rows. All rows for a given department must go to the same slave, and rows are delivered consecutively. Rows are delivered to a particular slave as directed by partition... and will be locally sorted by that slave. Examples of parallelized functions
  • 32. Serial execution Scramble alter table emp noparallel; select * from table ( scramble ( cursor ( select empno, ename from emp)) ); EMP
  • 33. Parallel execution Scramble Scramble Scramble EMP Scramble alter table emp parallel 4; select * from table ( scramble ( cursor ( select empno, ename from emp)) );
  • 34. - Using PL/SQL in SQL - Create script based on the table data Using the table function
  • 35. • Using SQL Create script based on the table data DEPT (table) SQL statement insert into DEPT( LOC, DNAME, DEPTNO) values ( 'NEW YORK', 'ACCOUNTING', 10); insert into DEPT( LOC, DNAME, DEPTNO) values ( 'DALLAS', 'RESEARCH', 20); insert into DEPT( LOC, DNAME, DEPTNO) values ( 'CHICAGO', 'SALES', 30); insert into DEPT( LOC, DNAME, DEPTNO) values ( 'BOSTON', 'OPERATIONS', 40);
  • 36. SQL statement SELECT 'insert into DEPT( LOC, DNAME, DEPTNO) values ( '''|| LOC||''', '''|| DNAME||''', '|| DEPTNO||');' line FROM DEPT; • Using SQL Create script based on the table data
  • 37. SELECT * FROM table(createinsertscriptfor('DEPT')); SQL statement • Using table functions Create script based on the table data
  • 38. • Using table functions • Hide complexity behind PL/SQL interface • Don’t worry about datatypes Create script based on the table data
  • 39. Overview of Table Functions Table Function Concepts Return collection, query like table Pipelined Parallel UsingTable Functions Use PL/SQL in SQL Hide complexity Table functions
  • 40. tahiti.oracle.com For all documentation online Oracle PL/SQL Programming (the book) Especially chapter 17 (by Steven Feuerstein) and chapter 21 (by Steven Feuerstein with help from Adrian Billington) References