SQL PLS-00103:在预期以下情况之一时遇到符号“文件结束”:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6967543/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 11:36:09  来源:igfitidea点击:

PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ;

sqloracleplsql

提问by Bhabani Sankar Mishra

I am running the following script -

我正在运行以下脚本 -

BEGIN
    select department_name 
    from egpl_department 
    where department_id in (select department_id 
                            from egpl_casemgmt_activity);
END ;

And got the Error -

并得到了错误 -

PLS-00103: Encountered the symbol "end-of-file" when 
expecting one of the following: 
;

回答by diederikh

In a PL/SQL block select statement should have an intoclause:

在 PL/SQL 块中,select 语句应该有一个into子句:

DECLARE
 v_department egpl_department.department_name%type;
BEGIN 
  select department_name 
  into   v_department
  from   egpl_department 
  where  department_id in (select department_id from egpl_casemgmt_activity); 

  -- Do something useful with v_department
END; 

回答by Codo

In PL/SQL you cannot just select some data. Where is the result supposed to go?

在 PL/SQL 中,您不能只选择一些数据。结果应该去哪里?

Your options are:

您的选择是:

  • Remove BEGINand ENDand run the SELECT with SQL*plus or some other tool that can run a SQL statement and present the result somewhere.

  • Use SELECT department_name INTO dep_nameto put the result into a PL/SQL variable (only works if your SELECT returns a single row)

  • Use SELECT department_name BULK COLLECT INTO dep_name_tableto put the result into a PL/SQL table (works for several rows)

  • 使用 SQL*plus 或其他一些可以运行 SQL 语句并在某处显示结果的工具删除BEGINEND运行 SELECT。

  • 使用SELECT department_name INTO dep_name把结果为PL / SQL变量(只适用,如果你的SELECT返回单行)

  • 使用SELECT department_name BULK COLLECT INTO dep_name_table把结果为PL / SQL表(几行作品)

Or maybe you can describe what you're trying to achieve and in what environment you want to run the SQL or PL/SQL code.

或者,您可以描述您要实现的目标以及要在什么环境中运行 SQL 或 PL/SQL 代码。

回答by APC

PLS-00103always means the compiler has hurled because we have made a syntax error. It would be really neat if the message text said: You have made a syntax error, please check your codebut alas it doesn't.

PLS-00103总是意味着编译器已经抛出,因为我们犯了一个语法错误。如果消息文本说:You have made a syntax error, please check your code但可惜它没有。

Oracle's documentation is comprehensive and online. You can find the section on integrating SQL queries into PL/SQL here. I urge you to read it, to forestall your next question. Because once you have fixed the simple syntax bloomer you're going to hit TOO_MANY_ROWS (assuming you have more than one department).

Oracle 的文档是全面的在线文档。您可以在此处找到有关将 SQL 查询集成到 PL/SQL 中的部分。我敦促你阅读它,以防止你的下一个问题。因为一旦你修复了简单的语法大器,你就会遇到 TOO_MANY_ROWS(假设你有多个部门)。

回答by steve godfrey

To avoid the too_many_rows problem, you could use a cursor, something like this (I haven't tested this, but along these lines )

为了避免 too_many_rows 问题,你可以使用一个游标,像这样(我没有测试过这个,但沿着这些线)

DECLARE 

 v_department egpl_department.department_name%type;

 cursor c_dept IS
  select department_name 
  into   v_department
  from   egpl_department 
  where  department_id in (select department_id from egpl_casemgmt_activity)
  order by department_name; 

BEGIN 

  OPEN c_dept;
  FETCH c_dept INTO v_department;
  CLOSE c_dept;

  -- do something with v_department

END;

This will put the first value it finds in the table into v_department. Use the ORDER BY clause to make sure the row returned would be the one you required, assuming there was the possibility of 2 different values.

这会将它在表中找到的第一个值放入 v_department。使用 ORDER BY 子句确保返回的行是您需要的行,假设可能有 2 个不同的值。

回答by Joseph Ptheitroadier

Most people would not consider the call to be the issue,

大多数人不会认为电话是问题,

but here's an amusing bug in Oracle Sql Developer that may emulate the issue..

但这是 Oracle Sql Developer 中的一个有趣的错误,它可以模拟这个问题。

exec dbowner.sp1 ( p1, p2, p3); -- notes about the fields

Error report - ORA-06550: line 1, column 362: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

错误报告 - ORA-06550:第 1 行,第 362 列:PLS-00103:在预期以下情况之一时遇到符号“文件结束”:

begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:

begin case 声明 end 异常退出 if loop mod null pragma raise return select update while with << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe 06550. 00000 - "line %s, column %s: \n%s" *原因:通常是 PL/SQL 编译错误。*行动:

exec dbowner.sp1 ( p1, p2, p3); 
-- notes about the fields

PL/SQL procedure successfully completed.

PL/SQL 过程成功完成。