gpt4 book ai didi

sql - Maven : PL/SQL script with sql-maven-plugin throws error PLS-00103

转载 作者:行者123 更新时间:2023-12-03 19:51:03 25 4
gpt4 key购买 nike

我正在尝试使用 sql-maven-plugin 在 Oracle 11 数据库上执行 PL/SQL 脚本。虽然脚本是有效的 PL/SQL(据我所知),但执行给我一个 PLS-00103 错误:

SQL 脚本:(drop_all_tables.sql)

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

还有我的插件配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>

<dependencies>
<dependency>
<groupId>oracle</groupId>
<artifactId>jdbc</artifactId>
<version>11.2.0.2.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>create-schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<url>${jdbc.url}</url>
<username>${jdbc.username}</username>
<password>${jdbc.password}</password>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>src/main/resources/sql/drop_all_tables.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>

这是 Maven 执行的输出:
[ERROR] Failed to execute:  BEGIN
EXECUTE IMMEDIATE 'DROP TABLE MY_TABLE';
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] ORA-06550: line 2, column 43:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

( begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge

最佳答案

我猜该插件是通过分号拆分 sql 脚本并尝试独立执行每个部分。第一个声明是

BEGIN
EXECUTE IMMEDIATE 'DROP TABLE MY_TABLE';

就 oracle 而言,这是不完整的。该插件确实有两个配置参数来改变这种行为, delimiterdelimiterType .通过更改如下配置并分离您的 BEGIN/ 阻止在单独的一行中,您应该能够执行此脚本。
<configuration>
<delimiter>/</delimiter>
<delimiterType>row</delimiterType>
</configuration>

关于sql - Maven : PL/SQL script with sql-maven-plugin throws error PLS-00103,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7580165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com