SlideShare a Scribd company logo
1 of 15
Download to read offline
9/16/2013
1
Exploring PL/SQL New Features and
Best Practices for Better Performance
Ami Aharonovich
Oracle ACE & OCP
Ami@DBAces.co.il
Who am I
• Oracle ACE
• Oracle Certified Professional DBA (OCP)
• Founder and CEO, DBAces
• Oracle DBA consultant and instructor, specializes in Oracle
database core technologies
• Specializes in training Oracle courses around the world
• Frequent speaker at the Oracle Open World convention
• President, Israel Oracle User Group
9/16/2013
2
Agenda
• Oracle SQL Developer: Overview
• PL/SQL Performance and Tuning:
– Parsing Time is Important
– Using Bulk Binding
– PL/SQL Function Result Cache
– Subprogram Inlining
– Finer Grained Dependencies
• New Features in Oracle Database 12c
• PL/SQL Best Practices and Guidelines
About My Presentation
• My slides and examples are based on:
– DBAces course: Exploring Oracle database 11g new features
and best practices for database developers and DBAs
– My presentations delivered at Oracle Open World
– Tom Kyte ilOUG seminar: “Ask Tom Kyte Live in Israel”
– My knowledge and experience
– Internet
9/16/2013
3
Oracle SQL Developer: Overview
• Free and fully supported graphical integrated development
environment that simplifies the development and
management of Oracle Database
• Oracle SQL Developer offers a complete:
– End-to-end development of your PL/SQL applications
– Worksheet for running queries and scripts
– DBA console for managing the database
– Reports interface
– Data modeling solution
– Migration platform for moving 3rd party databases to Oracle
Oracle SQL Developer: Overview
• Oracle SQL Developer supports Oracle Database 12c:
– Oracle Database 12c new features
– Manage Multitenant Pluggable Databases
– Oracle Database 12c Data Redaction in SQL Developer
9/16/2013
4
More Info on Oracle SQL Developer
• Prebuilt virtual machine with Database 11.2 & SQL Developer
http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html
• Oracle SQL Developer on OTN
www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html
• Oracle SQL Developer Documentation
http://docs.oracle.com/cd/E35137_01/index.htm
• Oracle SQL Developer Exchange
http://htmldb.oracle.com/pls/otn/f?p=42626:16:695907153071056::NO:::
• Oracle SQL Developer Forum
http://forums.oracle.com/forums/forum.jspa?forumID=260
• Oracle By Example (OBE), Demos and Tutorials at the Oracle
Learning Library
www.oracle.com/technetwork/developer-tools/sql-developer/obe-082749.html
Parsing Time is Important
BEGIN
FOR i IN 1..100000 LOOP
EXECUTE IMMEDIATE 'INSERT INTO t (x,y)
VALUES ('||i||',''A'')';
END LOOP;
END;
/
PL/SQL procedure successfully completed.
Elapsed: 00:00:42.91
Parsing_Time_is_Important.sql
9/16/2013
5
Parsing Time is Important
BEGIN
FOR i IN 1..100000 LOOP
EXECUTE IMMEDIATE 'INSERT INTO t (x,y)
VALUES (:i,''A'')' USING i;
END LOOP;
END;
/
PL/SQL procedure successfully completed.
Elapsed: 00:00:08.26
Parsing Time is Important
SELECT SUBSTR(sql_text,11,8) "Bind", COUNT(*),
ROUND(SUM(sharable_mem)/1024) "Memory KB"
FROM v$sqlarea
WHERE sql_text LIKE 'INSERT%INTO t (x,y)%'
GROUP BY SUBSTR(sql_text,11,8);
Bind COUNT(*) Memory KB
------------ ------------ ------------
NO_BIND 9,349 131,580
USE_BIND 1 14
9/16/2013
6
Using Bulk Binding
• Save context switch – better performance!
• Bind whole array of values simultaneously rather than
looping to perform fetch, insert, update and delete on
multiple rows
• Use BULK COLLECT – for SELECT statements
• Use FORALL – for DML statements
• Use the RETURNING clause to retrieve information
about the rows that are being modified
• Works also with dynamic SQL
Using Bulk Binding
• In case index numbers are not consecutive
– Use INDICES OF with or without bounds
– Use VALUES OF for associative array indexed by PLS_INTEGER
• Use SAVE EXCEPTIONS in your FORALL statements:
– Exceptions raised during execution are saved in the
%BULK_EXCEPTIONS cursor attribute
– Collection of records with two fields: ERROR_INDEX and
ERROR_CODE
FORALL index IN lower_bound..upper_bound
SAVE EXCEPTIONS
{insert_stmt | update_stmt | delete_stmt}
9/16/2013
7
Bulk SQL – Examples
• SELECT id BULK COLLECT INTO …
• FETCH emp_cur BULK COLLECT INTO …
• DELETE … RETURNING … BULK COLLECT INTO …
• FORALL i IN … UPDATE …
• FORALL i IN INDICES OF … INSERT …
Bulk.sql
It’s All About Caching
• Accessing memory is far quicker than accessing hard drives
• This fact gives rise to caching: the process of storing data in
memory instead of disks
• Caching is a common principle of Oracle database
architecture, in which users are fed data from the buffer
cache instead of the disks on where the database resides
• Oracle database 11g enhances performance by using:
– SQL Query Result Cache
– PL/SQL Function Result Cache
– Client Query Result Cache
9/16/2013
8
What is PL/SQL Function Result Cache?
• In the past, if you called a PL/SQL function 1,000 times and
each function call consumed 1 second, the 1,000 calls would
take 1,000 seconds
• With this new function results cache feature, depending on
the inputs to the function and whether the data underlying
the function changes, 1,000 function calls could take about
1 second, total
PL/SQL Function Result Cache
• Allows storing the results of PL/SQL functions in the SGA
• Caching mechanism is both efficient and easy to use
• Relieves you of the burden of designing and developing your own
caches and cache management policies
• Provides the ability to mark a PL/SQL function to indicate that its
result should be cached to allow lookup, rather than
recalculation, when the same parameter values are called
• Saves significant space and time
• Done transparently using the input parameters as the lookup key
• Instancewide – all distinct sessions invoking the function benefit
9/16/2013
9
Using PL/SQL Function Result Cache
• Include the RESULT_CACHE option in the function
declaration section of a package or function definition
CREATE OR REPLACE FUNCTION ProductName
(prod_id NUMBER, lang_id VARCHAR2)
RETURN NVARCHAR2
RESULT_CACHE
IS
result VARCHAR2(50);
BEGIN
SELECT translated_name INTO result FROM product_descriptions
WHERE product_id = prod_id AND language_id = lang_id;
RETURN result;
END;
PLSQL_Function_Result_Cache.sql
Subprogram Inlining
• Every call to a procedure or function causes a slight, but
measurable, performance overhead, which is especially
noticeable when the subprogram is called within a loop
• Automatic subprogram inlining can reduce the overheads
associated with calling subprograms, whilst leaving your
original source code in its normal modular state
• This is done by replacing the subprogram calls with a copy
of the code in the subprogram at compile time
9/16/2013
10
Subprogram Inlining
• Controlled by the PLSQL_OPTIMIZE_LEVEL parameter and
the INLINE pragma
• PLSQL_OPTIMIZE_LEVEL=2 (the default)
– INLINE pragma determines whether the following statement
or declaration should be inlined or not
• PLSQL_OPTIMIZE_LEVEL=3
– Optimizer may inline code automatically
– INLINE pragma can turn it off inlining for a statement or
increase the likelihood that the optimizer will choose to inline
a statement
Subprogram_Inlining.sql
Finer Grained Dependencies
• In previous releases, metadata recorded mutual
dependencies between objects with the granularity of the
whole object
• This means that dependent objects were sometimes
invalidated when there was no logical requirement to do so
• Oracle Database 11g records dependency metatdata at a
finer level of granularity
9/16/2013
11
Finer Grained Dependencies
• By reducing the consequential invalidation of dependent
objects in response to changes in the objects they depend
upon, application availability is increased
• The benefit is felt both in the development environment
and when a live application is parsed or upgraded
• Changes to schema objects does not cause consequential
invalidations
Finer_Grained_Dependencies.sql
New Features in Oracle Database 12c
• Invisible Columns
• Grant Roles to Code
• PL/SQL from SQL
• Improved Defaults:
– Default to a sequence
– Default when null inserted
– Identity type
• Enhanced Statistics:
– Statistics during loads
– Session private statistics for GTT’s
9/16/2013
12
12c Invisible Column
CREATE TABLE demo
(col1 NUMBER, col2 NUMBER, col3 NUMBER INVISIBLE);
DESCRIBE demo
Name Null? Type
--------------- ---------------- ---------------
COL1 NUMBER
COL2 NUMBER
INSERT INTO demo VALUES (1,2);
INSERT INTO demo (col1,col2,col3) VALUES (1,2,3);
12c Invisible Column
SELECT * FROM demo;
COL1 COL2
---------- ----------
1 2
1 2
SELECT col1, col2, col3 FROM demo;
COL1 COL2 COL3
---------- ---------- ----------
1 2
1 2 3
9/16/2013
13
12c Invisible Column
ALTER TABLE demo MODIFY (col2 INVISIBLE);
ALTER TABLE demo MODIFY (col3 VISIBLE);
SELECT column_name,column_id
FROM user_tab_columns
WHERE table_name=’DEMO’;
COLUMN_NAME COLUMN_ID
--------------- ---------------
COL1 1
COL3 2
COL2
PL/SQL Best Practices and Guidelines
• SQL is usually quicker than PL/SQL
• Avoid using procedural code when SQL code may be better
• Use bulk binds to reduce context switches between the
PL/SQL engine and the SQL engine
• Do not use UTL_FILE to read text files if you can use External
Tables instead
• Do not write PL/SQL merges if you can use SQL MERGE
• Use DML Error Handling (DBMS_ERRLOG) to trap failures in
DML rather than coding PL/SQL
9/16/2013
14
PL/SQL Best Practices and Guidelines
• Use PLS_INTEGER when dealing with integer data
– Efficient data type for integer variables
– Requires less storage than INTEGER or NUMBER
– Operations use machine arithmetic which is faster
• Beware of implicit data type conversions
• Modularize your code:
– Limit the number of lines of code between a BEGIN and END
– Use packaged programs to keep smaller executable sections
– Use local procedures and functions to hide logic
– Use a function interface to hide formulas and business rules
PL/SQL Best Practices and Guidelines
• Write readable code:
– Use UPPER and lower case
– Use indentation
– Avoid using hard-coded literals
– Use anchored declarations when possible
– Use cursor FOR loop
9/16/2013
15
Some Stuff to Read on the Web
• Oracle Database New Features Guide 11g Release 2 (11.2)
http://download.oracle.com/docs/cd/E11882_01/server.112/e17128/toc.htm
• Oracle Database PL/SQL Language Reference 12c Release 1 (12.1)
http://docs.oracle.com/cd/E16655_01/appdev.121/e17622/release_changes.htm
• PL/SQL Performance
http://www.oracle.com/technetwork/articles/sql/11g-plsql-091775.html
• Efficient PL/SQL Coding
http://www.oracle.com/technetwork/articles/sql/11g-efficient-coding-093640.html
• Oracle 12c Articles
http://www.oracle-base.com/articles/12c/articles-12c.php
Exploring PL/SQL New Features and
Best Practices for Better Performance
Ami Aharonovich
Oracle ACE & OCP
Ami@DBAces.co.il
Thank You !

