我有一个带CLOB
列的表。我想将现有数据转换为数据BLOB
类型。那失败了ORA-252858 invalid alteration of datatype
。
我想创建一个新BLOB
列,将现有数据复制到其中,然后删除现有CLOB
列。
如何从CLOB
列复制到BLOB
列?
我有一个带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
我有来自Quest 的信息:Oracle:如何将 CLOB 转换为 BLOB
在此处复制代码以避免死链接:
CREATE OR REPLACE FUNCTION clob_to_blob(p_clob IN CLOB) RETURN BLOB IS
v_blob BLOB;
v_offset NUMBER DEFAULT 1;
v_amount NUMBER DEFAULT 4096;
v_offsetwrite NUMBER DEFAULT 1;
v_amountwrite NUMBER;
v_buffer VARCHAR2(4096 CHAR);
BEGIN
dbms_lob.createtemporary(v_blob, TRUE);
Begin
LOOP
dbms_lob.READ (lob_loc => p_clob,
amount => v_amount,
offset => v_offset,
buffer => v_buffer);
v_amountwrite := utl_raw.length (r => utl_raw.cast_to_raw(c => v_buffer));
dbms_lob.WRITE (lob_loc => v_blob,
amount => v_amountwrite,
offset => v_offsetwrite,
buffer => utl_raw.cast_to_raw(v_buffer));
v_offsetwrite := v_offsetwrite + v_amountwrite;
v_offset := v_offset + v_amount;
v_amount := 4096;
END LOOP;
EXCEPTION
WHEN no_data_found THEN
NULL;
End;
RETURN v_blob;
END clob_to_blob;
这对我有用,即使 dbms_lob.converttoclob 没有。