Rails3无法将“ñ"保存到Oracle 11g [英] Rails3 cannot save 'ñ' to Oracle 11g

查看:76
本文介绍了Rails3无法将“ñ"保存到Oracle 11g的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3.2.13,ruby 1.9.3和Oracle 11g.当在数据库中使用诸如ñ"之类的字符保存记录时,出现以下错误:

I'm using Rails 3.2.13, ruby 1.9.3 and Oracle 11g. When saving a record in the DB with a character like 'ñ' I get the error below:

ActiveRecord::StatementInvalid (Encoding::UndefinedConversionError:
U+00F1 from UTF-8 to US-ASCII: INSERT INTO "OMNIAUTH_USERS" ("CREATED_AT",
"FIRST_NAME", "ID", "LAST_NAME", "STATUS", "UID", "UPDATED_AT") VALUES (:a1,
:a2, :a3, :a4, :a5, :a6, :a7)):
app/controllers/user_sessions_controller.rb:18:in `create'

我试图运行此查询以查看Oracle使用的语言:

I tried to run this query to see the language used by Oracle:

SELECT USERENV ('language') FROM DUAL

它返回了AMERICAN_AMERICA.AL32UTF8.

It returned AMERICAN_AMERICA.AL32UTF8.

这些是我对Oracle的瑰宝:

These are my gems for Oracle:

gem 'ruby-oci8', '~> 2.1.5'
gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.2'
gem 'ruby-plsql', '~> 0.5.0'

我该怎么办?

推荐答案

您必须区分两个不同的nls设置

You have to distinguish two different nls settings

  • 外部-由应用程序中的环境变量NLS_LANG定义.当您将数据发送到OCI客户端库时,这确定了内部字符串的表示形式.

  • the external one - defined by the environment variable NLS_LANG in you application. This determines your internal string representation when you send data to OCI client library.

内部之一.这是Oracle用于将数据存储在磁盘上的字符集.

the internal one. It is the character set used by Oracle to store your data on disk.

尝试执行

select r.module, t.*
from v$sesssion_connection_info t
join v$session r on (r.sid = t.sid and t.serial# = r.serial#)
where r.sid = <your ruby connection SID>;

select * from nls_database_parameters;
select * from nls_instance_parameters;

如果显示,则说明您使用的是US7ASCII或ISO8859P1之类的字词,那么Oracle接受您的字符并将其转换为目标字符集(通过删除重音符号或替换为'?').

If it shows, that you are using something like US7ASCII or ISO8859P1 then Oracle accepts your character and converts it into target character set(either by removing an accent or by replacing with '?').

这篇关于Rails3无法将“ñ"保存到Oracle 11g的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