# ActiveRecord Oracle and nvarchar2 or nclob datatype

**URL:** <https://www.ruby-forum.com/t/activerecord-oracle-and-nvarchar2-or-nclob-datatype/154945>\
**Category:** Rails\
**Created:** [December 5, 2008, 1:20pm UTC](https://www.ruby-forum.com/t/activerecord-oracle-and-nvarchar2-or-nclob-datatype/154945 "2008-12-05T13:20:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 5, 2008, 1:20pm UTC](https://www.ruby-forum.com/t/activerecord-oracle-and-nvarchar2-or-nclob-datatype/154945/1 "2008-12-05T13:20:30Z")

</div>

Hi,

I ve got oracle database which exists prior to my rails app… ☹

I ve got trouble when I am updating/inserting records of a table which  
includes nvarchar2 attributes.  
These have a specific maximum length.

I often get an error Value too long for column when doing my inserts/  
updates, but in fact that is not the case.  
I ve taken a look at the generated sql statements…

As far as I know you should add a “N” in front of the quoted value for  
oracle nvarchar2 or nclob datatypes…  
That s not happening inside of ActiveRecord, which is in my opinion  
the reason for my errors.

Has anybody a solution for this issue?

Thanks a lot in advance…  
Volker

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 15, 2008, 6:02pm UTC](https://www.ruby-forum.com/t/activerecord-oracle-and-nvarchar2-or-nclob-datatype/154945/2 "2008-12-15T18:02:26Z")

</div>

Just in case somebody is facing this issue as well…

It seems that ActiveRecord is not handling oracle nvarchar2 column  
types correctly.

If somebody is facing my issue: Please find beloa the code for a fix  
Many thanks to the oci adapter engineer who did the main work for it.

module ActiveRecord  
module ConnectionAdapters #:nodoc:  
class OracleColumn \< Column #:nodoc:  
attr\_reader :nchar  
def initialize(name, default, sql\_type, null)  
super  
@nchar = (@type == :string && sql\_type[0,1] == ‘N’)  
end  
end

```
class OracleAdapter < AbstractAdapter
  def quote(value, column = nil) #:nodoc:
    if value && column && [:text, :binary].include?(column.type)
      %Q{empty_#{ column.sql_type.downcase rescue 'blob' }()}
    elsif value && column && column.nchar
      'N' + super
    else
      super
    end
  end
end

```

end  
end
