20

Hell when I do:

select COALESCE (CORP_ID, 0) from crmuser.accounts;

The CORP_ID records which are Null returns 0 but when I do:

select COALESCE (EMAIL, 'NO EMAIL') from crmuser.accounts

I get an error:

ORA-12704: character set mismatch

The EMAIL field in NVARCHAR2(30). Is is My Datatype and if so What should I do to return default Values?

YasirA
  • 9,531
  • 2
  • 40
  • 61
Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168

2 Answers2

31

you should do

select COALESCE (EMAIL, n'NO EMAIL') from crmuser.accounts

to convert the literal to NVARCHAR.

eg http://sqlfiddle.com/#!4/73929/1 vs http://sqlfiddle.com/#!4/73929/2

DazzaL
  • 21,638
  • 3
  • 49
  • 57
2

This generic fix works with columns defined as either VARCHAR2 or NVARCHAR2:

select COALESCE (EMAIL, N'' || 'NO EMAIL') from crmuser.accounts

Just add N'' || before your non-Unicode string constant.

Cristian Scutaru
  • 1,375
  • 19
  • 23