在Trafodion數據庫,當咱們設定一個字段類型爲字符類型的時候(如CHAR或VARCHAR),字符編碼會以數據庫默認的字符編碼爲準。數據庫
好比下面例子,建立有一個字符類型字段的表,經過SHOWDDL命令能夠看到這個字段的編碼方式爲ISO88591。編碼
SQL>drop table seabase.test_chinese; create table seabase.test_chinese (rol_a varchar(10)); showddl seabase.test_chinese; --- SQL operation complete. SQL> --- SQL operation complete. SQL> CREATE TABLE TRAFODION.SEABASE.TEST_CHINESE ( ROL_A VARCHAR(10) CHARACTER SET ISO88591 COLLATE DEFAULT DEFAULT NULL SERIALIZED ) ; --- SQL operation complete.
此時若是想插入中文字符會報錯,解決方法就是修改字符的編碼類型爲UTF8。code
SQL>insert into seabase.test_chinese values('中國'); *** ERROR[8690] An invalid character value encountered in TRANSLATE function. [2016-10-25 06:22:47] SQL>alter table seabase.test_chinese alter column rol_a varchar(10) character set utf8; --- SQL operation complete.
如今咱們再經過SHOWDDL查看字段屬性已修改成UTF8類型,這時插入中文字符成功。io
SQL>showddl seabase.test_chinese; CREATE TABLE TRAFODION.SEABASE.TEST_CHINESE ( ROL_A VARCHAR(10 CHARS) CHARACTER SET UTF8 COLLATE DEFAULT DEFAULT NULL SERIALIZED /*altered_col*/ ) ; --- SQL operation complete. SQL>insert into seabase.test_chinese values('中國'); --- 1 row(s) inserted. SQL>select * from seabase.test_chinese; ROL_A ---------------------------------------- 中國 --- 1 row(s) selected.
固然咱們也能夠在建表的時候直接定義字段類型爲UTF8,方法以下:字符編碼
SQL>create table test_chinese(rol_a varchar(10) character set utf8); --- SQL operation complete. SQL>showddl test_chinese; CREATE TABLE TRAFODION.SEABASE.TEST_CHINESE ( ROL_A VARCHAR(10 CHARS) CHARACTER SET UTF8 COLLATE DEFAULT DEFAULT NULL NOT SERIALIZED ) ATTRIBUTES ALIGNED FORMAT ; --- SQL operation complete.