More Related Content

What's hot

Oracle database 12.2 new features
Oracle database 12.2 new featuresOracle database 12.2 new features
Oracle database 12.2 new featuresAlfredo Krieg
 
Best New Features of Oracle Database 12c
Best New Features of Oracle Database 12cBest New Features of Oracle Database 12c
Best New Features of Oracle Database 12cPini Dibask
 
Oracle SQL tuning with SQL Plan Management
Oracle SQL tuning with SQL Plan ManagementOracle SQL tuning with SQL Plan Management
Oracle SQL tuning with SQL Plan ManagementBjoern Rost
 
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft EngineerPLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft EngineerMarek Maśko
 
Oracle ebs capacity_analysisusingstatisticalmethods
Oracle ebs capacity_analysisusingstatisticalmethodsOracle ebs capacity_analysisusingstatisticalmethods
Oracle ebs capacity_analysisusingstatisticalmethodsAjith Narayanan
 
Internals of concurent managers
Internals of concurent managersInternals of concurent managers
Internals of concurent managersMaris Elsins
 
Best practices for large oracle apps r12 implementations apps14
Best practices for large oracle apps r12 implementations apps14Best practices for large oracle apps r12 implementations apps14
Best practices for large oracle apps r12 implementations apps14Ajith Narayanan
 
