cancel
Showing results for 
Search instead for 
Did you mean: 

In HANA VARCHAR datatype stores unicodes?

Former Member
0 Kudos

Hi,

In my previous document (), I write about NVARCHAR, it can store both non-Unicode and Unicode. and VARCHAR stores only non-Unicode characters. but following script insert Unicode in VARCHAR also, if so what is difference between VARCHAR and NVARCHAR.




CREATE COLUMN TABLE NEWS ( ID INTEGER  NOT NULL , NDATA NVARCHAR(500), DATA VARCHAR(500), PRIMARY KEY ("ID"));

INSERT INTO NEWS (ID, NDATA, DATA) VALUES(1,'दिल्ली भारत की राजधानी है.', 'Delhi is capital of India.');

INSERT INTO NEWS (ID, NDATA, DATA) VALUES(2,'मुंबई महाराष्ट्राची राजधानी आहे.', 'Mumbai is capital of Maharashtra.');

INSERT INTO NEWS (ID, NDATA, DATA) VALUES(3, 'Mumbai is capital of Maharashtra.', 'मुंबई महाराष्ट्राची राजधानी आहे.');



and output looks like




Accepted Solutions (0)

Answers (1)

Answers (1)

lbreddemann
Active Contributor
0 Kudos

HI there

the difference mainly is how the size of columns are interpreted - not what data goes in or out.

The actual internal implementation data type is exactly the same (check CS_COLUMN_TYPE in  TABLE_COLUMNS).


create column table vartest (vc varchar(10), nvc nvarchar(10));

insert into vartest values ('조조조조조조조조조조' ,'조조조조조조조조조조');

Started: 2014-06-13 17:32:04

Could not execute 'insert into vartest values ('조조조조조조조조조조' ,'조조조조조조조조조조')' in 38 ms 927 µs .

SAP DBTech JDBC: [274]: inserted value too large for column: Failed in "VC" column with the value '조조조조조조조조조조'


insert into vartest values ('조조조' ,'조조조조조조조조조조');

Started: 2014-06-13 17:32:43

Statement 'insert into vartest values ('조조조' ,'조조조조조조조조조조')'

successfully executed in 69 ms 241 µs  (server processing time: 36 ms 103 µs) - Rows Affected: 1 ;

Although both columns are of the same "length" the interpretation for varchar and nvarchar is quite different.

- Lars

henrique_pinto
Active Contributor
0 Kudos

So, varchar(10) contains 10 single-byte characters, while nvarchar(10) contains 10 multi-byte characters (the actual size depends on the codepage used for encoding, I guess).

lbreddemann
Active Contributor
0 Kudos

Correct - the size check ensures that only so much data gets inserted that a client application that expects single-byte characters don't get delivered too much data when reading the column.

The internal encoding however is, if I'm not mistaken, always CESU-8.