ORA-01722: Invalid number when implementing the Ruby article sample
112632Dec 15 2006 — edited Dec 15 2006Hi all,
When I implemented the Ruby on Rails article posted in http://www.oracle.com/technology/pub/articles/haefel-oracle-ruby.html, I found the following problem:
Everything was fine until I decided to test my application. When my web app tried to access some record of the table, the following error happened:
OCIError: ORA-01722: invalid number: select * from (select raw_sql_.*, rownum raw_rnum_ from (SELECT * FROM comics WHERE (comics.id = '2.0') ) raw_sql_ where rownum <= 1) where raw_rnum_ > 0
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in `log'
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/oracle_adapter.rb:277:in `execute'
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/oracle_adapter.rb:477:in `select'
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/oracle_adapter.rb:268:in `select_all'
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:390:in `find_by_sql'
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:924:in `find_every'
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:918:in `find_initial'
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:952:in `find_one'
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:941:in `find_from_ids'
F:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:382:in `find'
#{RAILS_ROOT}/app/controllers/comics_controller.rb:16:in `show'
The problem was related with the way RoR is accessing my table. I don't know the reason, but RoR is automatically building the SELECT sentence declaring my 'id' column as VARCHAR, so the sentence includes the expression " comics.id = '2.0' ".
I would like to hear the advice from more experienced RoR developers in order to solve this little issue... (I believe this is more a RoR problem than an Oracle one, but I didn't find anything useful in Rail forums).
Thank you very much in advance for your help.
Gregorio