Oracle Enterprise Manager 12c: The Oracle Monitoring tool of choice – Why yo...
Oracle Enterprise Manager 12c:  The Oracle Monitoring tool of choice – Why yo...Oracle Enterprise Manager 12c:  The Oracle Monitoring tool of choice – Why yo...
Oracle Enterprise Manager 12c: The Oracle Monitoring tool of choice – Why yo...Jeff Kayser
 
Performance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12cPerformance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12cAjith Narayanan
 
Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)
Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)
Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)Laurent Leturgez
 
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...Maris Elsins
 
Oracle 12c Parallel Execution New Features
Oracle 12c Parallel Execution New FeaturesOracle 12c Parallel Execution New Features
Oracle 12c Parallel Execution New FeaturesRandolf Geist
 
Oracle 12c New Features for Developers
Oracle 12c New Features for DevelopersOracle 12c New Features for Developers
Oracle 12c New Features for DevelopersCompleteITProfessional
 
SAP HANA Distributed System Scaleout and HA
SAP HANA Distributed System Scaleout and HASAP HANA Distributed System Scaleout and HA
SAP HANA Distributed System Scaleout and HALinh Nguyen
 
Sap basis-transaction-codes
Sap basis-transaction-codesSap basis-transaction-codes
Sap basis-transaction-codesKarthikN157
 
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
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharmaaioughydchapter
 
