【问题标题】:How to take more than 1000 records in array using rails 2如何使用rails 2在数组中获取超过1000条记录
【发布时间】:2015-02-16 12:12:21
【问题描述】:

如何使用rails 2从oracle数据库中获取1000多条记录

 @business_users_loc = User.find(:all,:conditions=>"(users.role_id NOT IN ('#{Role[:submember].id}') AND locations.mac_id IS NOT NULL and users.mac_id IS NOT NULL and locations.location_type='Business')",:order => 'users.created_at DESC',:joins=>:locations,:include=>[{:locations=>[:social_network_mac_id,{:pronto_gateway=>[:heartbeat]},:fb_sponsors_fanpage]}],:select=>"distinct(users.login_slug), users.created_at, users.email, users.login, users.id")

当我尝试上述查询时,我得到了这个错误

 ActiveRecord::StatementInvalid: OCIError: ORA-01795: maximum number of expressions in a list is 1000: SELECT * FROM "LOCATIONS" WHERE ("LOCATIONS"."ID" IN (19228,18667,14642,15727,13541,14700,....

你能帮帮我吗....

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-2 ruby-1.8.7


    【解决方案1】:

    用途:

    User.find_in_batches(:all,:conditions=>"users.role_id NOT IN ('#{Role[:submember].id}')") do |users|
     users.each do |user|
      #do somthing
     end
    end
    

    【讨论】:

      【解决方案2】:

      你可以看看find_in_batches方法。

      options = {
       :conditions=>"users.role_id NOT IN ('#{Role[:submember].id}')",
       :batch_size => 1010
      }
      User.find_in_batches(options) do |group|
        # YOUR CODE
      end
      

      根据需要更改:batch_size的值;默认值为 1000。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-17
        • 1970-01-01
        • 1970-01-01
        • 2017-05-21
        相关资源
        最近更新 更多