SlideShare a Scribd company logo
Carlos Oliveira / July 23, 2014
Agenda
 Code Refactoring – From anonymous block to
procedure
 Introduction
 Quote
 Code Refactoring
 Benefits
 Next Steps
 Training & Reference
 Thank You
Introduction
I am a forward-looking Information Systems Architect with a
solid Oracle DBA background comprising the daily
infrastructure tasks of the DBA, several projects as a Data
Modeler, and performance management projects.
I Started on the mainframe business, and soon had a deep dive
in application development for Oracle databases. After
acquiring an Oracle certification, I worked on performance
enhancement for applications using Oracle databases, and later
worked several years as an infrastructure DBA, later I worked
on data modeling projects and more recently a performance
management project, on both application and database layers.
“The limits of my language
mean the limits of my world.”
Ludwig Wittgenstein
Code Refactoring
Script_text_file_01.sql – file contents below
DECLARE
/********************************************************
Description: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Changed: xx/xx/xxxx
Changed By: xxxxxxx
********************************************************/
v_msg_text VARCHAR2(4000);
v_msg_num NUMBER(10) := 0;
BEGIN
v_msg_text := 'Procedure executed';
v_msg_num := 1;
END;
/
quit
Code Refactoring
CREATE OR REPLACE PROCEDURE DB_USER.PROC_NAME IS
/********************************************************
Description: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Changed: xx/xx/xxxx
Changed By: xxxxxxx
********************************************************/
v_msg_text VARCHAR2(4000);
v_msg_num NUMBER(10) := 0;
BEGIN
v_msg_text := 'Procedure executed';
v_msg_num := 1;
END;
/
Script_text_file_01.sql new
BEGIN
DB_USER.PROC_NAME;
END;
/
quit
Since the code is now stored in
the database, the
Script_text_file_01.sql only
contains the call to the
procedure.
Benefits
Compilation
• Most of the code is already compiled – only caller script remains
Memory
• Reduced memory usage
• Faster load
Tracking
• Code can be tracked inside DB
• Explicit dependency – change in related objects are flagged
Reuse
• Code is ready to be reused
• Change in central stored object is immediate for all calling scripts
Security
• Code can be included in database backup/restore
• Access to code restricted by database privileges
Next Steps
Modularization
• Identification of common code for grouping, organization or creation of internal
or even external procedures
• Encapsulation of complex code in procedures of functions
Error Control
• Inclusion of an Exception section for each code block
• Use of user-created exceptions
• Creation of common exception procedures
Best Practices
• Variable initialization
• Eliminate hard-code
And much more …
Training
• Performance Tuning Guide and Reference
 http://docs.oracle.com/cd/B10500_01/server.920/a96533/toc.htm
• SQL Reference
 http://docs.oracle.com/cd/B10500_01/server.920/a96540/toc.htm
• PL/SQL User's Guide and Reference
 http://docs.oracle.com/cd/B10500_01/appdev.920/a96624/toc.htm
Resources at Oracle website
Thank you
Carlos Oliveira / July 23, 2014

More Related Content

PPT
Websphere - Introduction to jdbc
PPT
Websphere - Introduction to SSL part 1
PPT
Websphere - Intoduction to Unicode websphere
PPT
Websphere - Introduction to logs and configuration
PPTX
Hierarchical architecture
PPTX
5 Ways to Make Your Postgres GDPR-Ready
 
PPS
Bfc Presentation
PPTX
Thick client pentesting_the-hackers_meetup_version1.0pptx
Websphere - Introduction to jdbc
Websphere - Introduction to SSL part 1
Websphere - Intoduction to Unicode websphere
Websphere - Introduction to logs and configuration
Hierarchical architecture
5 Ways to Make Your Postgres GDPR-Ready
 
Bfc Presentation
Thick client pentesting_the-hackers_meetup_version1.0pptx

What's hot (19)

PPTX
Cqrs.frameworks
PPTX
Clean Architecture
PPTX
CLR Stored Procedures
PPTX
Bottlenecks in Java Applications
PDF
Rundeck Office Hours: Best Practices for Access Control Policies
PPT
Architecture Proposition For Multimedia repository
PPTX
How to design a distributed system
PDF
Comparison between Dynamo and riak
PPTX
SnapComms Technical Overview
PPT
005.itsecurity bcp v1
PPTX
Redis. Seattle Data Science and Data Engineering Meetup
PDF
Version Control in TFS 2013: GIT - 2013 Application Lifecycle Management Event
PPTX
Highlights of Skills and Experience
PPTX
Highlights
PDF
"Building intuitive command-line interfaces in .NET", Alex Thissen
PPTX
ODP
Dos and Don'ts of Android Application Security (Security Professional Perspec...
PPTX
Ride the database in JUnit tests with Database Rider
PDF
VxClass for Incident Response
Cqrs.frameworks
Clean Architecture
CLR Stored Procedures
Bottlenecks in Java Applications
Rundeck Office Hours: Best Practices for Access Control Policies
Architecture Proposition For Multimedia repository
How to design a distributed system
Comparison between Dynamo and riak
SnapComms Technical Overview
005.itsecurity bcp v1
Redis. Seattle Data Science and Data Engineering Meetup
Version Control in TFS 2013: GIT - 2013 Application Lifecycle Management Event
Highlights of Skills and Experience
Highlights
"Building intuitive command-line interfaces in .NET", Alex Thissen
Dos and Don'ts of Android Application Security (Security Professional Perspec...
Ride the database in JUnit tests with Database Rider
VxClass for Incident Response
Ad

