Naming Your Program Data

To work with a variable or a constant, you must first declare it, and when you declare it, you give it a name. Here are the rules that PL/SQL insists you follow when naming your data structures (these are the same rules applied to names of database objects, such as tables and columns):

  • Names can be up to 30 characters in length.

  • Names must start with a letter.

  • After the first letter, names can then be composed of any of the following: letters, numerals, $, #, and _.

  • All names are case-insensitive (unless those names are placed within double quotes).

Given these rules, the following names are valid:

l_total_count
first_12_years
total_#_of_trees
salary_in_$

These next two names are not only valid but considered identical by PL/SQL because it is not a case-sensitive language:

ExpertsExchange
ExpertSexChange

The next three names are invalid, for the reasons indicated:

1st_account  --Starts with a number instead of a letter
favorite_ice_cream_flavors_that_dont_contain_nuts  --Too long
email_address@business_loc  --Contains invalid character (@)

There are some exceptions to these rules (why am I not surprised?). If you embed a name within double quotes when you declare it, you can bypass all the above rules except the maximum length of 30 characters. For example, all of the following declarations are valid:

DECLARE
   "truly_lower_case" INTEGER;
   "     " DATE; -- Yes, a name consisting of five spaces!
   "123_go!" VARCHAR2(10);
BEGIN
   "123_go!"  := 'Steven';
END;

Note that when you reference ...

Get Oracle PL/SQL Programming, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.