Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

plsql - create oracle package encountered PLS-00103: Encountered the symbol "CREATE"

I am writing an oracle package using Oracle sql developer, I got this compile error:

Error(7,1): PLS-00103: Encountered the symbol "CREATE" .

create or replace
PACKAGE TestPackage AS 
 FUNCTION beforePopulate RETURN BOOLEAN;
 FUNCTION afterPopulate RETURN BOOLEAN;
END TestPackage;

CREATE OR REPLACE PACKAGE BODY TestPackage AS
   FUNCTION beforePopulate RETURN BOOLEAN AS
   BEGIN
      DELETE FROM TEST_1;
      INSERT INTO TEST_1
      SELECT * FROM TEST WHERE VALUE=300;
      COMMIT;
      RETURN TRUE;
     EXCEPTION
       WHEN OTHERS THEN
        RETURN FALSE;
   END;
   FUNCTION afterPopulate RETURN BOOLEAN AS
     BEGIN
         UPDATE TEST SET RESULT="completed" WHERE VALUE=300;
            COMMIT;
         RETURN TRUE;
         EXCEPTION
           WHEN OTHERS RETURN FALSE;
        END;
  END;
END TestPackage;

If I add a / at line 6, the error became:

Error(6,1): PLS-00103: Encountered the symbol "/"

I tired an empty implementation like this:

create or replace 
package package1 as 
END PACKAGE1;

CREATE OR REPLACE 
package body package1 as 
end package1;

I got the same err.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you have BEGIN, END, etc you are in PL/SQL, not SQL.

A PL/SQL block needs to be terminated with a single ("forward") slash at the very beginning of the line. This tells Oracle that you are done with your PL/SQL block, so it compiles that block of text.

SQL query - terminated by semicolon:

update orders set status = 'COMPLETE' where order_id = 55255;

PL/SQL block - commands separated by semicolon, block is terminated by forward-slash:

create or replace procedure mark_order_complete (completed_order_id in number)
is
begin
     update orders set status = 'COMPLETE' where order_id = :completed_order_id;
end mark_order_complete;
/

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...