嘗試將 LONG 值的資料型別轉換為 char 時出現以下錯誤
從 alr_alerts a,alr_actions aa 中選擇 DBMS_LOB.SUBSTR(a.sql_statement_text)
其中 a.alert_id = aa.alert_id 和 a.alert_id =100081

sql_statement_text定義為 LONG 列。
uj5u.com熱心網友回復:
正如評論中提到的,long不能在 SQL 函式中使用,因此您最好重新設計表的結構并將其轉換為clob以使生活更輕松。
但是,如果您仍然需要以long源型別訪問此資料,則可以使用兩種方法。
- 將獲取
long(在 PL/SQL 中)并將其轉換為clob. 這從 12.1 開始可用,但它會為每行打開一個新的子游標。
with function f_get_long_as_clob( p_id int ) return clob as l_long long; begin select do_not_use_long into l_long from test_tab where id = p_id; return to_clob(l_long); end; select test_tab.id, f_get_long_as_clob(id) as clob_val from test_tab where id < 3
- 序列
long化為 XML 并隨后反序列化為clob.
select * from xmltable( '/ROWSET/ROW' passing dbms_xmlgen.getxmltype('select * from test_tab where id < 3') columns id int, clob_val clob path 'DO_NOT_USE_LONG' )
對于此示例資料:
create table test_tab (
id int,
do_not_use_long long
);
insert into test_tab
select level, lpad(level, 10, '0')
from dual
connect by level < 3;
兩種解決方案都將回傳
| ID | CLOB_VAL |
|---|---|
| 1 | 0000000001 |
| 2 | 0000000002 |
db<>小提琴
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/522703.html
標籤:甲骨文plsql
