1、clob欄位轉varchar欄位主要用到dbms_lob.substr方法,該方法有三個引數,分別是截取的clob欄位、截取長度以及起始位置,其中欄位名為必須的,截取長度以及其實位置可以根據需要使用,
dbms_lob.substr(欄位名,長度,起始位置)
2、varchar轉clob使用to_clob()方法,其官方解釋如下:
The TO_CLOB function converts NCLOB values in a LOB column or other character strings to CLOB values. char can be any of the datatypes CHAR, VARCHAR2, NCHAR,NVARCHAR2, CLOB, or NCLOB.
Oracle executes this function by converting the underlying LOB data from the national character set to the database character set.
to_clob(欄位名)
下面舉例進行說明(在陳述句執行后,請注意提交):
首先創建測驗表,表中包含三個字典,標識碼、clob測驗欄位和varchar測驗欄位,
create table t_test(id number,f_lob clob,f_str varchar(4000));
在表中插入一條測驗資料,其中clob和varchar欄位默認都為空,
insert into t_test(id ,f_lob ,f_str ) values (1,empty_clob(),'');
設定字串為4000長度,內容隨機
update t_test t set t.f_str=(SELECT DBMS_RANDOM.STRING ('x', 4000) FROM DUAL) where t.id=1;
設定clob欄位的值為f_str欄位的值
update t_test t set t.f_lob=to_clob(t.f_str) where t.id=1;
設定f_str的值為clob欄位的值
update t_test t set t.f_str='' where t.id=1;
update t_test t set t.f_str=dbms_lob.substr(t.f_lob,4000,1) where t.id=1;
注意:因為clob的欄位長度最大為4GB,varchar的最大長度為4000,所以在轉換的時候可能會造成資料部分內容丟失,因此在轉換之前,建議先通過DBMS_LOB.GETLENGTH(欄位名)方法查看欄位的長度后再進行轉換,避免資料內容丟失,
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/164813.html
標籤:其他
下一篇:uni-app 呼叫 jar 包
