Tom Tresansky
Tom Tresansky

Reputation: 19892

Are these PL/SQL variable initializations equivalent?

So I know I can initialize variables in PL/SQL using either of the following:

For example:

Are these two methods exactly equivalent to the PL/SQL engine, or are there any slight differences?

Upvotes: 2

Views: 149

Answers (2)

Boneist
Boneist

Reputation: 23578

According to the documentation you can use either:

To specify the initial value, use either the assignment operator (:=) or the keyword DEFAULT, followed by an expression

which means they are equivalent.

Upvotes: 0

Luc M
Luc M

Reputation: 17314

Yes they are equivalent.

From Oracle documentation

You can use the keyword DEFAULT instead of the assignment operator to initialize variables. You can also use DEFAULT to initialize subprogram parameters, cursor parameters, and fields in a user-defined record.

Use DEFAULT for variables that have a typical value. Use the assignment operator for variables (such as counters and accumulators) that have no typical value.

Example 2-8 Assigning Default Values to Variables with DEFAULT Keyword

SQL> DECLARE
  2    blood_type CHAR DEFAULT 'O';         -- Same as blood_type CHAR := 'O';
  3  
  4    hours_worked    INTEGER DEFAULT 40;  -- Typical value
  5    employee_count  INTEGER := 0;        -- No typical value
  6  
  7  BEGIN
  8    NULL;
  9  END;
 10  /

PL/SQL procedure successfully completed.

SQL>

Upvotes: 5

Related Questions