SlideShare a Scribd company logo
1 of 29
PL/SQL & SQL
CODING GUIDELINES – PART 2
Larry Nung
AGENDA
Variables & Types
Reference
Q & A
2
VARIABLES & TYPES
General
8. TRY TO USE ANCHORED DECLARATIONS
FOR VARIABLES, CONSTANTS AND TYPES.
BAD
DECLARE
v_empName VARCHAR2(10);
BEGIN
…
END;
GOOD
DECLARE
v_empName emp.ename%TYPE;
BEGIN
…
END;
9.TRY TO HAVE A SINGLE LOCATION TO DEFINE
YOUR TYPES.
10. TRY TO USE SUBTYPES FOR CONSTRUCTS
USED OFTEN IN YOUR APPLICATION.
BAD
DECLARE
v_str VARCHAR2(4000);
BEGIN
…
END;
GOOD
CREATE OR REPLACE PACKAGE PKG_SUBTYPE
AS
SUBTYPE STRING_MAX IS VARCHAR2(4000);
END PKG_SUBTYPE;
DECLARE
v_str PKG_SUBTYPE.STRING_MAX;
BEGIN
...
END;
11. NEVER INITIALIZE VARIABLES WITH NULL.
BAD
DECLARE
v_str VARCHAR2(30) := null;
BEGIN
...
END;
GOOD
DECLARE
v_str VARCHAR2(30);
BEGIN
...
END;
12. AVOID COMPARISONS WITH NULL VALUE,
CONSIDER USING IS [NOT] NULL.
BAD
DECLARE
v_str VARCHAR2(30);
BEGIN
if v_str = null then
…
end if;
END;
GOOD
DECLARE
v_str VARCHAR2(30);
BEGIN
if v_str is null then
…
end if;
END;
13. AVOID INITIALIZING VARIABLES USING
FUNCTIONS IN THE DECLARATION SECTION.
BAD
DECLARE
l_company_name VARCHAR2(30) :=
util_pck.get_company_name(in_id => 47);
BEGIN
…
END;
GOOD
DECLARE
v_str VARCHAR2(30);
BEGIN
<<init>>
BEGIN
v_str := util_pck.get_company_name(inId =>
47);
EXCEPTION
WHEN VALUE_ERROR THEN
...
END init;
END;
14. NEVER OVERLOAD DATA STRUCTURE
USAGES.
BAD
<<main>>
DECLARE
v_str VARCHAR2(30);
BEGIN
<<sub>>
DECLARE
v_str VARCHAR2(4000) ;
BEGIN
…
END sub;
END main;
15. NEVER USE QUOTED IDENTIFIERS.
BAD
<<main>>
DECLARE
"v_str" VARCHAR2(30) ;
BEGIN
…
END main;
16. AVOID USING OVERLY SHORT NAMES FOR
DECLARED OR IMPLICITLY DECLARED IDENTIFIERS.
17. AVOID THE USE OF ROWID OR UROWID
REFERENCE
26
REFERENCE
 Trivadis PL/SQL & SQL Coding Guidelines Version
2.0
 http://www.trivadis.com/sites/default/files/downloads/PL
SQL_and_SQL_Coding_Guidelines_2_0_HiRes.pdf
27
Q&A
28
QUESTION & ANSWER
29

More Related Content

Viewers also liked

Exposicion de la kinesiologia de la cara
Exposicion de la kinesiologia de la caraExposicion de la kinesiologia de la cara
Exposicion de la kinesiologia de la carastefany ojeda
 
Ender’s Game Presentation
Ender’s Game PresentationEnder’s Game Presentation
Ender’s Game PresentationTimotheezy
 
PL/SQL Coding Guidelines - Part 1
PL/SQL Coding Guidelines - Part 1PL/SQL Coding Guidelines - Part 1
PL/SQL Coding Guidelines - Part 1Larry Nung
 
Topshelf - An easy service hosting framework for building Windows services us...
Topshelf - An easy service hosting framework for building Windows services us...Topshelf - An easy service hosting framework for building Windows services us...
Topshelf - An easy service hosting framework for building Windows services us...Larry Nung
 
PL/SQL & SQL CODING GUIDELINES – Part 4
PL/SQL & SQL CODING GUIDELINES – Part 4PL/SQL & SQL CODING GUIDELINES – Part 4
PL/SQL & SQL CODING GUIDELINES – Part 4Larry Nung
 
