SlideShare a Scribd company logo
1
Connor McDonald
bit.ly/techguysong
PL/SQL - still super cool
Connor McDonald
Database Advocate
Copyright © 2019 Oracle and/or its affiliates.
3 3
4 4
5
6
Me
youtube bit.ly/youtube-connor
blog connor-mcdonald.com
twitter @connor_mc_d
400+ posts mainly on database & development
250 technical videos, new uploads every week
rants and raves on tech and the world :-)
7
etc...
facebook bit.ly/facebook-connor
linkedin bit.ly/linkedin-connor
instagram bit.ly/instagram-connor
slideshare bit.ly/slideshare-connor
8 8https://asktom.oracle.com
9https://asktom.oracle.com/officeho
10
before we begin
11
some ground rules...
12
this is not
Sangam 19 - PLSQL still the coolest
14
successful applications
15
my definition of success
16
meets business objectives
17
meets performance objectives
(really a business objective)
18
meets development objectives
(really a business objective)
19
meets security objectives
(really a business objective)
20
let's be real...
Sangam 19 - PLSQL still the coolest
22
make more, spend less
23
PL/SQL should help achieve this for you
24
the motivation
25
let's look at real life ...
26
"We'd never do that .... that's stupid"
27
but everyone does ... :-(
28
no matter what platform
29
30
no matter what direction
31
32
33
which leads to ...
34
"The database is slow"
Sangam 19 - PLSQL still the coolest
36
is PL/SQL the solution ?
37
remember definition of success
38
performance, maintenance, security
39
a small digression
40
utopia
Sangam 19 - PLSQL still the coolest
42
SmartDB
43
https://dzone.com/articles/the-smartdb-resource-center
44
utopia, n:
"an imagined a place or state of things in which everything is perfect."
45
100%
% people using
any form of SmartDB
46
#FAIL
47
100%
% closeness to full SmartDB
48
#FAIL
49
forget philosophy...focus on success
50
can even small PL/SQL investment help ?
performance
52
evolving to PL/SQL ...
53
.. bit by bit
54
my app = primary key lookup
55
56
SQL> create or replace
2 function simplepk(i int) return int is
3 res int;
4 begin
5 select pk
6 into res
7 from parse_demo
8 where pk = i;
9 return res;
10 end;
SimplePK
57
"PL/SQL is more expensive"
58
irony
59
"More layers...more expensive"
60 60
61
my app = a simple API
62
63
SQL> create or replace
2 procedure simpleapi(i1 int, i2 int, o1 out int, o2 out int, o3 out int) is
3 begin
4 select region_id into o1 from customer where id = i1;
5
6 for i in ( select order_id from cust_orders where cust_id = i2 )
7 loop
8 o2 := i.order_id;
9 end loop;
10
11 select count(*) into o3 from order_items where order_id = o2;
12 end;
SimpleAPI
64
let's make it "real"
sb_client
sb_server
66
the best java (et al) can do
67
it is not just latency
68
we'll come back to why shortly...
development
build
maintenance
70
benefit #1
71
"Crash Early"
"A dead program normally does a lot less damage than a crippled one."
72
C:src> type MyApp.java
...
...
PreparedStatement s =
con.prepareStatement("select any piece of old crap from dual");
...
...
C:src> javac SimplePKcache.java
[no errors]
73
SQL> create or replace
2 procedure MY_PROC is
3 begin
...
...
24 select any piece of old crap from dual;
...
...
75 end;
76 /
Warning: Procedure created with compilation errors.
74
benefit #2
75
the lazy way is the optimal way
76
rs = stmt.executeQuery(
"select ename from emp where empno = " + v_empno );
while(rs.next()) {
v_ename = rs.getInt(1);
}
PreparedStatement pstmt =
con.prepareStatement("select ename from emp where empno = ?");
pstmt.setInt(1, v_empno);
rs = pstmt.executeQuery();
while(rs.next()) {
v_ename = rs.getInt(1);
}
77
building SQL by concatenation
78
you'll get hacked
79
select ename
from emp
where empno = 6543
select ename
from emp
where empno = 6543
and 1=0
union all
select table_name
from all_tables
where table_name like '%SECURITY%'
select ename
from emp
where empno = 6543
and 1=0
union all
select username
from app_security
where ...
rs = stmt.executeQuery(
"select ename from emp where empno = " + v_empno );
80
begin
select ename
into v_ename
from emp
where empno = v_empno;
begin
dbms_sql.parse(
v_cur,
'select ename from emp where empno = '||v_empno,
dbms_sql.native );
dbms_sql.define_column(v_cur, 1, v_ename, 30);
l_status := dbms_sql.execute(v_cur);
while ( dbms_sql.fetch_rows(v_cur) > 0 ) loop
dbms_sql.column_value(v_cur, 1, v_ename);
end loop;
81
begin
execute immediate
'select ename from emp where empno = '||v_empno
into v_ename;
82
"We're safe... we use an ORM"
https://snyk.io/blog/sequelize-orm-npm-library-found-vulnerable-to-sql-injection-attacks/
84
not just static versus dynamic
85
back to performance
86
procedure GET_EMPS_FOR_JOB(p_job varchar2) is
begin
for i in (
select ename
from emp
where job = p_job
)
loop
...
end loop;
SQL> select ename from emp where job = 'SALES'
87
SELECT ENAME
FROM EMP
WHERE JOB = :B1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 10000 0.17 0.14 0 0 0 0
Fetch 10000 0.07 0.09 24 20000 0 40000
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 20001 0.25 0.24 24 20000 0 40000
88
SELECT ENAME
FROM EMP
WHERE JOB = :B1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 10000 0.17 0.14 0 0 0 0
Fetch 10000 0.07 0.09 24 20000 0 40000
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 20001 0.25 0.24 24 20000 0 40000
89
PreparedStatement pstmt =
con.prepareStatement("select ename from emp where empno = ?");
pstmt.setString(1,v_job);
rs = pstmt.executeQuery();
while(rs.next()) {
v_ename = rs.getInt(1);
}
pstmt.close();
SQL> select ename from emp where job = 'SALES'
90
select ename
from emp
where job = :1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 10000 0.06 0.10 0 0 0 0
Execute 10000 0.14 0.15 0 0 0 0
Fetch 40000 0.12 0.10 24 40000 0 40000
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 50000 0.32 0.37 24 40000 0 40000
91
select ename
from emp
where job = :1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 10000 0.06 0.10 0 0 0 0
Execute 10000 0.14 0.15 0 0 0 0
Fetch 40000 0.12 0.10 24 40000 0 40000
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 50000 0.32 0.37 24 40000 0 40000
92
OracleDataSource ods = new OracleDataSource();
ods.setImplicitCachingEnabled( true );
Properties cacheProps = new Properties();
cacheProps.put( "MaxStatementsLimit", "50" );
ods.setConnectionCacheProperties( cacheProps );
PreparedStatement pstmt =
con.prepareStatement("select ename from emp where empno = ?");
pstmt.setFetchSize(100);
pstmt.setString(1,v_job);
rs = pstmt.executeQuery();
while(rs.next()) {
v_ename = rs.getInt(1);
}
pstmt.close();
SQL> select ename from emp where job = 'SALES'
103
"It's good enough for me"
104
totally fine but ...
Sangam 19 - PLSQL still the coolest
107
benefit #3
108
no application is 100% complete
109
data loading, data patching
110
archival, adhoc query
111
a common build criticism
112
"No private sandbox"
113
true ... in the past
114
115
115
Sangam 19 - PLSQL still the coolest
117
<= 3 pluggables
19c
118
Oracle XE
119
100% free
development
build
maintenance
121
benefits #1
122
free dependency analysis
123
SQL> desc DBA_DEPENDENCIES
Name Null? Type
----------------------------- -------- --------------------
OWNER NOT NULL VARCHAR2(128)
NAME NOT NULL VARCHAR2(128)
TYPE VARCHAR2(19)
REFERENCED_OWNER VARCHAR2(128)
REFERENCED_NAME VARCHAR2(128)
REFERENCED_TYPE VARCHAR2(19)
REFERENCED_LINK_NAME VARCHAR2(128)
DEPENDENCY_TYPE VARCHAR2(4)
124
SQL> create or replace
2 procedure MY_PROC is
3 v_ename scott.emp.ename%type;
4 begin
5 select ename
6 into v_ename
7 from scott.emp
8 where 1=0;
9 end;
10 /
SQL> select name, referenced_name
2 from dba_dependencies
3 where name = 'MY_PROC';
NAME REFERENCED_NAME
-------------------- -------------------------------------
MY_PROC STANDARD
MY_PROC EMP
125
a common maintenance criticism
126
"Deployment means down time"
127
packages
128
break the invalidation chain
proc A proc B proc C proc D
pack A pack B pack C pack D
body A body B body C body D
11g and beyond
pack A pack B pack C pack D
body A body B body C
body D
132
12c and beyond
133
edition based redefinition
134
procedure MY_PROC is
begin
...
... "v1 code"
...
end;
procedure MY_PROC is
begin
...
... "v2 code"
...
end;
security
136
benefit #1
137
the opportunity of better security
138
SQL> select username, program from v$session;
USERNAME PROGRAM
-------------------- ----------------------------
MY_SCHEMA JDBC Thin Client
MY_SCHEMA JDBC Thin Client
MY_SCHEMA JDBC Thin Client
MY_SCHEMA JDBC Thin Client
MY_SCHEMA JDBC Thin Client
MY_SCHEMA JDBC Thin Client
...
...
139
TABLES
MY_SCHEMA
140
there isn't a limit on schemas
141
least privilege is the best privilege
142
nothing connects to the data owner ... ever
143
ins,upd,del,sel privs
APP_CONNECTING
TABLES
MY_SCHEMA
144
execute privs
APP_CONNECTING
TABLES
MY_SCHEMA
PL/SQL
145
select privs
execute privs
APP_CONNECTING
TABLES
MY_SCHEMA
PL/SQL
146
benefit #2 - corollary
147
execute privs
APP_CONNECTING
TABLES
MY_SCHEMA
PL/SQL
148
triggers
149
triggers are hard
150
putting theory into practice
151
customer example
Sangam 19 - PLSQL still the coolest
153
development team
C++
C#
no Oracle experience
no database experience !
155
C#, C++ ESB Tuxedo
Weblogic
156
public static void RaceStarted(int race_id)
{
...
}
public static void HorseScratched(int race_id, int horse_id)
{
...
}
public static void NewCustomer(int cust_seq, ...)
{
...
}
public static void DepositIntoAccount(int ...)
{
...
}
157
plus hundreds more...
158
PROCEDURE customer_bet(
p_transaction_ts IN timestamp
,p_bet_type IN bet.bet_type%TYPE
,p_store IN bet.store%TYPE
,p_accountnum IN bet.bet_account_num%TYPE
,p_amount IN bet.amount%TYPE
...
);
PROCEDURE pay_winner(
p_transaction_ts IN timestamp
,p_bet_seq IN bet.bet_seq%TYPE
,p_bet_type IN bet.bet_type%TYPE
,p_store IN bet.store%TYPE
,p_accountnum IN bet.bet_account_num%TYPE
,p_amount_to_pay IN bet.paid_payout%TYPE
,p_amount_to_refund IN bet.paid_refunds%TYPE
...
);
159
that's it!
160
the benefits can be addictive
161
pl/sql c#
162
"We added one procedure to solve one problem,
then another procedure to solve another problem,
and very quickly...now they want PLSQL everywhere"
- Office Hours, June 2019
163
addressing some common criticisms
164
"PL/SQL is not object oriented"
165
OO principles
166
167
PL/SQL
168
"We don't have PL/SQL skills"
169
procedural language
170
if-then-else, loop, subroutines, parameters
171
"We struggle with SQL"
172
"We struggle with good PL/SQL"
173
it ... doesn't ... matter
174
utopia
175
wrap up
176
it doesn't have to be a war
177
it doesn't have to be utopia
178
PL/SQL is easy to learn, easy to write
179
good wins for small effort
180
kick starts the journey to big wins
181
Sangam 19 - PLSQL still the coolest
183
Thank you
youtube bit.ly/youtube-connor
blog connor-mcdonald.com
twitter @connor_mc_d

More Related Content

PDF
Flashback ITOUG
PDF
UKOUG - 25 years of hints and tips
PDF
UKOUG 2019 - SQL features
PDF
Sangam 2019 - The Latest Features
PDF
Sangam 19 - Analytic SQL
PPTX
SQL techniques for faster applications
PDF
Sangam 19 - Successful Applications on Autonomous
PDF
KScope19 - SQL Features
Flashback ITOUG
UKOUG - 25 years of hints and tips
UKOUG 2019 - SQL features
Sangam 2019 - The Latest Features
Sangam 19 - Analytic SQL
SQL techniques for faster applications
Sangam 19 - Successful Applications on Autonomous
KScope19 - SQL Features

What's hot (20)

PDF
APEX Connect 2019 - array/bulk processing in PLSQL
PDF
Latin America Tour 2019 - 10 great sql features
PPTX
Using SQL to process hierarchies
PDF
ANSI vs Oracle language
PDF
Latin America Tour 2019 - pattern matching
PPT
Dbms plan - A swiss army knife for performance engineers
PDF
APEX Connect 2019 - SQL Tuning 101
PDF
pstack, truss etc to understand deeper issues in Oracle database
PDF
Latin America tour 2019 - Flashback
PPTX
SQL Tuning 101 - Sep 2013
PPTX
Analytic SQL Sep 2013
PDF
Oracle Database 12c Application Development
PDF
Oracle trace data collection errors: the story about oceans, islands, and rivers
PDF
Most important "trick" of performance instrumentation
PDF
Performance tuning a quick intoduction
PDF
Pattern Matching with SQL - APEX World Rotterdam 2019
PDF
A close encounter_with_real_world_and_odd_perf_issues
PPTX
OpenWorld 2018 - 20 years of hints and tips
PDF
Connor McDonald 11g for developers
KEY
実践 memcached
APEX Connect 2019 - array/bulk processing in PLSQL
Latin America Tour 2019 - 10 great sql features
Using SQL to process hierarchies
ANSI vs Oracle language
Latin America Tour 2019 - pattern matching
Dbms plan - A swiss army knife for performance engineers
APEX Connect 2019 - SQL Tuning 101
pstack, truss etc to understand deeper issues in Oracle database
Latin America tour 2019 - Flashback
SQL Tuning 101 - Sep 2013
Analytic SQL Sep 2013
Oracle Database 12c Application Development
Oracle trace data collection errors: the story about oceans, islands, and rivers
Most important "trick" of performance instrumentation
Performance tuning a quick intoduction
Pattern Matching with SQL - APEX World Rotterdam 2019
A close encounter_with_real_world_and_odd_perf_issues
OpenWorld 2018 - 20 years of hints and tips
Connor McDonald 11g for developers
実践 memcached
Ad

Similar to Sangam 19 - PLSQL still the coolest (20)

PDF
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
PPT
High Performance Jdbc
PPTX
OpenWorld 2018 - Common Application Developer Disasters
PDF
APEX tour 2019 - successful development with autonomous
PDF
Database and application performance vivek sharma
PPTX
Sql and PL/SQL Best Practices I
PDF
Ebs dba con4696_pdf_4696_0001
PPTX
Web 2.0 Development with IBM DB2
PDF
OOW19 - Slower and less secure applications
PPTX
Server-Side Development for the Cloud
PDF
APEX Connect 2019 - successful application development
PDF
Feb14 successful development
PDF
High performance database applications with pure query and ibm data studio.ba...
PPTX
PostgreSQL Database Slides
PPTX
Sangam 18 - Database Development: Return of the SQL Jedi
PPTX
PL/SQL User-Defined Functions in the Read World
PPTX
Thinking Beyond ORM in JPA
PPT
08 Dynamic SQL and Metadata
PDF
JDBC Next: A New Asynchronous API for Connecting to a Database
PDF
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
High Performance Jdbc
OpenWorld 2018 - Common Application Developer Disasters
APEX tour 2019 - successful development with autonomous
Database and application performance vivek sharma
Sql and PL/SQL Best Practices I
Ebs dba con4696_pdf_4696_0001
Web 2.0 Development with IBM DB2
OOW19 - Slower and less secure applications
Server-Side Development for the Cloud
APEX Connect 2019 - successful application development
Feb14 successful development
High performance database applications with pure query and ibm data studio.ba...
PostgreSQL Database Slides
Sangam 18 - Database Development: Return of the SQL Jedi
PL/SQL User-Defined Functions in the Read World
Thinking Beyond ORM in JPA
08 Dynamic SQL and Metadata
JDBC Next: A New Asynchronous API for Connecting to a Database
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
Ad

More from Connor McDonald (13)

PDF
APAC Groundbreakers 2019 - Perth/Melbourne
PDF
OOW19 - Flashback, not just for DBAs
PDF
OOW19 - Read consistency
PDF
OOW19 - Killing database sessions
PDF
OOW19 - Ten Amazing SQL features
PDF
Latin America Tour 2019 - 18c and 19c featues
PDF
Latin America Tour 2019 - slow data and sql processing
PDF
OG Yatra - upgrading to the new 12c+ optimizer
PDF
OG Yatra - 25 years of hints and tips
PDF
OG Yatra - Flashback, not just for developers
PDF
Kscope19 - Flashback: Good for Developers as well as DBAs
PDF
Kscope19 - Understanding the basics of SQL processing
PDF
18c and 19c features for DBAs
APAC Groundbreakers 2019 - Perth/Melbourne
OOW19 - Flashback, not just for DBAs
OOW19 - Read consistency
OOW19 - Killing database sessions
OOW19 - Ten Amazing SQL features
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019 - slow data and sql processing
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - 25 years of hints and tips
OG Yatra - Flashback, not just for developers
Kscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Understanding the basics of SQL processing
18c and 19c features for DBAs

Recently uploaded (20)

PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
project resource management chapter-09.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
A Presentation on Touch Screen Technology
PDF
Getting Started with Data Integration: FME Form 101
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
Mushroom cultivation and it's methods.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Zenith AI: Advanced Artificial Intelligence
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Tartificialntelligence_presentation.pptx
project resource management chapter-09.pdf
TLE Review Electricity (Electricity).pptx
A Presentation on Touch Screen Technology
Getting Started with Data Integration: FME Form 101
NewMind AI Weekly Chronicles - August'25-Week II
Building Integrated photovoltaic BIPV_UPV.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
Group 1 Presentation -Planning and Decision Making .pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
A comparative analysis of optical character recognition models for extracting...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Hybrid model detection and classification of lung cancer
Mushroom cultivation and it's methods.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Programs and apps: productivity, graphics, security and other tools
Chapter 5: Probability Theory and Statistics
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Zenith AI: Advanced Artificial Intelligence

Sangam 19 - PLSQL still the coolest