Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

why a semi-colon is not enough when creating packages and package bodies?

705503Jun 6 2009 — edited Jun 6 2009
Hi,

I'm struggling with a quite simple problem - when creating a package header and body in the same script, it does not work as expected. See for example this very simple package:

CREATE OR REPLACE PACKAGE mypackage AS
PROCEDURE test_proc(id INTEGER);
END mypackage;

CREATE OR REPLACE PACKAGE BODY mypackage AS
PROCEDURE test_proc(id INTEGER) IS
BEGIN
NULL;
END test_proc;
END mypackage;

When executed from JDeveloper (or sqlplus), the package is created but with a "PLS-00103: Encountered the symbol CREATE" error. It seems Oracle does not recognize the script contains header and body, and uses the whole script as a header (which is obviously wrong).

If modified so that there are "/" everything works fine:

CREATE OR REPLACE PACKAGE mypackage AS
PROCEDURE test_proc(id INTEGER);
END mypackage;
/

CREATE OR REPLACE PACKAGE BODY mypackage AS
PROCEDURE test_proc(id INTEGER) IS
BEGIN
NULL;
END test_proc;
END mypackage;
/

Why is this necessary? Why Oracle does not recognize that "END mypackage;" actually ends package header definition, and combines it with the body definition into an invalid block? I've thought semicolon is a valid separator, so why is the "/" necessary?

It does not work even when I try to run the statements separately (from the same worksheet in Jdeveloper) - first select the header block, hit F9 (execute statement), then repeated the same for body. In this case both header and body are created, but are invalid because the last semicolon is removed from them (so it's not possible to compile them).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2009
Added on Jun 6 2009
8 comments
896 views