oracle 创建oracle包遇到PLS-00103:遇到符号“CREATE”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9231788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
create oracle package encountered PLS-00103: Encountered the symbol "CREATE"
提问by Gary
I am writing an oracle package using Oracle sql developer, I got this compile error:
我正在使用 Oracle sql developer 编写一个 oracle 包,我收到了这个编译错误:
Error(7,1): PLS-00103: Encountered the symbol "CREATE" .
Error(7,1): PLS-00103: 遇到符号 "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:
如果我/
在第 6 行添加一个,则错误变为:
Error(6,1): PLS-00103: Encountered the symbol "/"
错误(6,1):PLS-00103:遇到符号“/”
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.
我犯了同样的错误。
回答by Andrew Wolfe
When you have BEGIN, END, etc you are in PL/SQL, not SQL.
当您有 BEGIN、END 等时,您使用的是 PL/SQL,而不是 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.
PL/SQL 块需要在行的最开始用单个(“正向”)斜杠终止。这告诉 Oracle 您已经完成了 PL/SQL 块,因此它会编译该文本块。
SQL query - terminated by semicolon:
SQL 查询 - 以分号终止:
update orders set status = 'COMPLETE' where order_id = 55255;
PL/SQL block - commands separatedby semicolon, block is terminated by forward-slash:
PL / SQL块-命令分离由分号,块由斜杠终止:
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;
/
回答by M. P. R.
This worked for me using Oracle SQL Developer:
这对我使用 Oracle SQL Developer 有用:
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 TESTE;
INSERT INTO TESTE
SELECT 1,1,1 FROM DUAL;
COMMIT;
RETURN TRUE;
EXCEPTION
WHEN OTHERS THEN
RETURN FALSE;
END;
FUNCTION afterPopulate
RETURN BOOLEAN AS
BEGIN
UPDATE TESTE SET TESTE='OK' WHERE TESTE='';
COMMIT;
RETURN TRUE;
EXCEPTION
WHEN OTHERS THEN RETURN FALSE;
END;
END TestPackage;
/
I couldn't get it to run until I actually created the tables and columns it'd use.
在我实际创建它要使用的表和列之前,我无法让它运行。
回答by Dropout
After a couple hours of frustration I managed to make this stuff work. I had the exactproblem as you did.
经过几个小时的挫折后,我设法使这些东西起作用。我和你一样遇到了确切的问题。
The solution for me was to run it as a script - not in the package code. Forward slashes work correctly in the SQL worksheet. I'm attaching the difference, I hope it will help you!
我的解决方案是将它作为脚本运行 - 而不是在包代码中。正斜杠在 SQL 工作表中正常工作。我附上差异,希望对您有所帮助!
回答by Error
I had the same problem. I create package using main menu od the left and put package declaration and body inside same .sql file. Problem get solved when I copy all code and paste it into new worksheet and put "/" after end package_name (both after package declaration and body) and then execute worksheet as script.
我有同样的问题。我使用左侧的主菜单创建包,并将包声明和正文放在同一个 .sql 文件中。当我复制所有代码并将其粘贴到新工作表中并在 end package_name 之后(在包声明和正文之后)后放置“/”,然后将工作表作为脚本执行时,问题就解决了。
回答by Vishy
execute package and package body separately with F5
用F5分别执行包和包体
回答by Jan Němec
I had this problem (Error(6,1): PLS-00103: Encountered the symbol "/" ) when I coppied all the db package code (both procedures headers and implementations) in sqldeveloper into user/packages/MY_PACKAGE_NAME/MY_PACKAGE_BODY instead of copying headers (without '/' at the end) into user/packages/MY_PACKAGE_NAME and implementation (without headers at the top and without '/' at the end) into user/packages/MY_PACKAGE_NAME/MY_PACKAGE_BODY.
当我将 sqldeveloper 中的所有数据库包代码(程序头和实现)复制到 user/packages/MY_PACKAGE_NAME/MY_PACKAGE_BODY 而不是将标题(末尾没有“/”)复制到 user/packages/MY_PACKAGE_NAME 和实现(顶部没有标题,末尾没有“/”)复制到 user/packages/MY_PACKAGE_NAME/MY_PACKAGE_BODY。