Oracle Database 12c "New features"
Oracle Database 12c "New features" Oracle Database 12c "New features"
Oracle Database 12c "New features" Anar Godjaev
 

What's hot (20)

Oracle database 12.2 new features
Oracle database 12.2 new featuresOracle database 12.2 new features
Oracle database 12.2 new features
 
Best New Features of Oracle Database 12c
Best New Features of Oracle Database 12cBest New Features of Oracle Database 12c
Best New Features of Oracle Database 12c
 
Oracle SQL tuning with SQL Plan Management
Oracle SQL tuning with SQL Plan ManagementOracle SQL tuning with SQL Plan Management
Oracle SQL tuning with SQL Plan Management
 
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft EngineerPLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
 
Oracle ebs capacity_analysisusingstatisticalmethods
Oracle ebs capacity_analysisusingstatisticalmethodsOracle ebs capacity_analysisusingstatisticalmethods
Oracle ebs capacity_analysisusingstatisticalmethods
 
Avoid boring work_v2
Avoid boring work_v2Avoid boring work_v2
Avoid boring work_v2
 
Internals of concurent managers
Internals of concurent managersInternals of concurent managers
Internals of concurent managers
 
Best practices for large oracle apps r12 implementations apps14
Best practices for large oracle apps r12 implementations apps14Best practices for large oracle apps r12 implementations apps14
Best practices for large oracle apps r12 implementations apps14
 
Oracle Enterprise Manager 12c: The Oracle Monitoring tool of choice – Why yo...
Oracle Enterprise Manager 12c:  The Oracle Monitoring tool of choice – Why yo...Oracle Enterprise Manager 12c:  The Oracle Monitoring tool of choice – Why yo...
Oracle Enterprise Manager 12c: The Oracle Monitoring tool of choice – Why yo...
 
Performance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12cPerformance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12c
 
Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)
Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)
Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)
 
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
 
Oracle 12c Parallel Execution New Features
Oracle 12c Parallel Execution New FeaturesOracle 12c Parallel Execution New Features
Oracle 12c Parallel Execution New Features
 
Oracle 12c New Features for Developers
Oracle 12c New Features for DevelopersOracle 12c New Features for Developers
Oracle 12c New Features for Developers
 
SAP HANA Distributed System Scaleout and HA
SAP HANA Distributed System Scaleout and HASAP HANA Distributed System Scaleout and HA
SAP HANA Distributed System Scaleout and HA
 
Sap basis-transaction-codes
Sap basis-transaction-codesSap basis-transaction-codes
Sap basis-transaction-codes
 
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
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharma
 
Awr doag
Awr doagAwr doag
Awr doag
 
Oracle Database 12c "New features"
Oracle Database 12c "New features" Oracle Database 12c "New features"
Oracle Database 12c "New features"
 

Similar to Exploring plsql new features best practices september 2013

The Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result CacheThe Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result CacheSteven Feuerstein
 
Optimizing applications and database performance
Optimizing applications and database performanceOptimizing applications and database performance
Optimizing applications and database performanceInam Bukhary
 
COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesAlfredo Abate
 
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
 
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
 
Migrating to Database 12c Multitenant - New Opportunities To Get It Right!
Migrating to Database 12c Multitenant - New Opportunities To Get It Right!Migrating to Database 12c Multitenant - New Opportunities To Get It Right!
Migrating to Database 12c Multitenant - New Opportunities To Get It Right!Performance Tuning Corporation
 
Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...
Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...
Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...InSync2011
 
Turbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk ProcessingTurbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk ProcessingSteven Feuerstein
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2Alex Zaballa
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2Alex Zaballa
 
2008 Collaborate IOUG Presentation
2008 Collaborate IOUG Presentation2008 Collaborate IOUG Presentation
2008 Collaborate IOUG PresentationBiju Thomas
 

Similar to Exploring plsql new features best practices september 2013 (20)

The Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result CacheThe Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result Cache
 
Optimizing applications and database performance
Optimizing applications and database performanceOptimizing applications and database performance
Optimizing applications and database performance
 
COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_Features
 
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...
 
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
 
Migrating to Database 12c Multitenant - New Opportunities To Get It Right!
Migrating to Database 12c Multitenant - New Opportunities To Get It Right!Migrating to Database 12c Multitenant - New Opportunities To Get It Right!
Migrating to Database 12c Multitenant - New Opportunities To Get It Right!
 
