我正在尝试使用LiquiBase执行以下插入操作:
INSERT INTO table (id, value) VALUES (0, 'nullás')
//
这显然是一个随机值,目标是在VARCHAR2列中插入非英语的带重音符号的字符。目标是Oracle 12c。如果我通过PC上的SQL Developer手动运行插入,则可以正常运行。但是,当我从同一台PC通过LiquiBase运行它时,会产生以下内容:
null�s
执行日志:
INSERT INTO table (id, value) VALUES (0, 'null?s')
插入本身包含在单独的SQL文件中。像这样将其添加到变更集文件中:
<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="1" author="aaa" >
<comment>insert.sql</comment>
<sqlFile dbms="oracle" encoding="UTF-8" path="insert.sql" relativeToChangelogFile="true" endDelimiter="//" />
</changeSet>
以前,编码设置为“ utf8”,我认为这是一个错字,但是将其更改为“ UTF-8”后仍然存在问题。相关的POM设置:
<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa</groupId>
<artifactId>aaa</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<version.ojdbc>12.2.0.1.0</version.ojdbc>
<version.org.liquibase.liquibase-maven-plugin>3.6.2</version.org.liquibase.liquibase-maven-plugin>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<liquibase.url>jdbc:oracle:thin:@1.2.3.4:1521/aaa</liquibase.url>
<!-- liquibase.url>offline:oracle?outputLiquibaseSql=true</liquibase.url -->
<liquibase.execute.goal>update</liquibase.execute.goal>
<liquibase.driver>oracle.jdbc.OracleDriver</liquibase.driver>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${version.org.liquibase.liquibase-maven-plugin}</version>
<configuration>
<propertyFile>liquibase.properties</propertyFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<outputFileEncoding>UTF-8</outputFileEncoding>
<systemProperties>
<property>
<name>file.encoding</name>
<value>UTF-8</value>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>${version.ojdbc}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>liquibase_01</id>
<properties>
<liquibase.changeLogFile>liquibase_01.xml</liquibase.changeLogFile>
<liquibase.username>${admin.shema.name}</liquibase.username>
<liquibase.password>${admin.shema.password}</liquibase.password>
<liquibase.migrationSqlOutputFile>target/liquibase/migr_01.sql</liquibase.migrationSqlOutputFile>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>${liquibase.execute.goal}</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
我已经尝试了以下方法:
<?xml...
行,但未添加我不确定我还能尝试什么。这可能是Oracle方面的设置吗?字符集似乎是“ AL32UTF8”:
select value from nls_database_parameters where parameter='NLS_CHARACTERSET';
AL32UTF8
在Oracle服务器操作系统上未设置 NLS_LANG
变量。
Oracle本身已安装在具有英语本地化版本的Windows Server 2008 R2上。然后再说一次,具有相同运行时环境的相同LiquiBase版本与SQL Server 2017(以英语本地化安装在Windows Server 2016上)一起使用时效果很好,重音符号与上述相同的INSERT语句插入。在项目的此部分,没有启用以上所有详细的UTF-8设置。
答案 0 :(得分:1)
解决方案是上面SteveDonie的评论:文件编码必须为UTF-8。