小编典典

Maven:具有sql-maven-plugin的PL / SQL脚本引发错误PLS-00103

sql

我正在尝试使用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

阅读 222

收藏
2021-04-22

共1个答案

小编典典

我猜这个插件是用分号分割sql脚本,并试图独立执行每个部分。第一个语句是

BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE MY_TABLE';

就oracle而言,这是不完整的。该插件确实具有两个配置参数来更改此行为,delimiterdelimiterType。通过更改如下所示的配置,并单独用一行将您的BEGIN块分隔/开,您应该能够执行此脚本。

<configuration>
    <delimiter>/</delimiter>
    <delimiterType>row</delimiterType>
</configuration>
2021-04-22