将映像插入BLOB Oracle 10g [英] Inserting Image Into BLOB Oracle 10g

查看:95
本文介绍了将映像插入BLOB Oracle 10g的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像插入签名的BLOB字段中,然后从表中进行选择并呈现在报告上.我似乎无法弄清楚如何将图像放入表格中.但是,当我只渲染图像的路径而不是图像本身时,我做了一个插入操作.

I am trying to insert an image into an BLOB field in a signatures which i will then select from the table and render on a report. I cannot seem to figure how to get the image into the table. I did an insert however when i render only the path to the image was shown on the report and not the image itself.

表格

CREATE TABLE esignatures (
  office   NUMBER(6,0)  NOT NULL,
  username VARCHAR2(10) NOT NULL,
  iblob    BLOB         NOT NULL
)

INSERT语句(SQL)

INSERT INTO esignatures  
VALUES (100, 'BOB', utl_raw.cast_to_raw('C:\pictures\image1.png'));

我肯定知道我要以十六进制值的形式插入字符串位置,我如何才能在表中获取图像的十六进制值,因此在渲染时我会看到正在显示的图像.

I know for sure i am inserting the String location in the form of a HEX value how can i get the image HEX value in the table so when i render i will see the image being displayed.

推荐答案

您无法从pl/sql访问本地目录.如果使用bfile,则将建立目录(创建目录)在运行Oracle的服务器上,您将需要在其中放置映像.

You cannot access a local directory from pl/sql. If you use bfile, you will setup a directory (create directory) on the server where Oracle is running where you will need to put your images.

如果要从本地计算机插入少量图像,则需要一个客户端应用程序来执行此操作.您可以编写自己的脚本,但是我通常为此使用Toad.在架构浏览器中,单击到表.单击数据选项卡,然后按+号添加一行.双击BLOB列,然后将打开一个向导.最左侧的图标会将图像加载到Blob中:

If you want to insert a handful of images from your local machine, you'll need a client side app to do this. You can write your own, but I typically use Toad for this. In schema browser, click onto the table. Click the data tab, and hit + sign to add a row. Double click the BLOB column, and a wizard opens. The far left icon will load an image into the blob:

SQL Developer具有类似的功能.请参见下面的加载"链接:

SQL Developer has a similar feature. See the "Load" link below:

如果您需要通过导线拉图像,则可以使用pl/sql进行操作,但并非一帆风顺.首先,您需要设置ACL列表访问权限(出于安全原因),以允许用户拉线.请参阅本文有关ACL设置的更多信息.

If you need to pull images over the wire, you can do it using pl/sql, but its not straight forward. First, you'll need to setup ACL list access (for security reasons) to allow a user to pull over the wire. See this article for more on ACL setup.

假设ACL已完成,您将像这样拉出图像:

Assuming ACL is complete, you'd pull the image like this:

declare
    l_url varchar2(4000) := 'http://www.oracleimg.com/us/assets/12_c_navbnr.jpg';
    l_http_request   UTL_HTTP.req;
    l_http_response  UTL_HTTP.resp;
    l_raw RAW(2000);
    l_blob BLOB;
begin
   -- Important: setup ACL access list first!

    DBMS_LOB.createtemporary(l_blob, FALSE);

    l_http_request  := UTL_HTTP.begin_request(l_url);
    l_http_response := UTL_HTTP.get_response(l_http_request);

  -- Copy the response into the BLOB.
  BEGIN
    LOOP
      UTL_HTTP.read_raw(l_http_response, l_raw, 2000);
      DBMS_LOB.writeappend (l_blob, UTL_RAW.length(l_raw), l_raw);
    END LOOP;
  EXCEPTION
    WHEN UTL_HTTP.end_of_body THEN
      UTL_HTTP.end_response(l_http_response);
  END;

  insert into my_pics (pic_id, pic) values (102, l_blob);
  commit;

  DBMS_LOB.freetemporary(l_blob); 
end;

希望有帮助.

这篇关于将映像插入BLOB Oracle 10g的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