web analytics

Initializing Variables in Oracle PL/SQL

Options

codeling 1602 - 6666
@2016-01-08 09:20:01

Whenever you declare a variable, PL/SQL assigns it a default value of NULL. If you want to initialize a variable with a value other than the NULL value, you can do so during the declaration, using either of the following:

  • The DEFAULT keyword
  • The assignment operator

For example:

counter binary_integer := 0;

greetings varchar2(20) DEFAULT 'Have a Good Day';

You can also specify that a variable should not have a NULL value using the NOT NULL constraint. If you use the NOT NULL constraint, you must explicitly assign an initial value for that variable. For example:

name     VARCHAR(25) NOT NULL := 'Smith';

It is a good programming practice to initialize variables properly otherwise, sometimes program would produce unexpected result.

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com