# ActiveRecord and null string in Oracle

**URL:** <https://www.ruby-forum.com/t/activerecord-and-null-string-in-oracle/150835>\
**Category:** Rails\
**Created:** [October 14, 2008, 12:11am UTC](https://www.ruby-forum.com/t/activerecord-and-null-string-in-oracle/150835 "2008-10-14T00:11:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [October 14, 2008, 12:11am UTC](https://www.ruby-forum.com/t/activerecord-and-null-string-in-oracle/150835/1 "2008-10-14T00:11:06Z")

</div>

When an empty string is stored in Oracle, it is converted to a null.  
When I retrieve it with rails, I get a nil object.

I would like to modify my Rails model to return an empty string  
instead of  
null for that attribute, instead of modifying code in multiple places.  
Is  
that easily doable? I tried an alias, but that did not work.

Thanks in Advance,  
Don Mc

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [October 14, 2008, 8:37am UTC](https://www.ruby-forum.com/t/activerecord-and-null-string-in-oracle/150835/2 "2008-10-14T08:37:05Z")

</div>

U can use a simple new method to return attribute.to\_s (nil.to\_s  
returns  
a blank string)

I don’t think there is a direct way to read a nil value from the  
database in  
an attribute… and then directly expecting the attribute value to be a  
blank  
string.

If null doesn’t mean anything to u, U can simply modify the database  
column  
to not accept null values and make the default blank string. Not sure  
if  
that works with oracle but i would have tried it.

Good luck

On Tue, Oct 14, 2008 at 12:10 AM, Don.Mc [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks in Advance,  
> Don Mc
> 
> >

–  
Mahmoud Said  
Software Developer

> **[Thoughts](http://blog.modsaid.com)**

www.eSpace.com.eg  
+20-16-1223857
