Mike Chen
Mike Chen

Reputation: 1

Cannot read Chinese Char from SQL into R

I have a DB with Chinese collation (type: Chinese_PRC_CI_AS). When i read this DB into Rstudio, all the Characters becomes ????. I tried changing System Locale to Chinese settings (Sys.setlocale(category="LC_ALL",locale="chinese") but still doesn't work. Any ideas?

SQL DB: Columns in SQL

Columns in RStudio

I've searched the internet to no avail.

Thanks in advance

To provide more information, i'm using mssql, and sessionInfo() is:

R version 3.2.5 (2016-04-14) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1

locale: 1 LC_COLLATE=Chinese (Simplified)_People's Republic of China.936 LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936

attached base packages: 1 stats graphics grDevices utils datasets methods base

other attached packages: 1 RMySQL_0.10.9 DBI_0.5-1 date_1.2-36 data.table_1.10.4 stringr_1.1.0 ggplot2_2.2.1 RODBC_1.3-14 zoo_1.7-14 chron_2.3-49
[10] plyr_1.8.4

loaded via a namespace (and not attached): 1 Rcpp_0.12.9 lattice_0.20-34 assertthat_0.1 grid_3.2.5 gtable_0.2.0 magrittr_1.5 scales_0.4.1 stringi_1.1.2 lazyeval_0.2.0
[10] tools_3.2.5 munsell_0.4.3 colorspace_1.3-2 tibble_1.2

Upvotes: 0

Views: 526

Answers (1)

ahsen_mukhtar_maken
ahsen_mukhtar_maken

Reputation: 31

you can do the following:

 select * from table where [conditions]
 [remaining query]
 COLLATE DATABASE_DEFAULT;

use this last line to get the req collation.

Upvotes: 0

Related Questions