gpt4 book ai didi

oracle10g - 将当前 CLOB 列复制到 Oracle 中的新 BLOB 列

转载 作者:行者123 更新时间:2023-12-04 05:38:23 28 4
gpt4 key购买 nike

我有一张 table ,上面有 CLOB列。我想将现有数据转换为 BLOB数据类型。失败了 ORA-252858 invalid alteration of datatype .

我想创建一个新的 BLOB列,将现有数据复制到其中,然后删除现有 CLOB列。

如何从 CLOB 复制列到 BLOB柱子?

最佳答案

create table temp(col_clob clob,col_blob blob);

insert into temp (col_clob) values('hi i am gaurav soni');
insert into temp (col_clob) values('hi i am gaurav soni');
insert into temp (col_clob) values('hi i am gaurav soni');
insert into temp (col_clob) values('hi i am gaurav soni');
insert into temp (col_clob) values('hi i am gaurav soni');

/你需要创建一个函数,将clob转换为blob,如下所示:
坦率地说,我从另一个来源获取了这个功能,但你会感到困惑,因为在那个论坛上有一个讨论,这就是为什么我在这里提到/
create or replace function CLOB_TO_BLOB (p_clob CLOB) return BLOB
as
l_blob blob;
l_dest_offset integer := 1;
l_source_offset integer := 1;
l_lang_context integer := DBMS_LOB.DEFAULT_LANG_CTX;
l_warning integer := DBMS_LOB.WARN_INCONVERTIBLE_CHAR;
BEGIN

DBMS_LOB.CREATETEMPORARY(l_blob, TRUE);
DBMS_LOB.CONVERTTOBLOB
(
dest_lob =>l_blob,
src_clob =>p_clob,
amount =>DBMS_LOB.LOBMAXSIZE,
dest_offset =>l_dest_offset,
src_offset =>l_source_offset,
blob_csid =>DBMS_LOB.DEFAULT_CSID,
lang_context=>l_lang_context,
warning =>l_warning
);
return l_blob;
END;

--update the col_blob with the function we have created above

update temp set col_blob = clob_to_blob(col_clob);

select * from temp;

输出
 COL_CLOB                               COL_BLOB           
-------------------------------------- -------------------
hi i am gaurav soni hi i am gaurav soni
hi i am gaurav soni hi i am gaurav soni
hi i am gaurav soni hi i am gaurav soni
hi i am gaurav soni hi i am gaurav soni
hi i am gaurav soni hi i am gaurav soni

关于oracle10g - 将当前 CLOB 列复制到 Oracle 中的新 BLOB 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11612181/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com