获取错误 ORA-06502: PL/SQL: 数字或值错误

Getting error ORA-06502: PL/SQL: numeric or value error

我得到

ORA-06502: PL/SQL: numeric or value error in below code:

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

您需要使用 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)
                       );

干杯!!

如果你有 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 ;
/