oracle数据库中的系统自带表情,Oracle无法存储表情符号

I have a problem saving emoji to the Oracle database.

This is a simple Java program which takes user input from the webpage and save it to the database.

This is what it looks like before I save to DB.

4386a24e87367767ec534848485ad6ac.png

And this is what it looks like when it retrieves it from database.

ae72ab22722d9339e646f87660d0c1f0.png

The database column defined as CLOB so my expectation that it persist text with emoji just fine.

I also tried to save and retrieve emoji with sqlplus and have no luck as well:

SQL> update emoji_table set emoji_column = 'Test 😂' where emoji_table_id = 123;

1 row updated.

SQL> select emoji_column from emoji_table where emoji_table_id = 123;

EMOJI_TABLE

--------------------------------------------------------------------------------

Test ????

I assume there might be an issue with Oracle character encoding or something like that.

Could you please advice what might be wrong and where to look for potential fix.

Thank you

UPDATE #1

As suggested by Wernfried Domscheit I checked my NLS_CHARACTERSET and it appears to be WE8MSWIN1252.

As I understand this is the root cause of the issue, it is not UTF-8, hence doesn't have reserved list of emoji.

The output of the

select DUMP(emoji_column, 1016) from emoji_table where emoji_table_id = 123

is following

ERROR at line 1:

ORA-00932: inconsistent datatypes: expected - got CLOB

Could you please advice how to workaround?

UPDATE #2

Here is the output of DUMP sql query:

select DUMP(TO_CHAR(emoji_column), 1016) from emoji_table where emoji_table_id = 123

DUMP(TO_CHAR(TEMPLATE),1016)

--------------------------------------------------------------------------------

Typ=1 Len=6 CharacterSet=WE8MSWIN1252: 42,6f,64,79,20,bf

As I can see CharacterSet is WE8MSWIN1252 which matches the NLS_CHARACTERSET of the Oracle instance.

Is there a workaround to save emoji with WE8MSWIN1252?

Probably Base64 encoding could be a workaround but I would like to know if there is a better solution.

解决方案

In order to see emoji in sql*plus do following:

Choose a font which is capable to display emojis (see FACE WITH TEARS OF JOY (U+1F602) Font Support)

Set character set of your console to UTF-8

Set NLS_LANG accordingly

Run slqplus

On Windows it would be:

chcp 65001

set NLS_LANG=.AL32UTF8

sqlplus ...

Regarding settings in java, please have a look at Database JDBC Developer's Guide - Globalization Support. Since you get data as ???? I assume the value is properly inserted into database as 😂 is U+1F602, which is in UTF-8 F0 9F 98 82, i.e. 4 Bytes.

Update:

You cannot store Unicode emojis when your character set is WE8MSWIN1252 which is only single-byte. Either use NCLOB data type or migrate your database to UTF-8, see Character Set Migration

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值