出现错误 ORA-06502: PL/SQL: numeric or value error
Posted
技术标签:
【中文标题】出现错误 ORA-06502: PL/SQL: numeric or value error【英文标题】:Getting error ORA-06502: PL/SQL: numeric or value error 【发布时间】:2020-02-28 06:49:07 【问题描述】:我来了
ORA-06502:PL/SQL:以下代码中的数字或值错误:
record_state := record_state || 'Inserting record Entry for student: ' ||
roll_no || ' for date: ' || To_Char(admission_date,'yyyymmdd') ||
' @ ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') || CHR(10);
以下是数据类型:
roll_no - NUMBER(10,0)
admission_date - TIMESTAMP(6)
record_state - CLOB
【问题讨论】:
您是否尝试过逐个删除表达式,直到找到有问题的表达式? 【参考方案1】:如果你有 lob 对象,我建议使用 DBMS_LOB
库。
DECLARE
record_state CLOB;
BEGIN
DBMS_LOB.CREATETEMPORARY(record_state);
-- here you should make sure that the string is not too long (max 32K), otherwise the concatenation with pipes will not work. There will be an exception.
DBMS_LOB.append (record_state , 'Inserting record Entry for student: ' || roll_no || ' for date: ' || To_Char(admission_date,'yyyymmdd') || ' @ ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') || CHR(10));
-- do more operations
dbms_lob.freetemporary(record_state);
END ;
/
【讨论】:
【参考方案2】:您需要使用to_clob
将字符串转换为clob,然后您可以连接两个clob,如下所示:
record_state := record_state ||
to_clob(
'Inserting record Entry for student: ' || roll_no || ' for date: ' || To_Char(admission_date,'yyyymmdd') || ' @ ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') || CHR(10)
);
干杯!!
【讨论】:
以上是关于出现错误 ORA-06502: PL/SQL: numeric or value error的主要内容,如果未能解决你的问题,请参考以下文章
ORA-06502 PL/SQL:数字或值错误:字符到数字的转换错误;