PL/SQL & SQL CODING GUIDELINES – Part 5
PL/SQL & SQL CODING GUIDELINES – Part 5PL/SQL & SQL CODING GUIDELINES – Part 5
PL/SQL & SQL CODING GUIDELINES – Part 5Larry Nung
 
Oracle Database 12c Attack Vectors
Oracle Database 12c Attack VectorsOracle Database 12c Attack Vectors
Oracle Database 12c Attack VectorsMartin Toshev
 
Electrical Engineering Interview Questions
Electrical Engineering Interview QuestionsElectrical Engineering Interview Questions
Electrical Engineering Interview Questionsashiesh0007
 

Viewers also liked (8)

Exposicion de la kinesiologia de la cara
Exposicion de la kinesiologia de la caraExposicion de la kinesiologia de la cara
Exposicion de la kinesiologia de la cara
 
Ender’s Game Presentation
Ender’s Game PresentationEnder’s Game Presentation
Ender’s Game Presentation
 
PL/SQL Coding Guidelines - Part 1
PL/SQL Coding Guidelines - Part 1PL/SQL Coding Guidelines - Part 1
PL/SQL Coding Guidelines - Part 1
 
Topshelf - An easy service hosting framework for building Windows services us...
Topshelf - An easy service hosting framework for building Windows services us...Topshelf - An easy service hosting framework for building Windows services us...
Topshelf - An easy service hosting framework for building Windows services us...
 
PL/SQL & SQL CODING GUIDELINES – Part 4
PL/SQL & SQL CODING GUIDELINES – Part 4PL/SQL & SQL CODING GUIDELINES – Part 4
PL/SQL & SQL CODING GUIDELINES – Part 4
 
PL/SQL & SQL CODING GUIDELINES – Part 5
PL/SQL & SQL CODING GUIDELINES – Part 5PL/SQL & SQL CODING GUIDELINES – Part 5
PL/SQL & SQL CODING GUIDELINES – Part 5
 
Oracle Database 12c Attack Vectors
Oracle Database 12c Attack VectorsOracle Database 12c Attack Vectors
Oracle Database 12c Attack Vectors
 
Electrical Engineering Interview Questions
Electrical Engineering Interview QuestionsElectrical Engineering Interview Questions
Electrical Engineering Interview Questions
 

More from Larry Nung

Ansible - simple it automation
Ansible - simple it automationAnsible - simple it automation
Ansible - simple it automationLarry Nung
 
sonarwhal - a linting tool for the web
sonarwhal - a linting tool for the websonarwhal - a linting tool for the web
sonarwhal - a linting tool for the webLarry Nung
 
LiteDB - A .NET NoSQL Document Store in a single data file
LiteDB - A .NET NoSQL Document Store in a single data fileLiteDB - A .NET NoSQL Document Store in a single data file
LiteDB - A .NET NoSQL Document Store in a single data fileLarry Nung
 
PL/SQL & SQL CODING GUIDELINES – Part 8
PL/SQL & SQL CODING GUIDELINES – Part 8PL/SQL & SQL CODING GUIDELINES – Part 8
PL/SQL & SQL CODING GUIDELINES – Part 8Larry Nung
 
MessagePack - An efficient binary serialization format
MessagePack - An efficient binary serialization formatMessagePack - An efficient binary serialization format
MessagePack - An efficient binary serialization formatLarry Nung
 
PL/SQL & SQL CODING GUIDELINES – Part 7
PL/SQL & SQL CODING GUIDELINES – Part 7PL/SQL & SQL CODING GUIDELINES – Part 7
PL/SQL & SQL CODING GUIDELINES – Part 7Larry Nung
 
BenchmarkDotNet - Powerful .NET library for benchmarking
BenchmarkDotNet  - Powerful .NET library for benchmarkingBenchmarkDotNet  - Powerful .NET library for benchmarking
BenchmarkDotNet - Powerful .NET library for benchmarkingLarry Nung
 
PLSQL Coding Guidelines - Part 6
PLSQL Coding Guidelines - Part 6PLSQL Coding Guidelines - Part 6
PLSQL Coding Guidelines - Part 6Larry Nung
 
