Lesson 7 | Naming conventions |
Objective | Create a naming convention in Oracle. |
Creating Oracle Naming Conventions using PL/SQL Variables
Naming conventions, which are often overlooked because they do not seem to be important, do not become an issue until they are not implemented. A lack of naming conventions causes developers to spend their valuable time trying to debug and maintain the application code.
Oracle Naming Conventions
Below are the common naming conventions:
- Use a naming convention to avoid ambiguity in the code.
- Avoid using the same name for the database column and variables in your code.
- Adopt a naming convention for various objects such as the following example:
Using
v_
as a prefix representing a variable and g_
as a prefix representing a global variable avoids naming conflicts with database objects.
vg_petname VARCHAR2(30);
Oracle PL/SQL Programming
Naming Conventions
The same naming conventions apply to PL/SQL constants, variables, cursors, cursor variables, exceptions, procedures, functions, and packages. Names can be simple, qualified, remote, or both qualified and remote. For example:
- Simple.procedure name only:
raise_salary(employee_id, amount);
- Qualified.procedure name preceded by the name of the package that contains it (this is called dot notation because a dot separates the package name from the
procedure name): emp_actions.raise_salary(employee_id, amount);
- Remote.procedure name followed by the remote access indicator (@) and a link to the database on which the procedure is stored:
raise_salary@newyork(employee_id, amount);
- Qualified and remote:
emp_actions.raise_salary@newyork(employee_id, amount)
It is important to create and follow
naming conventions.
Standards provide a
common language for everyone in the team to understand and maintain the code easily.
The next lesson concludes this module.
Naming Conventions - Exercise