在 SQL 数据库中存储阿拉伯语

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3560173/
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-01 07:19:03  来源:igfitidea点击:

store arabic in SQL database

sqlsql-serversql-server-2008collation

提问by kartal

I tried to store Arabic string in SQL 2008 database but it converted to " question mark " why ? and what should I do ?

我试图在 SQL 2008 数据库中存储阿拉伯字符串,但它转换为“问号”,为什么?我该怎么办?

回答by Martin Smith

You need to choose an Arabic collation for your varchar/char columns or use Unicode (nchar/nvarchar)

您需要为 varchar/char 列选择阿拉伯语排序规则或使用 Unicode (nchar/nvarchar)

CREATE TABLE #test
(
col1 VARCHAR(100) COLLATE Latin1_General_100_CI_AI,
col2 VARCHAR(100) COLLATE Arabic_CI_AI_KS_WS,
col3 NVARCHAR(100)
)
INSERT INTO #test VALUES(N'?? ????? ???????',N'?? ????? ???????',N'?? ????? ???????')

Note the N before values in insert statement above. If you do not mention it, system will treat the values as Varchar, not NVarchar.

注意上面插入语句中的 N 之前的值。如果您不提及它,系统会将这些值视为 Varchar,而不是 NVarchar。

SELECT * FROM #test

Returns

退货

col1                           col2                           col3
------------------------------ ------------------------------ ------------------------------
?? ????? ???????               ?? ????? ???????               ?? ????? ???????

To see a list of Arabic collations use

要查看阿拉伯语排序规则列表,请使用

SELECT name, description 
FROM fn_helpcollations() 
WHERE name LIKE 'Arabic%'

回答by Basheer AL-MOMANI

All of what you have to do is to make sure that

你所要做的就是确保

the column Data typeis nvarchar()

column Data typenvarchar()

enter image description here

在此处输入图片说明

after that I inserted Arabic with no problems

之后我插入阿拉伯语没有问题

enter image description here

在此处输入图片说明

回答by A Ghazal

You can change the collation on the database level instead of changing for each column in the database:

您可以在数据库级别更改排序规则,而不是更改数据库中的每一列:

USE master;
GO
ALTER DATABASE TestDB
COLLATE Arabic_CI_AI;
GO

回答by nazim hatipoglu

insert into table (column) values (N'xxx').)

插入表(列)值(N'xxx')。)

You should put N before string to make it unicode

您应该将 N 放在字符串之前以使其成为unicode

回答by Pradeepkumar Cb

Try using this:
the column Data type is nvarchar()

尝试使用这个:
列数据类型是nvarchar()

INSERT INTO CompanyMaster values(N'" + txtCompNameAR.Text + "',N'" + txtCompAddressAR.Text + "','" + txtPh.Text + "')

回答by Biskrem Muhammad

make sure all your tables and varcharcolumns have the collation of utf8_general_ci

确保所有表和varchar列的整理utf8_general_ci

回答by jaad salem

Add 'N'before every value. example:

在每个值之前添加“N”。例子:

INSERT INTO table1 VALUES(N'aaaaaaaaa',N'?????????????',N'aaaaaaaaaaa',N'???????????')

回答by Akram

Iti is easy to store Arabic string in Oracle. Use this code:

在 Oracle 中存储阿拉伯字符串很容易。使用此代码:

declare @P_CUSTOMER_NAME  nchar(50) 
set @P_CUSTOMER_NAME2=N'??????'

The above will save in Oracle just fine.

以上将保存在Oracle中就好了。