OOW13 Exadata and ODI with Parallel
OOW13 Exadata and ODI with ParallelOOW13 Exadata and ODI with Parallel
OOW13 Exadata and ODI with Parallel
 
Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...
Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...
Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...
 
Turbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk ProcessingTurbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk Processing
 
Ora 4 the_sqldba
Ora 4 the_sqldbaOra 4 the_sqldba
Ora 4 the_sqldba
 
Plantilla oracle
Plantilla oraclePlantilla oracle
Plantilla oracle
 
ow.ppt
ow.pptow.ppt
ow.ppt
 
ow.ppt
ow.pptow.ppt
ow.ppt
 
Ow
OwOw
Ow
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2
 
Using AWR for SQL Analysis
Using AWR for SQL AnalysisUsing AWR for SQL Analysis
Using AWR for SQL Analysis
 
01 oracle architecture
01 oracle architecture01 oracle architecture
01 oracle architecture
 
2008 Collaborate IOUG Presentation
2008 Collaborate IOUG Presentation2008 Collaborate IOUG Presentation
2008 Collaborate IOUG Presentation
 

More from Andrejs Vorobjovs

Peteris Arajs - Where is my data
Peteris Arajs - Where is my dataPeteris Arajs - Where is my data
Peteris Arajs - Where is my dataAndrejs Vorobjovs
 
Maksims Greckis - Trace File Analyzer
Maksims Greckis - Trace File Analyzer  Maksims Greckis - Trace File Analyzer
Maksims Greckis - Trace File Analyzer Andrejs Vorobjovs
 
Aleksejs Nemirovskis - Manage your data using oracle BDA
Aleksejs Nemirovskis - Manage your data using oracle BDAAleksejs Nemirovskis - Manage your data using oracle BDA
Aleksejs Nemirovskis - Manage your data using oracle BDAAndrejs Vorobjovs
 
My two cents about Mysql backup
My two cents about Mysql backupMy two cents about Mysql backup
My two cents about Mysql backupAndrejs Vorobjovs
 
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories. Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories. Andrejs Vorobjovs
 
OTN tour 2015 press release in Russian
OTN tour 2015 press release in RussianOTN tour 2015 press release in Russian
OTN tour 2015 press release in RussianAndrejs Vorobjovs
 
OTN tour 2015 benchmarking oracle io performance with Orion by Alex Gorbachev
OTN tour 2015 benchmarking oracle io performance with Orion by Alex GorbachevOTN tour 2015 benchmarking oracle io performance with Orion by Alex Gorbachev
OTN tour 2015 benchmarking oracle io performance with Orion by Alex GorbachevAndrejs Vorobjovs
 
OTN tour 2015 Oracle Enterprise Manager 12c – Proof of Concept
OTN tour 2015 Oracle Enterprise Manager 12c – Proof of ConceptOTN tour 2015 Oracle Enterprise Manager 12c – Proof of Concept
OTN tour 2015 Oracle Enterprise Manager 12c – Proof of ConceptAndrejs Vorobjovs
 
OTN tour Oracle db Cloud by Alex Gorbachev
OTN tour Oracle db Cloud by Alex GorbachevOTN tour Oracle db Cloud by Alex Gorbachev
OTN tour Oracle db Cloud by Alex GorbachevAndrejs Vorobjovs
 
OTN tour 2015 Experience in implementing SSL between oracle db and oracle cli...
OTN tour 2015 Experience in implementing SSL between oracle db and oracle cli...OTN tour 2015 Experience in implementing SSL between oracle db and oracle cli...
OTN tour 2015 Experience in implementing SSL between oracle db and oracle cli...Andrejs Vorobjovs
 
OTN tour 2015 AWR data mining
OTN tour 2015 AWR data miningOTN tour 2015 AWR data mining
OTN tour 2015 AWR data miningAndrejs Vorobjovs
 

More from Andrejs Vorobjovs (20)

Peteris Arajs - Where is my data
Peteris Arajs - Where is my dataPeteris Arajs - Where is my data
Peteris Arajs - Where is my data
 
Maksims Greckis - Trace File Analyzer
Maksims Greckis - Trace File Analyzer  Maksims Greckis - Trace File Analyzer
Maksims Greckis - Trace File Analyzer
 
Aleksejs Nemirovskis - Manage your data using oracle BDA
Aleksejs Nemirovskis - Manage your data using oracle BDAAleksejs Nemirovskis - Manage your data using oracle BDA
Aleksejs Nemirovskis - Manage your data using oracle BDA
 
LVOUG meetup #18
LVOUG meetup #18LVOUG meetup #18
LVOUG meetup #18
 
LVOUG meetup #17
LVOUG meetup #17LVOUG meetup #17
LVOUG meetup #17
 
