使用CLOB给出了ORA-06502:PL / SQL:数值或值错误

时间:2018-04-18 18:34:01

标签: oracle plsql clob

下面的代码引发了一个错误:" ORA-06502:PL / SQL:数字或值错误 ORA-06512:第24行"。

DECLARE 
v_clob CLOB;
CURSOR cur_a
IS
SELECT
device_num,
Account_number,
CustomerName,
Prem_address ,
      contact_phone ,
      W_status ,
      A_status ,
      "12-1 AM" Twelve21,
      "1-2 AM" One22,
      "2-3 AM" Two23,
      "3-4 AM" Three24,
      CIn4Hrs
    FROM account a
    WHERE 1 =1 ;
BEGIN
  DBMS_LOB.CreateTemporary( v_clob, true );
  FOR rec IN cur_a
  LOOP
    v_clob := v_clob ||rec.device_num|| ',' ||rec.Account_number|| ',' ||rec.contact_phone || ',' ||rec.W_status|| ',' ||rec.A_status|| ',' ||rec.Twelve21|| ',' ||rec.One22|| ',' ||rec.Two23|| ',' ||rec.Three24|| ',' ||rec.CIn4Hrs|| ',' ||SUBSTR(rec.CustomerName,1,15)|| ',' ||SUBSTR(rec.Prem_address,1,15) || UTL_TCP.crlf;
  END LOOP;
END; 

1 个答案:

答案 0 :(得分:0)

您不能使用字符串连接运算符||附加到clob。 VARCHAR2(记录字段的默认类型)最大为32K。 clob的大小超过了它。你需要包装 每个元素都带有to_clob函数,例如:

v_clob || to_clob(rec.device_num) || ',' || to_clob(rec.Account_number)