Oracle PL/SQL/PL SQL/Constant Number — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 09:59, 26 мая 2010
Содержание
Change constant number
SQL>
SQL> -- change constant number
SQL>
SQL> declare
2 myconstant constant number := 50;
3 begin
4 myconstant := 51;
5 end;
6 /
myconstant := 51;
*
ERROR at line 4:
ORA-06550: line 4, column 5:
PLS-00363: expression "MYCONSTANT" cannot be used as an assignment target
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
SQL>
Declare initialized constant number
SQL>
SQL>
SQL>
SQL> -- declare initialized constant number
SQL>
SQL> declare
2 l_number_constant constant number := 50;
3 begin
4 null;
5 dbms_output.put_line(l_number_constant);
6 end;
7 /
50
PL/SQL procedure successfully completed.
SQL>
SQL>
declare number constant uninitialized
SQL>
SQL> declare
2 myNumber_constant constant number;
3 begin
4 null;
5 end;
6 /
myNumber_constant constant number;
*
ERROR at line 2:
ORA-06550: line 2, column 5:
PLS-00322: declaration of a constant "MYNUMBER_CONSTANT" must contain an initialization assignment
ORA-06550: line 2, column 23:
PL/SQL: Item ignored
SQL>
This script demonstrates constants
SQL>
SQL>
SQL> SET SERVEROUTPUT ON
SQL>
SQL>
SQL> DECLARE
2 fnameValue CONSTANT VARCHAR2(50) := "Ron";
3 BEGIN
4 fnameValue := "AAA";
5 EXCEPTION
6 WHEN OTHERS
7 THEN
8 DBMS_OUTPUT.PUT_LINE(SQLERRM);
9 END;
10 /
fnameValue := "AAA";
*
ERROR at line 4:
ORA-06550: line 4, column 5:
PLS-00363: expression "FNAMEVALUE" cannot be used as an assignment target
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
SQL>
you must initialize the constant at the time of declaration
SQL>
SQL>
SQL> declare
2 myNumber_constant constant number := 50;
3 begin
4 null;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL>
SQL>