My two cents about Mysql backup
My two cents about Mysql backupMy two cents about Mysql backup
My two cents about Mysql backup
 
LVOUG meetup #16
LVOUG meetup #16LVOUG meetup #16
LVOUG meetup #16
 
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories. Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
Middleware upgrade to Oracle Fusion Middleware(FMW) 12c.Real Case stories.
 
Top 15 MySQL parameters
Top 15 MySQL parameters Top 15 MySQL parameters
Top 15 MySQL parameters
 
Riga Dev Day vestule
Riga Dev Day vestuleRiga Dev Day vestule
Riga Dev Day vestule
 
Rdd2016 featured talks
Rdd2016 featured talksRdd2016 featured talks
Rdd2016 featured talks
 
Rdd2016 flyer
Rdd2016 flyerRdd2016 flyer
Rdd2016 flyer
 
meetup #15
meetup #15meetup #15
meetup #15
 
OTN tour 2015 press release in Russian
OTN tour 2015 press release in RussianOTN tour 2015 press release in Russian
OTN tour 2015 press release in Russian
 
OTN tour 2015, 100miles
OTN tour 2015, 100milesOTN tour 2015, 100miles
OTN tour 2015, 100miles
 
OTN tour 2015 benchmarking oracle io performance with Orion by Alex Gorbachev
OTN tour 2015 benchmarking oracle io performance with Orion by Alex GorbachevOTN tour 2015 benchmarking oracle io performance with Orion by Alex Gorbachev
OTN tour 2015 benchmarking oracle io performance with Orion by Alex Gorbachev
 
OTN tour 2015 Oracle Enterprise Manager 12c – Proof of Concept
OTN tour 2015 Oracle Enterprise Manager 12c – Proof of ConceptOTN tour 2015 Oracle Enterprise Manager 12c – Proof of Concept
OTN tour 2015 Oracle Enterprise Manager 12c – Proof of Concept
 
OTN tour Oracle db Cloud by Alex Gorbachev
OTN tour Oracle db Cloud by Alex GorbachevOTN tour Oracle db Cloud by Alex Gorbachev
OTN tour Oracle db Cloud by Alex Gorbachev
 
OTN tour 2015 Experience in implementing SSL between oracle db and oracle cli...
OTN tour 2015 Experience in implementing SSL between oracle db and oracle cli...OTN tour 2015 Experience in implementing SSL between oracle db and oracle cli...
OTN tour 2015 Experience in implementing SSL between oracle db and oracle cli...
 
OTN tour 2015 AWR data mining
OTN tour 2015 AWR data miningOTN tour 2015 AWR data mining
OTN tour 2015 AWR data mining
 

Recently uploaded

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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
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
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
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
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
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
 
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
 

Recently uploaded (20)

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)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
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
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
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
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
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
 
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
 

