将 unicode 文本插入 Oracle 数据库表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32452131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:00:11  来源:igfitidea点击:

Insert unicode text into Oracle database table

databaseoracleunicodeoracle-sqldeveloperoracle-apex

提问by Quan Nguyen

I create a table in OracleDB 11cthrough SQL Developer 4.1.1

我通过SQL Developer 4.1.1OracleDB 11c 中创建了一个表

CREATE TABLE FAC.FAC_CODE_CPQLDN(    
    ID NUMBER(10), 
    CODE NVARCHAR2(100) NOT NULL, 
    NAME NLOB, 
    NOTE NLOB, 
    PARENT_ID NUMBER(10),
    CONSTRAINT FAC_CODE_CPQLDN_PK PRIMARY KEY (ID)
);

After that, I insert data into this table

之后,我将数据插入到这个表中

REM INSERTING into FAC_CODE_CPQLDN
SET DEFINE OFF;
insert into FAC_CODE_CPQLDN(ID, CODE, NAME, NOTE, PARENT_ID) values (1, 'C1.1', 'Chi phí c?ng ty', '', 0);

But I get the error

但我得到了错误

SQL Error: ORA-01465: invalid hex number

Please let me know how to fix it?

请让我知道如何解决它?

回答by Stawros

Try to convert varchar2 values to RAW-format before insert into BLOB fields -

在插入 BLOB 字段之前尝试将 varchar2 值转换为 RAW 格式 -

insert into FAC_CODE_CPQLDN(ID, CODE, NAME, NOTE, PARENT_ID) 
values (1, 'C1.1', UTL_RAW.CAST_TO_RAW('Chi phí c?ng ty'), null, 0);

回答by Ben

Most of this is unnecessary, you have a database with the characterset AL32UTF8, i.e. one that's already in a unicode characterset - UTF-8.

其中大部分是不必要的,您有一个包含 AL32UTF8 字符集的数据库,即一个已经在 unicode 字符集 - UTF-8 中的数据库。

If you declare the columns as a VARCHAR2 then you should be able to just insert the data.

如果您将列声明为 VARCHAR2,那么您应该能够插入数据。

SQL> create table fac_code_cpqldn(name varchar2(100));

Table created.

SQL> insert into fac_code_cpqldn values ('chi phí c?ng ty');

1 row created.

SQL>

NVARCHAR2s, NLOBs etc. are far more difficult to work with than the standard datatypes. For the avoidance of doubt; this is a 11.2 database:

NVARCHAR2、NLOB 等比标准数据类型更难使用。为避免疑义; 这是一个 11.2 的数据库:

SQL> select * from v$version;

BANNER
---------------------------------------------------------
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production

You can find out your characterset from NLS_DATABASE_PARAMETERS, as I originally commented:

正如我最初评论的那样,您可以从NLS_DATABASE_PARAMETERS 中找到您的字符

SQL> select value
  2    from nls_database_parameters
  3   where parameter = 'NLS_CHARACTERSET';

VALUE
-------------------------------------------
AL32UTF8