SonarQube - The leading platform for Continuous Code Quality
SonarQube - The leading platform for Continuous Code QualitySonarQube - The leading platform for Continuous Code Quality
SonarQube - The leading platform for Continuous Code QualityLarry Nung
 
Visual studio 2017
Visual studio 2017Visual studio 2017
Visual studio 2017Larry Nung
 
Web deploy command line
Web deploy command lineWeb deploy command line
Web deploy command lineLarry Nung
 
Common.logging
Common.loggingCommon.logging
Common.loggingLarry Nung
 
protobuf-net - Protocol Buffers library for idiomatic .NET
protobuf-net - Protocol Buffers library for idiomatic .NETprotobuf-net - Protocol Buffers library for idiomatic .NET
protobuf-net - Protocol Buffers library for idiomatic .NETLarry Nung
 
Regular expression
Regular expressionRegular expression
Regular expressionLarry Nung
 
Fx.configuration
Fx.configurationFx.configuration
Fx.configurationLarry Nung
 
StackExchange.redis
StackExchange.redisStackExchange.redis
StackExchange.redisLarry Nung
 
GRUNT - The JavaScript Task Runner
GRUNT - The JavaScript Task RunnerGRUNT - The JavaScript Task Runner
GRUNT - The JavaScript Task RunnerLarry Nung
 

More from Larry Nung (20)

Ansible - simple it automation
Ansible - simple it automationAnsible - simple it automation
Ansible - simple it automation
 
sonarwhal - a linting tool for the web
sonarwhal - a linting tool for the websonarwhal - a linting tool for the web
sonarwhal - a linting tool for the web
 
LiteDB - A .NET NoSQL Document Store in a single data file
LiteDB - A .NET NoSQL Document Store in a single data fileLiteDB - A .NET NoSQL Document Store in a single data file
LiteDB - A .NET NoSQL Document Store in a single data file
 
PL/SQL & SQL CODING GUIDELINES – Part 8
PL/SQL & SQL CODING GUIDELINES – Part 8PL/SQL & SQL CODING GUIDELINES – Part 8
PL/SQL & SQL CODING GUIDELINES – Part 8
 
MessagePack - An efficient binary serialization format
MessagePack - An efficient binary serialization formatMessagePack - An efficient binary serialization format
MessagePack - An efficient binary serialization format
 
PL/SQL & SQL CODING GUIDELINES – Part 7
PL/SQL & SQL CODING GUIDELINES – Part 7PL/SQL & SQL CODING GUIDELINES – Part 7
PL/SQL & SQL CODING GUIDELINES – Part 7
 
BenchmarkDotNet - Powerful .NET library for benchmarking
BenchmarkDotNet  - Powerful .NET library for benchmarkingBenchmarkDotNet  - Powerful .NET library for benchmarking
BenchmarkDotNet - Powerful .NET library for benchmarking
 
PLSQL Coding Guidelines - Part 6
PLSQL Coding Guidelines - Part 6PLSQL Coding Guidelines - Part 6
PLSQL Coding Guidelines - Part 6
 
SonarQube - The leading platform for Continuous Code Quality
SonarQube - The leading platform for Continuous Code QualitySonarQube - The leading platform for Continuous Code Quality
SonarQube - The leading platform for Continuous Code Quality
 
Visual studio 2017
Visual studio 2017Visual studio 2017
Visual studio 2017
 
Web deploy command line
Web deploy command lineWeb deploy command line
Web deploy command line
 
Web deploy
Web deployWeb deploy
Web deploy
 
SikuliX
SikuliXSikuliX
SikuliX
 
Common.logging
Common.loggingCommon.logging
Common.logging
 
protobuf-net - Protocol Buffers library for idiomatic .NET
protobuf-net - Protocol Buffers library for idiomatic .NETprotobuf-net - Protocol Buffers library for idiomatic .NET
protobuf-net - Protocol Buffers library for idiomatic .NET
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Fx.configuration
Fx.configurationFx.configuration
Fx.configuration
 
StackExchange.redis
StackExchange.redisStackExchange.redis
StackExchange.redis
 
Disruptor
DisruptorDisruptor
Disruptor
 
GRUNT - The JavaScript Task Runner
GRUNT - The JavaScript Task RunnerGRUNT - The JavaScript Task Runner
GRUNT - The JavaScript Task Runner
 

PL/SQL Coding Guidelines - Part 2