Let's say we need to fetch the records from this sql query in rails.
The output will be something like
which is nothing but a cursor object. But how to read the records from this cursor?.
The code to fetch the record is
s = ActiveRecord::Base.connection.execute("select id, email from users" )
The output will be something like
< OCI8::Cursor:0xf73ac30 >
which is nothing but a cursor object. But how to read the records from this cursor?.
The code to fetch the record is
while r = s.fetch_hash puts s endThe output will be
{"ID"=>10005, "EMAIL"=>"2@gmail.com"} {"ID"=>10006, "EMAIL"=>"3@gmail.com"} {"ID"=>10002, "EMAIL"=>"1@gmail.com"}
No comments:
Post a Comment