美文网首页
学习小结-oracle

学习小结-oracle

作者: fred_ma | 来源:发表于2017-01-06 00:05 被阅读0次
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

我的思路:尽量缩小联查的每个表的数据量;

下面在网上找到关于: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

相关链接:http://www.thinksaas.cn/topics/0/497/497546.html

相关文章

  • 学习小结-oracle

    由于三张表都比较大,顺序的影响可以先不考虑; 我的思路:尽量缩小联查的每个表的数据量; 下面在网上找到关于:Rub...

  • Oracle命令小结

    基本信息 系统用户: sys,systemsysmanScott其中scott的默认密码是tiger dba_us...

  • 【转载】Nested loops、Hash join、Sort

    原文地址 nested loop 嵌套循环(原理): oracle从较小结果集(驱动表、也可以被称为outer)中...

  • Oracle手工注入小结

    前言: 明日复明日,明日何其多。既然这么多,不妨再拖拖。 Mysql和Mssql的注入环境都有了,手注也简单过了一...

  • Docker安装Oracle,并使用navicat连接Oracl

    查找oracle镜像docker search oracle 我们选择学习版,不选择完整版oracle-xe-11...

  • 相老师的OCP教程 1-5课文字版

    甲骨论相老师01课笔记 Oracle的学习软件:sqldeveloper。学习Oracle时一定要注重原理的学习,...

  • 复习进度日更2

    日期:2020.1.12.17 学习时长:0.5H 政治学习内容小结:未学习 英语学习内容小结:未学习 专业科学习...

  • 复习进度日更3

    日期:2020.1.12.17 学习时长:0.5H 政治学习内容小结:未学习 英语学习内容小结:未学习 专业科学习...

  • JOIN

    ORACLE的SQL JOIN方式小结详细介绍了各种JOIN,以及(+)的表达方式image.png 一张图看懂J...

  • 复习进度日更1

    日期:2020.12.16 学习时长:0.5h 政治学习内容小结:未完成学习 英语学习内容小结:未完成学习 专业科...

网友评论

      本文标题:学习小结-oracle

      本文链接:https://www.haomeiwen.com/subject/vrctbttx.html