Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Appendix

A - PL/SQL & SQL Coding Guidelines as PDF

These guidelines are primarily produced inHTML usingMaterial for MkDocs.

However, we provide these guidelines also asPDF produced bywkhtmltopdf.

Trivadis PL/SQL & SQl Coding Guidelines in PDF format

The formatting is not perfect, but it should be adequate for those who want to work with offline documents.

B - Mapping new guidelines to prior versions

Old
Id
New
Id
TextSeverityChange-
ability
Effi-
ciency
Maintain-
ability
Port-
ability
Reli-
ability
Reus-
ability
Secu-
rity
Test-
ability
11010Try to label your sub blocks.Minor
21020Always have a matching loop or block label.Minor
31030Avoid defining variables that are not used.Minor
41040Avoid dead code.Minor
51050Avoid using literals in your code.Minor
61060Avoid storing ROWIDs or UROWIDs in database tables.Major
71070Avoid nesting comment blocks.Minor
n/a1080Avoid using the same expression on both sides of a relational comparison operator or a logical operator.Minor
82110Try to use anchored declarations for variables, constants and types.Major
92120Try to have a single location to define your types.Minor
102130Try to use subtypes for constructs used often in your code.Minor
n/a2135Avoid assigning values to local variables that are not used by a subsequent statement.Major
112140Never initialize variables with NULL.Minor
n/a2145Never self-assign a variable.Minor
122150Avoid comparisons with NULL value, consider using IS [NOT] NULL.Blocker
132160Avoid initializing variables using functions in the declaration section.Critical
142170Never overload variables.Major
152180Never use quoted identifiers.Major
162185Avoid using overly short names for explicitly or implicitly declared identifiers.Minor
172190Avoid using ROWID or UROWID.Major
182210Avoid declaring NUMBER variables, constants or subtypes with no precision.Minor
192220Try to use PLS_INTEGER instead of NUMBER for arithmetic operations with integer values.Minor
n/a2230Try to use SIMPLE_INTEGER datatype when appropriate.Minor
202310Avoid using CHAR data type.Major
212320Never use VARCHAR data type.Major
222330Never use zero-length strings to substitute NULL.Major
232340Always define your VARCHAR2 variables using CHAR SEMANTIC (if not defined anchored).Minor
242410Try to use boolean data type for values with dual meaning.Minor
252510Avoid using the LONG and LONG RAW data types.Major
n/a2610Never use self-defined weak ref cursor types.Minor
263110Always specify the target columns when coding an insert statement.Major
n/a3115Avoid self-assigning a column.Minor
273120Always use table aliases when your SQL statement involves more than one source.Major
283130Try to use ANSI SQL-92 join syntax.Minor
293140Try to use anchored records as targets for your cursors.Major
n/a3145Avoid using SELECT * directly from a table or view.Major
n/a3150Try to use identity columns for surrogate keys.Minor
n/a3160Avoid visible virtual columns.Major
n/a3170Always use DEFAULT ON NULL declarations to assign default values to table columns if you refuse to store NULL values.Major
n/a3180Always specify column names instead of positional references in ORDER BY clauses.Major
n/a3185Never use ROWNUM at the same query level as ORDER BY.Major
n/a3190Avoid using NATURAL JOIN.Major
n/a3195Always use wildcards in a LIKE clause.Minor
303210Always use BULK OPERATIONS (BULK COLLECT, FORALL) whenever you have to execute a DML statement for more than 4 times.Major
n/a3220Always process saved exceptions from a FORALL statement.Major
n/a3310Never commit within a cursor loop.Critical
n/a3320Try to move transactions within a non-cursor loop into procedures.Major
314110Always use %NOTFOUND instead of NOT %FOUND to check whether a cursor returned data.Minor
324120Avoid using %NOTFOUND directly after the FETCH when working with BULK OPERATIONS and LIMIT clause.Critical
334130Always close locally opened cursors.Major
344140Avoid executing any statements between a SQL operation and the usage of an implicit cursor attribute.Major
354210Try to use CASE rather than an IF statement with multiple ELSIF paths.Major
364220Try to use CASE rather than DECODE.Minor
374230Always use a COALESCE instead of a NVL command, if parameter 2 of the NVL function is a function call or a SELECT statement.Critical
384240Always use a CASE instead of a NVL2 command if parameter 2 or 3 of NVL2 is either a function call or a SELECT statement.Critical
n/a4250Avoid using identical conditions in different branches of the same IF or CASE statement.Major
n/a4260Avoid inverting boolean conditions with NOT.Minor
n/a4270Avoid comparing boolean values to boolean literals.Minor
394310Never use GOTO statements in your code.Major
404320Always label your loops.Minor
n/a4325Never reuse labels in inner scopes.Major
414330Always use a CURSOR FOR loop to process the complete cursor results unless you are using bulk operations.Minor
424340Always use a NUMERIC FOR loop to process a dense array.Minor
434350Always use 1 as lower and COUNT() as upper bound when looping through a dense array.Major
444360Always use a WHILE loop to process a loose array.Minor
n/a4365Never use unconditional CONTINUE or EXIT in a loop.Major
454370Avoid using EXIT to stop loop processing unless you are in a basic loop.Major
464375Always use EXIT WHEN instead of an IF statement to exit from a loop.Minor
474380Try to label your EXIT WHEN statements.Minor
484385Never use a cursor for loop to check whether a cursor returns data.Major
494390Avoid use of unreferenced FOR loop indexes.Major
504395Avoid hard-coded upper or lower bound values with FOR loops.Minor
n/a5010Try to use a error/logging framework for your application.Critical
515020Never handle unnamed exceptions using the error number.Critical
525030Never assign predefined exception names to user defined exceptions.Blocker
535040Avoid use of WHEN OTHERS clause in an exception section without any other specific handlers.Major
54n/aAvoid use of EXCEPTION_INIT pragma for a 20nnn error.Major
555050Avoid use of the RAISE_APPLICATION_ERROR built-in procedure with a hard-coded 20nnn error number or hard-coded message.Major
565060Avoid unhandled exceptions.Major
575070Avoid using Oracle predefined exceptions.Critical
n/a5080Always use FORMAT_ERROR_BACKTRACE when using FORMAT_ERROR_STACK or SQLERRM.Minor
586010Always use a character variable to execute dynamic SQL.Major
596020Try to use output bind arguments in the RETURNING INTO clause of dynamic DML statements rather than the USING clause.Minor
607110Try to use named notation when calling program units.Major
617120Always add the name of the program unit to its end keyword.Minor
n/a7125Always use CREATE OR REPLACE instead of CREATE alone.Minor
627130Always use parameters or pull in definitions rather than referencing external variables in a local program unit.Major
637140Always ensure that locally defined procedures or functions are referenced.Major
647150Try to remove unused parameters.Minor
687160Always explicitly state parameter mode.Major
n/a7170Avoid using an IN OUT parameter as IN or OUT only.Major
657210Try to keep your packages small. Include only few procedures and functions that are used in the same context.Minor
667220Always use forward declaration for private functions and procedures.Minor
677230Avoid declaring global variables public.Major
n/a7250Never use RETURN in package initialization block.Minor
697310Avoid standalone procedures – put your procedures in packages.Minor
707320Avoid using RETURN statements in a PROCEDURE.Major
n/a7330Always assign values to OUT parameters.Major
717410Avoid standalone functions – put your functions in packages.Minor
737420Always make the RETURN statement the last statement of your function.Major
727430Try to use no more than one RETURN statement within a function.Major
747440Never use OUT parameters to return values from a function.Major
757450Never return a NULL value from a BOOLEAN function.Major
n/a7460Try to define your packaged/standalone function deterministic if appropriate.Major
767510Always prefix Oracle supplied packages with owner schema name.Major
777710Avoid cascading triggers.Major
n/a7720Never use multiple UPDATE OF in trigger event clause.Blocker
n/a7730Avoid multiple DML events per trigger.Minor
n/a7740Never handle multiple DML events per trigger if primary key is assigned in trigger.Major
n/a7810Never use SQL inside PL/SQL to read sequence numbers (or SYSDATE).Major
n/a7910Never use DML within a SQL macro.Critical
788110Never use SELECT COUNT(*) if you are only interested in the existence of a row.Major
n/a8120Never check existence of a row to decide whether to create it or not.Major
798210Always use synonyms when accessing objects of another application schema.Major
n/a8310Always validate input parameter size by assigning the parameter to a size limited variable in the declaration section of program unit.Minor
n/a8410Always use application locks to ensure a program unit is only running once at a given time.Minor
n/a8510Always use dbms_application_info to track program process transiently.Minor
n/a9010Always use a format model in string to date/time conversion functions.Major
n/a9020Try to use a format model and NLS_NUMERIC_CHARACTERS in string to number conversion functions.Major
n/a9030Try to define a default value on conversion errors.Minor
n/a9040Try using FX in string to date/time conversion format model to avoid fuzzy conversion.Minor

[8]ページ先頭

©2009-2025 Movatter.jp