G-9216
🆓Always follow naming conventions for procedures.
Reason
SQL identifiers share the same namespace as PL/SQL identifiers. Follow naming conventions to prevent naming conflicts, improve readability, and clearly indicate the scope without forcing the use of qualified names. A common practice is to use a prefix and/or suffix to distinguish the identifier types.
Recommendations
Name is built from a verb followed by a noun. The name of the procedure should answer the question “What is done?”
Procedures and functions are often named with underscores between words because some editors write all letters in uppercase in the object tree, so it is difficult to read them.
Optionally prefixed by a project abbreviation.
Examples
calculate_salaryset_hiredatecheck_order_state
Example
Non-Compliant Example
create or replace package department_api is -- ... procedure fermer_département(in_id in number); end; /
Issues
| Line | Column | Message |
|---|---|---|
| 3 | 14 |
We do not want accented letters in procedure names.
Compliant Solution - ★★★★★
create or replace package department_api is -- ... procedure fermer_departement(in_id in number); end; /
All accented letters are replaced with plain Latin letters.
Tests
Test SQL query
select owner || '.' || object_type || '.' || object_name
|| case when procedure_name is not null then '.' || procedure_name end as identifier,
case object_type
when 'PACKAGE' then 'Procedure ' || procedure_name || ' in package ' || object_name
when 'TYPE' then 'Procedure ' || procedure_name || ' in type ' || object_name
else initcap(object_type) || ' ' || object_name
end || ' does not match ''' || lower(#ProcedurePattern#) || '''.' as message
from dba_procedures p
where not exists (
select 1
from dba_arguments a
where p.object_id = a.object_id
and p.subprogram_id = a.subprogram_id
and a.position = 0 -- return value of a function
)
and object_type != 'TRIGGER'
and object_name not like 'AQ$%'
and owner in (#SchemaNames#)
and not regexp_like(procedure_name, replace(lower(#ProcedurePattern#), '(?i)', null), 'i')
order by identifierTest results
| Identifier | Message | Migration |
|---|---|---|
| DBL_OWNER.PACKAGE.DEPARTMENT_API.FERMER_DÉPARTEMENT | Procedure FERMER_DÉPARTEMENT in package DEPARTMENT_API does not match '(?i)^[a-z][a-z0-9$#_]*$'. | - |
Parameters
Use parameters to customize the rule to your needs.
| Parameter | Description | Default Value |
|---|---|---|
| ProcedurePattern | Regular expression pattern for procedures in PL/SQL packages and types. | (?i)^[a-z][a-z0-9$#_]*$ |
| SchemaNames | Comma-separated list of database schemas owning the database objects of an application. | dbl_owner |
References
- similar to plsql:PlSql.FunctionAndProcedureNaming
The scope of plsql:PlSql.FunctionAndProcedureNaming is functions and procedures.