Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
50
Добавлен:
16.04.2013
Размер:
5.97 Mб
Скачать

Assigning Values to Variables

BEGIN

...

IF birthdate = outer.birthdate THEN ...

END;

...

END;

/

As the next example shows, the qualifier can also be the name of an enclosing subprogram:

PROCEDURE check_credit (...) IS rating NUMBER;

FUNCTION valid (...) RETURN BOOLEAN IS rating NUMBER;

BEGIN

...

IF check_credit.rating < 3 THEN ...

END; BEGIN

...

END;

/

However, within the same scope, a label and a subprogram cannot have the same name.

Assigning Values to Variables

You can use assignment statements to assign values to variables. For example, the following statement assigns a new value to the variable bonus, overwriting its old value:

bonus := salary * 0.15;

Unless you expressly initialize a variable, its value is undefined (NULL).

Variables and constants are initialized every time a block or subprogram is entered. By default, variables are initialized to NULL:

DECLARE

counter INTEGER; BEGIN

-- COUNTER is initially NULL, so 'COUNTER + 1' is also null. counter := counter + 1;

IF counter IS NULL THEN

dbms_output.put_line('Sure enough, COUNTER is NULL not 1.'); END IF;

END;

/

To avoid unexpected results, never reference a variable before you assign it a value.

The expression following the assignment operator can be arbitrarily complex, but it must yield a datatype that is the same as or convertible to the datatype of the variable.

2-16 PL/SQL User's Guide and Reference

Соседние файлы в папке Oracle 10g