如何使用 ORACLE 中的 SQL UPDATE 命令将 BLOB 数据附加/连接到 BLOB 列

发布于 2024-11-18 03:35:41 字数 389 浏览 3 评论 0原文

我需要将数据附加到我的 BLOB 字段, 如何使用 UPDATE 命令执行此操作? 我要问的是;是否可以连接 blob 数据,以便我最终可以将其设置为类似的字段 更新BLOB_表 放 BLOB_field = BLOB_field + BLOB_data

我尝试使用 DBMS_LOB.APPEND 但它不返回值;所以我创建了一个函数,它给出了“指定的 LOB 定位器无效”的错误

CREATE OR REPLACE FUNCTION MAKESS.CONCAT_BLOB(A in BLOB,B in BLOB) RETURN BLOB IS
 C BLOB;
BEGIN
DBMS_LOB.APPEND(c,A);
DBMS_LOB.APPEND(c,B);
RETURN c;
END;
/

I need to append data to my BLOB field,
how can I do this using an UPDATE command?
What i am asking is; is it possible to concatenate blob data so that i can eventually set it to a field like
UPDATE BLOB_table
SET
BLOB_field = BLOB_field + BLOB_data

I tried using DBMS_LOB.APPEND but it does not return a value; so i created a function which gives me an error of "invalid LOB locator specified"

CREATE OR REPLACE FUNCTION MAKESS.CONCAT_BLOB(A in BLOB,B in BLOB) RETURN BLOB IS
 C BLOB;
BEGIN
DBMS_LOB.APPEND(c,A);
DBMS_LOB.APPEND(c,B);
RETURN c;
END;
/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愿得七秒忆 2024-11-25 03:35:41

您需要使用 创建一个临时 blob DBMS_LOB.createtemporary

SQL> CREATE OR REPLACE FUNCTION CONCAT_BLOB(A IN BLOB, B IN BLOB) RETURN BLOB IS
  2     C BLOB;
  3  BEGIN
  4     dbms_lob.createtemporary(c, TRUE);
  5     DBMS_LOB.APPEND(c, A);
  6     DBMS_LOB.APPEND(c, B);
  7     RETURN c;
  8  END;
  9  /

Function created

那么您应该能够在更新语句中使用它:

SQL> CREATE TABLE t (a BLOB, b BLOB, c BLOB);

Table created

SQL> INSERT INTO t VALUES
  2     (utl_raw.cast_to_raw('aaa'), utl_raw.cast_to_raw('bbb'), NULL);

1 row inserted

SQL> UPDATE t SET c=CONCAT_BLOB(a,b);

1 row updated

SQL> SELECT utl_raw.cast_to_varchar2(a),
  2         utl_raw.cast_to_varchar2(b),
  3         utl_raw.cast_to_varchar2(c)
  4  FROM t;

UTL_RAW.CAST_TO_VARCHAR2(A UTL_RAW.CAST_TO_VARCHAR2(B UTL_RAW.CAST_TO_VARCHAR2(C
-------------------------- -------------------------- --------------------------
aaa                        bbb                        aaabbb 

You need to create a temporary blob with DBMS_LOB.createtemporary:

SQL> CREATE OR REPLACE FUNCTION CONCAT_BLOB(A IN BLOB, B IN BLOB) RETURN BLOB IS
  2     C BLOB;
  3  BEGIN
  4     dbms_lob.createtemporary(c, TRUE);
  5     DBMS_LOB.APPEND(c, A);
  6     DBMS_LOB.APPEND(c, B);
  7     RETURN c;
  8  END;
  9  /

Function created

Then you should be able to use it in an update statement:

SQL> CREATE TABLE t (a BLOB, b BLOB, c BLOB);

Table created

SQL> INSERT INTO t VALUES
  2     (utl_raw.cast_to_raw('aaa'), utl_raw.cast_to_raw('bbb'), NULL);

1 row inserted

SQL> UPDATE t SET c=CONCAT_BLOB(a,b);

1 row updated

SQL> SELECT utl_raw.cast_to_varchar2(a),
  2         utl_raw.cast_to_varchar2(b),
  3         utl_raw.cast_to_varchar2(c)
  4  FROM t;

UTL_RAW.CAST_TO_VARCHAR2(A UTL_RAW.CAST_TO_VARCHAR2(B UTL_RAW.CAST_TO_VARCHAR2(C
-------------------------- -------------------------- --------------------------
aaa                        bbb                        aaabbb 
一枫情书 2024-11-25 03:35:41

借助 PL/SQL blob 可以就地更新,根本不需要自定义函数:

BEGIN
   FOR c IN (select a, b from t where a is not null for update) LOOP
       DBMS_LOB.APPEND(c.a, c.b);
   END LOOP;
END;
/

With help of PL/SQL blob can be updated in place with no need for custom function at all:

BEGIN
   FOR c IN (select a, b from t where a is not null for update) LOOP
       DBMS_LOB.APPEND(c.a, c.b);
   END LOOP;
END;
/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文