學(xué)習(xí)小結(jié)-oracle

select distinct brands.*from product_prices
inner join products on products.id = product_prices.product_id
inner join brands on brands.id = products.brand_id
inner join product_batches on product_prices.batch_id = product_batches.id
where (quotation_batches.id =289859 OR quotation_batches.group_id =289859) 
and products.publish_stage IN (0,1)
 and brands.status NOT IN (1,2)

由于三張表都比較大,順序的影響可以先不考慮;

select * from 
( select distinct * from products where products.publish_stage IN (0,1) )  t1
inner join  ( select distinct brands.*from brands where  brands.status NOT IN (1,2) ) t2 
on t1.batch_id  = t2.id
inner join product_prices t3 on  t1.id = t3.product_id
inner join product_batches t4 on t3.batch_id = t4.id

我的思路:盡量縮小聯(lián)查的每個表的數(shù)據(jù)量;

下面在網(wǎng)上找到關(guān)于:Ruby通過OCI8操作Oracle存儲的事例

1.讀blob的存儲過程

CREATE OR REPLACE PROCEDURE "P_READ_IMAGE"
(
V_IMG_ID IN NUMBER,
CUR_RESULT OUT SYS_REFCURSOR
)
AS
BEGIN
    OPEN CUR_RESULT FOR
    SELECT ID,IMG
    FROM T_IMAGE
    WHERE ID=V_IMG_ID ;
END;

5、ruby讀圖片操作

require 'oci8'
h_conn = OCI8.new(DB_USER, DB_PASSWORD, DB_SERVER)
s_photo_target_path = "~/222.jpg"
photo_id = 1
begin
    cursor = h_conn.parse('begin P_READ_IMAGE(
          :img_id,
          :list
      ); end;')
    cursor.bind_param(':img_id', photo_id)
    cursor.bind_param(':list', nil, OCI8::Cursor)
    cursor.exec()
    ret_cursor = cursor[':list']
    puts ret_cursor.getColNames.join(",")
    while row = ret_cursor.fetch()
        puts row[0]
        File.open(s_photo_target_path, 'wb') do |f|
            f.write(row[1].read)
        end
        break;
    end
rescue OCIError
    puts '-'*80
    puts "Code: " + $!.code.to_s
    puts "Desc: " + $!.message
    puts '-'*80
end

相關(guān)鏈接:http://www.thinksaas.cn/topics/0/497/497546.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容