如何连接BLOB字段(Oracle)



是否可以连接特定表中的A1和A2(例如):

CREATE TABLE MY_SCHEME.CONC_BLOB
(
  A1       BLOB,
  A1_SORT  NUMBER(20),
  T_TYPE   VARCHAR2(9 BYTE),
  A2       BLOB,
  A2_SORT  NUMBER(20),
  A3       VARCHAR2(32 BYTE),
  A4       BLOB,
  A5       VARCHAR2(8 BYTE)
)

怎样

BLOB可以与DBMS_LOB包连接,特别是与APPEND过程连接。但是,您将需要使用一些PL/SQL来迭代相关行并调用过程。

我不太明白你所说的下表是什么意思,所以我不能给你举个例子。

更新:

PL/SQL的相关部分可能如下所示:

DECLARE
  a1_lob BLOB;
  a2_lob  BLOB;
BEGIN
  SELECT A1, A2 INTO a1_lob, a2_lob
  FROM CONC_BLOB
  WHERE A1_SORT = 'some value'
  FOR UPDATE;
  dbms_lob.append(a1_lob, a2_lob);
  COMMIT;
END;

FYI:如果您打算使用blob来存储大文本(这就是为什么我想将它们连接起来),我建议使用CLOB。它将允许您在连接的最佳部分使用||。不幸的是,当clob的长度超过32767 时,您可能会面临||的问题

以下是我使用帮助表类型和存储函数将任意数量的BLOB连接到单个BLOB的解决方案:

create or replace type blobs as table of blob;
create or replace function concat_blobs(parts in blobs) return blob
is
    temp blob;
begin
    if parts is null or parts.count = 0 then
       return null;
    end if;
    dbms_lob.createtemporary(temp, false, dbms_lob.CALL);
    for i in parts.first .. parts.last
    loop
        dbms_lob.append(temp, parts(i));
    end loop;
    return temp;
end;
-- usage example:
select concat_blobs(blobs(to_blob(hextoraw('CAFE')), to_blob(hextoraw('BABE')))) from dual;

-- bonus
create or replace type raws as table of raw(2000);
create or replace function raws_to_blobs(arg in raws) return blobs
is
    res blobs;
begin
    select to_blob(column_value) bulk collect into res from table(arg);
    return res;
end;
-- usage example:
select concat_blobs(raws_to_blobs(raws(hextoraw('CAFE'), hextoraw('BABE'))) from dual;

另请参阅Oracle 10中的多个RAW串联:使用HEXTORAW填充blob数据。

最新更新