Consider script:
============
set bail on;
set autoterm on;
set list on;
set echo on;
shell if exist r:\temp\tmp4test.fdb del r:\temp\tmp4test.fdb;
create database 'localhost:r:\temp\tmp4test.fdb' user sysdba password 'masterkey';
create package pg_test as
begin
constant k_publ_1 smallint = 1;
function fn_test returns smallint;
constant k_publ_2 smallint = 2;
end
;
recreate package body pg_test as
begin
constant k_priv_1 smallint = -1
; --------------------------------------- [ 1 ]
function fn_test returns smallint as
begin
return 1;
end
-- ; ------------------------------------ [ 2 ]
-- constant k_priv_2 smallint = -2; ----- [ 3 ]
end
;
============
IMO, some inconsistency presents currently in the syntax and/or requirement of declaration of package body items.
Comment out "[ 1 ]" or Uncomment lines "[ 2 ]" or "[ 3 ]" -- and you will get "token unknown".
In order words:
1) semicolon is mandatory after CONSTANT declaration (see "[ 1 ]");
2) semicolon must NOT presend after `end` that terminates function/procedure (see "[ 2 ]"). But such rule actual only for the BODY of package. For the package HEAD, on the contrary, semicolon is required after each declared constant / unit;
3) all constants in the package BODY must be declared before first unit (proc/func) -- see "[ 3 ]".
Why such rules were introduced ?
Especially, it is unclear reason of prohibition for ";" to be inserted between items in the package body.
/* requirement to put all constants at the top looks logical and generally accepted; but then it makes sense to reflect this in the doc ? */
Checked on 6.0.0.1978-12b2158.