a4114
a4114

Reputation: 41

How can I get japanese character correctly shown in oracle database

I know oracle database have two character set : NLS_NCHAR_CHARACTERSET and NLS_CHARACTERSET.

I have set them as:

NLS_CHARACTERSET           WE8MSWIN1252
NLS_NCHAR_CHARACTERSET     UTF8

when I create the database.

Also I create my table use NVARCHAR not VARCHAR,so it is supposed to be saved use UTF8 :

ID          NUMBER      
EMAIL       NVARCHAR2(255)  
USER_NAME   NVARCHAR2(255)      
POST_AT     DATE
CONTENTS    NVARCHAR2(255)  

However I can not get the right outputs. When I insert rows containing japanese characters, it just give out like "???" when I check it at terminal.

I don't know why it is not working. Does any one know a method to solve this problem?

Also, if I don't care how it is saved in database, just want to get the right output after taking out from database, is there any method to decode it correctly? (I have tried several method to convert encoding but not working)

I use PHP's OCI8 to access the database. the version of oracle database is oracle 11gR2 for linux.x64

Upvotes: 4

Views: 2387

Answers (2)

a4114
a4114

Reputation: 41

Thanks for all helps. I cannot resolve this problem after all without recreate the database and reset the character set... one thing I learned is that one MUST pay attention to the initial setting when creating a oracle database...

Upvotes: 0

Thomas Martin Klein
Thomas Martin Klein

Reputation: 444

If all else fails, you can http://php.net/manual/en/function.base64-encode.php the string before inserting and decode after fetching. Worst case.

Upvotes: 1

Related Questions