Viewers also liked (7)

PPTX
Three phase waveforms rcs
PPSX
Machado de assis obras
PPT
Machado De Assis
PPT
Eça de Queirós
PPTX
Eça de Queirós
PPT
Machado de Assis
PPT
Os Lusíadas - a estrutura
Three phase waveforms rcs
Machado de assis obras
Machado De Assis
Eça de Queirós
Eça de Queirós
Machado de Assis
Os Lusíadas - a estrutura
Ad

Similar to Oracle plsql code refactoring - from anonymous block to stored procedure (20)

PPT
PLSQLIV.ppt
PPS
Procedures/functions of rdbms
PPTX
Relational Database Management System
PPT
Sql optimize
PPT
You shouldneverdo
PPT
Writing Maintainable Code
PPT
Writing maintainable Oracle PL/SQL code
PPT
oracle pl-sql lec 7 oracle pl-sql lec 7 plsql Lec07.ppt
PPTX
Plsql guide 2
PPTX
Stored procedures
PPT
Oracle PL/SQL exception handling
PPTX
Take Full Advantage of the Oracle PL/SQL Compiler
PPT
05 Creating Stored Procedures
PPTX
Oracle: Procedures
PPTX
Oracle: Procedures
PPT
Module04
TXT
Sql procedures
PDF
Oracle PL SQL Programming Animal Guide 5th Edition Steven Feuerstein
PPT
Intro to tsql
PPT
Intro to tsql unit 14
PLSQLIV.ppt
Procedures/functions of rdbms
Relational Database Management System
Sql optimize
You shouldneverdo
Writing Maintainable Code
Writing maintainable Oracle PL/SQL code
oracle pl-sql lec 7 oracle pl-sql lec 7 plsql Lec07.ppt
Plsql guide 2
Stored procedures
Oracle PL/SQL exception handling
Take Full Advantage of the Oracle PL/SQL Compiler
05 Creating Stored Procedures
Oracle: Procedures
Oracle: Procedures
Module04
Sql procedures
Oracle PL SQL Programming Animal Guide 5th Edition Steven Feuerstein
Intro to tsql
Intro to tsql unit 14

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
cuic standard and advanced reporting.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Encapsulation theory and applications.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
Review of recent advances in non-invasive hemoglobin estimation
The Rise and Fall of 3GPP – Time for a Sabbatical?
cuic standard and advanced reporting.pdf
Network Security Unit 5.pdf for BCA BBA.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Encapsulation theory and applications.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
MIND Revenue Release Quarter 2 2025 Press Release
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf

Oracle plsql code refactoring - from anonymous block to stored procedure

  • 1. Carlos Oliveira / July 23, 2014
  • 2. Agenda  Code Refactoring – From anonymous block to procedure  Introduction  Quote  Code Refactoring  Benefits  Next Steps  Training & Reference  Thank You
  • 3. Introduction I am a forward-looking Information Systems Architect with a solid Oracle DBA background comprising the daily infrastructure tasks of the DBA, several projects as a Data Modeler, and performance management projects. I Started on the mainframe business, and soon had a deep dive in application development for Oracle databases. After acquiring an Oracle certification, I worked on performance enhancement for applications using Oracle databases, and later worked several years as an infrastructure DBA, later I worked on data modeling projects and more recently a performance management project, on both application and database layers.
  • 4. “The limits of my language mean the limits of my world.” Ludwig Wittgenstein
  • 5. Code Refactoring Script_text_file_01.sql – file contents below DECLARE /******************************************************** Description: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Changed: xx/xx/xxxx Changed By: xxxxxxx ********************************************************/ v_msg_text VARCHAR2(4000); v_msg_num NUMBER(10) := 0; BEGIN v_msg_text := 'Procedure executed'; v_msg_num := 1; END; / quit
  • 6. Code Refactoring CREATE OR REPLACE PROCEDURE DB_USER.PROC_NAME IS /******************************************************** Description: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Changed: xx/xx/xxxx Changed By: xxxxxxx ********************************************************/ v_msg_text VARCHAR2(4000); v_msg_num NUMBER(10) := 0; BEGIN v_msg_text := 'Procedure executed'; v_msg_num := 1; END; / Script_text_file_01.sql new BEGIN DB_USER.PROC_NAME; END; / quit Since the code is now stored in the database, the Script_text_file_01.sql only contains the call to the procedure.
  • 7. Benefits Compilation • Most of the code is already compiled – only caller script remains Memory • Reduced memory usage • Faster load Tracking • Code can be tracked inside DB • Explicit dependency – change in related objects are flagged Reuse • Code is ready to be reused • Change in central stored object is immediate for all calling scripts Security • Code can be included in database backup/restore • Access to code restricted by database privileges
  • 8. Next Steps Modularization • Identification of common code for grouping, organization or creation of internal or even external procedures • Encapsulation of complex code in procedures of functions Error Control • Inclusion of an Exception section for each code block • Use of user-created exceptions • Creation of common exception procedures Best Practices • Variable initialization • Eliminate hard-code And much more …
  • 9. Training • Performance Tuning Guide and Reference  http://docs.oracle.com/cd/B10500_01/server.920/a96533/toc.htm • SQL Reference  http://docs.oracle.com/cd/B10500_01/server.920/a96540/toc.htm • PL/SQL User's Guide and Reference  http://docs.oracle.com/cd/B10500_01/appdev.920/a96624/toc.htm Resources at Oracle website
  • 10. Thank you Carlos Oliveira / July 23, 2014