简体   繁体   English

ORA-06550 第 2 行,第 44 列:PLS-00103: 遇到符号“文件结束”

[英]ORA-06550 line 2, column 44:PLS-00103: Encountered the symbol "end-of-file"

I am trying to execute a SQL script from Java using some rxjava2 methods.我正在尝试使用一些 rxjava2 方法从 Java 执行 SQL 脚本。 I have a resource file called init_db.sql .我有一个名为init_db.sql的资源文件。

Its content:其内容:

BEGIN
EXECUTE IMMEDIATE 'DROP TABLE animals';
EXCEPTION
   WHEN OTHERS THEN
      IF SQLCODE != -942 THEN
         RAISE;
      END IF;
END;
/
CREATE TABLE animals (
  id        NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
  name      VARCHAR2(40) NOT NULL,
  amount    INT,
  CONSTRAINT animals_pk PRIMARY KEY (id));

INSERT INTO animals (name, amount) values ('Cats', 10);
INSERT INTO animals (name, amount) values ('Dogs', 10);
INSERT INTO animals (name, amount) values ('Rats', 10);

The method where the Java code is executed is the next:执行 Java 代码的方法是下一个:

public  Completable initOracleDatabase(Vertx vertx, JDBCClient jdbc) {
    System.out.println("Init Oracle Database **** executing..sql script...");
    Completable completable =
      jdbc.rxGetConnection().flatMapCompletable(sqlConnection -> vertx.fileSystem().rxReadFile("init_db.sql")
        .flatMapObservable(buffer -> Observable.fromArray(buffer.toString().replaceAll(";.*$", "").split(";")))
        .flatMapCompletable(sqlConnection::rxExecute)
        .doAfterTerminate(sqlConnection::close));
   
    return completable;

And this is the error that I got from the logs:这是我从日志中得到的错误:

java.sql.SQLException: ORA-06550: line 2, column 44:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
 * & = - + ; < / > at in is mod remainder not rem return
returning <an exponent (**)> <> or != or ~= >= <= <> and or
 like like2 like4 likec between into using || multiset bulk
 member submultiset

and the error trace log:和错误跟踪日志:

at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:509)
  at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:461)
  at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1104)
  at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:553)
  at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:269)
  at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:655)
  at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:229)
  at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:41)
  at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:928)
  at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1205)
  at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1823)
  at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1778)
  at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:303)

Basically I would like to know if can I use in one only statement this SQL scriptor not?基本上我想知道我是否可以在一个唯一的声明中使用这个 SQL 脚本程序? or if I am missing anything or some error code translate between SQL script and Java?或者如果我遗漏了任何东西或在 SQL 脚本和 Java 之间转换的错误代码?

You are mixing PL/SQL and SQL code in the same script.您在同一脚本中混合使用 PL/SQL 和 SQL 代码。

  • SQL statements can be terminated by ; SQL 语句可以由;终止. .
  • PL/SQL blocks are terminated by / on a newline and will contain nested PL/SQL (or SQL) statements that are each terminated by ; PL/SQL 块以换行符/终止,并将包含嵌套的 PL/SQL(或 SQL)语句,每个语句以;终止。 . .

So you cannot naively split your code on ;所以你不能天真地拆分你的代码; and expect it to work as you will incorrectly split the PL/SQL blocks.并期望它能正常工作,因为您会错误地拆分 PL/SQL 块。

In addition to using ;除了使用; as an SQL statement terminator, you can also use / on a newline;作为 SQL 语句终止符,您还可以在换行符上使用/ so you could rewrite your script as:所以你可以将你的脚本重写为:

BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE animals';
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -942 THEN
      RAISE;
    END IF;
END;
/

CREATE TABLE animals (
  id        NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
  name      VARCHAR2(40) NOT NULL,
  amount    INT,
  CONSTRAINT animals_pk PRIMARY KEY (id)
)
/

INSERT INTO animals (name, amount) values ('Cats', 10)
/
INSERT INTO animals (name, amount) values ('Dogs', 10)
/
INSERT INTO animals (name, amount) values ('Rats', 10)
/

And split the script on \n/\n .并在\n/\n上拆分脚本。

Or, you can just ignore catching the ORA-00942 exception and just use SQL and continue using the ;或者,您可以忽略捕获 ORA-00942 异常并仅使用 SQL 并继续使用; statement terminator:语句终止符:

DROP TABLE animals;

CREATE TABLE animals (
  id        NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
  name      VARCHAR2(40) NOT NULL,
  amount    INT,
  CONSTRAINT animals_pk PRIMARY KEY (id)
);

INSERT INTO animals (name, amount) values ('Cats', 10);
INSERT INTO animals (name, amount) values ('Dogs', 10);
INSERT INTO animals (name, amount) values ('Rats', 10);

Or, you can create a more complicated solution that actually parses PL/SQL and SQL statements and can split the script into individual statement based on the syntax tree.或者,您可以创建一个更复杂的解决方案,它实际解析 PL/SQL 和 SQL 语句,并可以根据语法树将脚本拆分为单独的语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PLS-00103:在FlyWay中遇到符号“文件结尾” - PLS-00103: Encountered the symbol “end-of-file” in FlyWay PLS-00103:遇到符号“文件结束” - PLS-00103: Encountered the symbol “end-of-file” ORA-06550:第1行,第7列:PLS-00306:错误的数量或调用中的参数类型 - ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call PLS-00103:预期以下情况之一时遇到符号“ TEST_PKG”: - PLS-00103: Encountered the symbol “TEST_PKG” when expecting one of the following: ; 错误:PLS-00103:在预期以下情况之一时遇到符号“ AS”:返回 - Error: PLS-00103: Encountered the symbol “AS” when expecting one of the following:return 引起:java.sql.SQLException:ORA-06550:第 1 行,第 7 列:PLS-00306:ZDBC11CAA5BDA99F77E6FB4DABD_SPE_FA 7 调用中的 ZDBC11CAA5BDA99F77E6FB4DABD8SPE_7 的错误编号或类型 - Caused by: java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'PR_SP_FAHMI' java.sql.SQLException:ORA-06550:第1行第13列:授予用户对EXECUTE包的权限后 - java.sql.SQLException: ORA-06550: line 1, column 13: After granting user permission to EXECUTE package java.sql.SQLException:ORA-06550 - java.sql.SQLException: ORA-06550 Java语言-java.sql.SQLException:ORA-06550 - Java Language - java.sql.SQLException: ORA-06550 调用SQL过程:SQL异常 - 代码:6550 ORA-06550 - Calling SQL Procedure: SQL exception - code: 6550 ORA-06550
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM