LiquiBase 向 Oracle 插入重音字符
LiquiBase insert accented characters to Oracle
我正在尝试使用 LiquiBase 执行以下插入:
INSERT INTO table (id, value) VALUES (0, 'nullás')
//
这显然是一个随机值,目的是将非英语、带重音符号的字符插入到 VARCHAR2 列中。目标是 Oracle 12c。如果我 运行 通过 SQL Developer 从我的 PC 手动插入,它工作正常。但是当我从同一台 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 文件添加了
<?xml...
行,但未添加
- 上面的UTF-8配置基本上都是我新加的
- 在 Maven 命令行中添加了“-Dfile.encoding=UTF-8”
- 将 MAVEN_OPTS 变量设置为“-Dfile.encoding=UTF-8”
我不确定我还能尝试什么。这可能是 Oracle 方面的设置吗?字符集好像是"AL32UTF8":
select value from nls_database_parameters where parameter='NLS_CHARACTERSET';
AL32UTF8
NLS_LANG
Oracle 服务器上未设置变量 OS。
Oracle 本身安装在具有英文本地化的 Windows Server 2008 R2 上。再一次,具有相同 运行 时间环境的相同 LiquiBase 版本与 SQL Server 2017(安装在具有英语本地化的 Windows Server 2016 上)一起工作得很好,重音字符插入与上面相同的 INSERT 语句。并且none上面详细的UTF-8设置在这部分项目中启用。
解决方案是上面 SteveDonie 的评论:文件编码需要是 UTF-8。
我正在尝试使用 LiquiBase 执行以下插入:
INSERT INTO table (id, value) VALUES (0, 'nullás')
//
这显然是一个随机值,目的是将非英语、带重音符号的字符插入到 VARCHAR2 列中。目标是 Oracle 12c。如果我 运行 通过 SQL Developer 从我的 PC 手动插入,它工作正常。但是当我从同一台 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 文件添加了
<?xml...
行,但未添加 - 上面的UTF-8配置基本上都是我新加的
- 在 Maven 命令行中添加了“-Dfile.encoding=UTF-8”
- 将 MAVEN_OPTS 变量设置为“-Dfile.encoding=UTF-8”
我不确定我还能尝试什么。这可能是 Oracle 方面的设置吗?字符集好像是"AL32UTF8":
select value from nls_database_parameters where parameter='NLS_CHARACTERSET';
AL32UTF8
NLS_LANG
Oracle 服务器上未设置变量 OS。
Oracle 本身安装在具有英文本地化的 Windows Server 2008 R2 上。再一次,具有相同 运行 时间环境的相同 LiquiBase 版本与 SQL Server 2017(安装在具有英语本地化的 Windows Server 2016 上)一起工作得很好,重音字符插入与上面相同的 INSERT 语句。并且none上面详细的UTF-8设置在这部分项目中启用。
解决方案是上面 SteveDonie 的评论:文件编码需要是 UTF-8。