Exploring plsql new features best practices september 2013

  • 1. 9/16/2013 1 Exploring PL/SQL New Features and Best Practices for Better Performance Ami Aharonovich Oracle ACE & OCP Ami@DBAces.co.il Who am I • Oracle ACE • Oracle Certified Professional DBA (OCP) • Founder and CEO, DBAces • Oracle DBA consultant and instructor, specializes in Oracle database core technologies • Specializes in training Oracle courses around the world • Frequent speaker at the Oracle Open World convention • President, Israel Oracle User Group
  • 2. 9/16/2013 2 Agenda • Oracle SQL Developer: Overview • PL/SQL Performance and Tuning: – Parsing Time is Important – Using Bulk Binding – PL/SQL Function Result Cache – Subprogram Inlining – Finer Grained Dependencies • New Features in Oracle Database 12c • PL/SQL Best Practices and Guidelines About My Presentation • My slides and examples are based on: – DBAces course: Exploring Oracle database 11g new features and best practices for database developers and DBAs – My presentations delivered at Oracle Open World – Tom Kyte ilOUG seminar: “Ask Tom Kyte Live in Israel” – My knowledge and experience – Internet
  • 3. 9/16/2013 3 Oracle SQL Developer: Overview • Free and fully supported graphical integrated development environment that simplifies the development and management of Oracle Database • Oracle SQL Developer offers a complete: – End-to-end development of your PL/SQL applications – Worksheet for running queries and scripts – DBA console for managing the database – Reports interface – Data modeling solution – Migration platform for moving 3rd party databases to Oracle Oracle SQL Developer: Overview • Oracle SQL Developer supports Oracle Database 12c: – Oracle Database 12c new features – Manage Multitenant Pluggable Databases – Oracle Database 12c Data Redaction in SQL Developer
  • 4. 9/16/2013 4 More Info on Oracle SQL Developer • Prebuilt virtual machine with Database 11.2 & SQL Developer http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html • Oracle SQL Developer on OTN www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html • Oracle SQL Developer Documentation http://docs.oracle.com/cd/E35137_01/index.htm • Oracle SQL Developer Exchange http://htmldb.oracle.com/pls/otn/f?p=42626:16:695907153071056::NO::: • Oracle SQL Developer Forum http://forums.oracle.com/forums/forum.jspa?forumID=260 • Oracle By Example (OBE), Demos and Tutorials at the Oracle Learning Library www.oracle.com/technetwork/developer-tools/sql-developer/obe-082749.html Parsing Time is Important BEGIN FOR i IN 1..100000 LOOP EXECUTE IMMEDIATE 'INSERT INTO t (x,y) VALUES ('||i||',''A'')'; END LOOP; END; / PL/SQL procedure successfully completed. Elapsed: 00:00:42.91 Parsing_Time_is_Important.sql
  • 5. 9/16/2013 5 Parsing Time is Important BEGIN FOR i IN 1..100000 LOOP EXECUTE IMMEDIATE 'INSERT INTO t (x,y) VALUES (:i,''A'')' USING i; END LOOP; END; / PL/SQL procedure successfully completed. Elapsed: 00:00:08.26 Parsing Time is Important SELECT SUBSTR(sql_text,11,8) "Bind", COUNT(*), ROUND(SUM(sharable_mem)/1024) "Memory KB" FROM v$sqlarea WHERE sql_text LIKE 'INSERT%INTO t (x,y)%' GROUP BY SUBSTR(sql_text,11,8); Bind COUNT(*) Memory KB ------------ ------------ ------------ NO_BIND 9,349 131,580 USE_BIND 1 14
  • 6. 9/16/2013 6 Using Bulk Binding • Save context switch – better performance! • Bind whole array of values simultaneously rather than looping to perform fetch, insert, update and delete on multiple rows • Use BULK COLLECT – for SELECT statements • Use FORALL – for DML statements • Use the RETURNING clause to retrieve information about the rows that are being modified • Works also with dynamic SQL Using Bulk Binding • In case index numbers are not consecutive – Use INDICES OF with or without bounds – Use VALUES OF for associative array indexed by PLS_INTEGER • Use SAVE EXCEPTIONS in your FORALL statements: – Exceptions raised during execution are saved in the %BULK_EXCEPTIONS cursor attribute – Collection of records with two fields: ERROR_INDEX and ERROR_CODE FORALL index IN lower_bound..upper_bound SAVE EXCEPTIONS {insert_stmt | update_stmt | delete_stmt}
  • 7. 9/16/2013 7 Bulk SQL – Examples • SELECT id BULK COLLECT INTO … • FETCH emp_cur BULK COLLECT INTO … • DELETE … RETURNING … BULK COLLECT INTO … • FORALL i IN … UPDATE … • FORALL i IN INDICES OF … INSERT … Bulk.sql It’s All About Caching • Accessing memory is far quicker than accessing hard drives • This fact gives rise to caching: the process of storing data in memory instead of disks • Caching is a common principle of Oracle database architecture, in which users are fed data from the buffer cache instead of the disks on where the database resides • Oracle database 11g enhances performance by using: – SQL Query Result Cache – PL/SQL Function Result Cache – Client Query Result Cache
  • 8. 9/16/2013 8 What is PL/SQL Function Result Cache? • In the past, if you called a PL/SQL function 1,000 times and each function call consumed 1 second, the 1,000 calls would take 1,000 seconds • With this new function results cache feature, depending on the inputs to the function and whether the data underlying the function changes, 1,000 function calls could take about 1 second, total PL/SQL Function Result Cache • Allows storing the results of PL/SQL functions in the SGA • Caching mechanism is both efficient and easy to use • Relieves you of the burden of designing and developing your own caches and cache management policies • Provides the ability to mark a PL/SQL function to indicate that its result should be cached to allow lookup, rather than recalculation, when the same parameter values are called • Saves significant space and time • Done transparently using the input parameters as the lookup key • Instancewide – all distinct sessions invoking the function benefit
  • 9. 9/16/2013 9 Using PL/SQL Function Result Cache • Include the RESULT_CACHE option in the function declaration section of a package or function definition CREATE OR REPLACE FUNCTION ProductName (prod_id NUMBER, lang_id VARCHAR2) RETURN NVARCHAR2 RESULT_CACHE IS result VARCHAR2(50); BEGIN SELECT translated_name INTO result FROM product_descriptions WHERE product_id = prod_id AND language_id = lang_id; RETURN result; END; PLSQL_Function_Result_Cache.sql Subprogram Inlining • Every call to a procedure or function causes a slight, but measurable, performance overhead, which is especially noticeable when the subprogram is called within a loop • Automatic subprogram inlining can reduce the overheads associated with calling subprograms, whilst leaving your original source code in its normal modular state • This is done by replacing the subprogram calls with a copy of the code in the subprogram at compile time
  • 10. 9/16/2013 10 Subprogram Inlining • Controlled by the PLSQL_OPTIMIZE_LEVEL parameter and the INLINE pragma • PLSQL_OPTIMIZE_LEVEL=2 (the default) – INLINE pragma determines whether the following statement or declaration should be inlined or not • PLSQL_OPTIMIZE_LEVEL=3 – Optimizer may inline code automatically – INLINE pragma can turn it off inlining for a statement or increase the likelihood that the optimizer will choose to inline a statement Subprogram_Inlining.sql Finer Grained Dependencies • In previous releases, metadata recorded mutual dependencies between objects with the granularity of the whole object • This means that dependent objects were sometimes invalidated when there was no logical requirement to do so • Oracle Database 11g records dependency metatdata at a finer level of granularity
  • 11. 9/16/2013 11 Finer Grained Dependencies • By reducing the consequential invalidation of dependent objects in response to changes in the objects they depend upon, application availability is increased • The benefit is felt both in the development environment and when a live application is parsed or upgraded • Changes to schema objects does not cause consequential invalidations Finer_Grained_Dependencies.sql New Features in Oracle Database 12c • Invisible Columns • Grant Roles to Code • PL/SQL from SQL • Improved Defaults: – Default to a sequence – Default when null inserted – Identity type • Enhanced Statistics: – Statistics during loads – Session private statistics for GTT’s
  • 12. 9/16/2013 12 12c Invisible Column CREATE TABLE demo (col1 NUMBER, col2 NUMBER, col3 NUMBER INVISIBLE); DESCRIBE demo Name Null? Type --------------- ---------------- --------------- COL1 NUMBER COL2 NUMBER INSERT INTO demo VALUES (1,2); INSERT INTO demo (col1,col2,col3) VALUES (1,2,3); 12c Invisible Column SELECT * FROM demo; COL1 COL2 ---------- ---------- 1 2 1 2 SELECT col1, col2, col3 FROM demo; COL1 COL2 COL3 ---------- ---------- ---------- 1 2 1 2 3
  • 13. 9/16/2013 13 12c Invisible Column ALTER TABLE demo MODIFY (col2 INVISIBLE); ALTER TABLE demo MODIFY (col3 VISIBLE); SELECT column_name,column_id FROM user_tab_columns WHERE table_name=’DEMO’; COLUMN_NAME COLUMN_ID --------------- --------------- COL1 1 COL3 2 COL2 PL/SQL Best Practices and Guidelines • SQL is usually quicker than PL/SQL • Avoid using procedural code when SQL code may be better • Use bulk binds to reduce context switches between the PL/SQL engine and the SQL engine • Do not use UTL_FILE to read text files if you can use External Tables instead • Do not write PL/SQL merges if you can use SQL MERGE • Use DML Error Handling (DBMS_ERRLOG) to trap failures in DML rather than coding PL/SQL
  • 14. 9/16/2013 14 PL/SQL Best Practices and Guidelines • Use PLS_INTEGER when dealing with integer data – Efficient data type for integer variables – Requires less storage than INTEGER or NUMBER – Operations use machine arithmetic which is faster • Beware of implicit data type conversions • Modularize your code: – Limit the number of lines of code between a BEGIN and END – Use packaged programs to keep smaller executable sections – Use local procedures and functions to hide logic – Use a function interface to hide formulas and business rules PL/SQL Best Practices and Guidelines • Write readable code: – Use UPPER and lower case – Use indentation – Avoid using hard-coded literals – Use anchored declarations when possible – Use cursor FOR loop
  • 15. 9/16/2013 15 Some Stuff to Read on the Web • Oracle Database New Features Guide 11g Release 2 (11.2) http://download.oracle.com/docs/cd/E11882_01/server.112/e17128/toc.htm • Oracle Database PL/SQL Language Reference 12c Release 1 (12.1) http://docs.oracle.com/cd/E16655_01/appdev.121/e17622/release_changes.htm • PL/SQL Performance http://www.oracle.com/technetwork/articles/sql/11g-plsql-091775.html • Efficient PL/SQL Coding http://www.oracle.com/technetwork/articles/sql/11g-efficient-coding-093640.html • Oracle 12c Articles http://www.oracle-base.com/articles/12c/articles-12c.php Exploring PL/SQL New Features and Best Practices for Better Performance Ami Aharonovich Oracle ACE & OCP Ami@DBAces.co.il Thank You !