HelloWorld
HelloWorld

Reputation: 4349

Like statement in Rails 3

I'm trying to run a simple like clause using the following code...

Message.where('to LIKE ?', '%hi')

My model class is as follows...

class Message < ActiveRecord::Base

attr_accessor :from, :error_messages, :use_background_job, :to
attr_accessible :status, :to, :from, :cc, :bcc, :subject, :body, :error_messages, :use_background_job

I'm using activerecord and the activerecord-oracle_enhanced-adapter gem. However I get the following error...

  ←[1m←[36mMessage Load (161.1ms)←[0m  ←[1mSELECT "MESSAGES".* FROM "MESSAGES" WHERE (to LIKE 'hi')←[0m
ActiveRecord::StatementInvalid: OCIError: ORA-00936: missing expression: SELECT "MESSAGES".* FROM "MESSAGES"  WHERE (to LIKE 'hi')
        from stmt.c:230:in oci8lib_191.so
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.1.5-x86-mingw32/lib/oci8/cursor.rb:126:in `exec'

Is this an Oracle issue or is my syntax for the like clause incorrect?

Upvotes: 0

Views: 146

Answers (2)

Raghu
Raghu

Reputation: 2563

Try using Message.where('messages.to LIKE ?', '%hi'). I think 'to' is a reserved keyword in sql.

Upvotes: 1

usha
usha

Reputation: 29369

Looks like "to" is a Oracle Keyword.

Try this

Message.where('"to" LIKE ?', '%hi')

Oracle uses double quotes to escape keywords

Upvotes: 1

Related Questions