我正在使用sql-maven-plugin在几个数据库上执行一些MySQL脚本。我想在同一个SQL脚本中部署表、数据、触发器、事件和存储过程。
我有一个行分隔符的问题,因为对于INSERT或CREATE我使用了;,但是对于我的触发器,我必须使用DELIMITER //来更改分隔符。
我知道插件允许更改分隔符,但它将适用于所有脚本,我想只为一个独特的脚本的一部分更改分隔符。
这是我的maven配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<username>${db.user}</username>
<password>${db.passwd}</password>
<encoding>UTF-8</encoding>
<orderFile>ascending</orderFile>
<keepFormat>true</keepFormat>
<driverProperties>characterEncoding=utf8,
connectionCollation=utf8_general_ci,
sql_mode=STRICT_TRANS_TABLES</driverProperties>
</configuration>
<executions>
<execution>
<id>execution-mysql</id>
<phase>prepare-package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>jdbc:mysql://${db.url}:${db.port}</url
<delimiterType>normal</delimiterType>
<fileset>
<basedir>${project.build.directory}/sql/</basedir>
<includes>
<include>${file.sql}</include>
</includes>
</fileset>
</configuration>
</execution>
</executions>
</plugin>发布于 2012-10-26 15:44:19
您可以在配置块中将delimeterType设置为"row“。
<configuration>
...
<delimiterType>row</delimiterType>
...
</configuration>delimiterType
row Normal表示任何分隔符的出现都会终止
命令,而with row,仅包含分隔符的行将被识别为命令的结尾。
欲了解更多信息,请访问http://mojo.codehaus.org/sql-maven-plugin/execute-mojo.html#delimiterType
示例: create-proc.sql
CREATE PROCEDURE ADD_BOOK (IN title VARCHAR(100))
BEGIN
-- your sql code
INSERT INTO Book (title) VALUES (title);
END
; -- this means the end of the sql commandhttps://stackoverflow.com/questions/13072354
复制相似问题