An error SQL0010N is reported when the DB2 SQL script is executed

Recently, the following error was reported when executing the DB2 database SQL script:
DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0010N The string constant beginning with "'场景号')" does not have an ending string delimiter. SQLSTATE=42603。
 
The scenario is as follows:
The production environment needs to import a batch of data scripts, including Chinese
Then organize it into a data script and execute the command to import the data: db2 -tvf import.sql
However, after the command is executed, an error is reported
 
Error message:
DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0010N The string constant beginning with "'场景号')" does not have an ending string delimiter. SQLSTATE=42603
 
problem analysis:
The script content executes fine in the DB2 client tool, so it can be determined that the problem is with Chinese characters.
There are 3 levels of character sets in DB2 database: operating system level LANG, instance level (client level) db2codepage, database level Database code page/set.
  1. 操作系统级是用户应用程序使用的代码页,可以使用环境变量LANG=C等来设置。用set命令、或者echo $LANG查看其值。
  2. 实例级DB2应用程序进行客户端到数据库服务端代码页转换时使用的,比如使用SQL脚本时,db2读取脚本时就是按照实例级的字符集db2codepage来识别该脚本的。可用db2set -all来查看其值。可用db2set db2codepage= 128来设置其值。
  3. 数据库级的字符集是在创建数据库时指定的,是后续不可修改的。设置语句类似:db2 "CREATE DATABASE dbname USING CODESET UTF-8 TERRITORY CN"。可以在连接数据后,使用: db2 get db cfg for dbname 命令,来查看Database code page/set的值。
 本问题中数据库级的字符集是1386,即GBK字符集;终端实例级的字符集也是1386字符集。但是,SQL脚本时UTF-8格式的,db2按照1386字符集去读取UTF-8格式的脚本就会出现不可识别的乱码,最终报错SQL0010N.
 
解决方法:
临时修改实例级字符集为UTF-8格式,执行完脚本后再恢复为GBK格式。
1. 连接到数据库
$db2 connect to [dbname] user [username] using [password]
2. 设置临时字符集
$db2set db2codepage=1208
$db2 terminate
3. 再次连接到数据库
$db2 connect to [dbname] user [username] using [password]
4. 导入数据
$db2 -tvf import.sql // 执行SQL脚本
5. 恢复数据库字符集设置
$db2set db2codepage=1386
$db2 terminate
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326027734&siteId=291194637