我收到错误消息,提示字符串连接结果太长

问题描述 投票:0回答:1

我正在尝试将数据插入到值超过 4000 个字符的表中,为了克服这个问题,我在 zzz_drop_result_718001 上创建了列 qcnotes 数据类型 clob,但我无法完成它。

DECLARE 
    GRPNM VARCHAR2(100); 
    CLOBNOTES CLOB;
BEGIN 
    DELETE ZZZ_DROP_RESULT_718001;
    COMMIT;
    FOR REC IN (SELECT * FROM zzz_vw_recentdrop) 
    LOOP
    BEGIN
        IF REC.NOTELENGTH <= 3999 THEN      
            INSERT INTO ZZZ_DROP_RESULT_718001 (
                loggeddate, category, groupname, payer, datatype, qcnotes, ATTACHMENT, QCCONCERN
            ) VALUES (
                REC.LOGGEDDATE, REC.CATEGORY, REC.GROUPNAME, REC.PAYER, NULL, REC.QCNOTES, REC.ATTATCHMENT, REC.QCCONCERN
            );
            commit;
        ELSIF length(substr(rec.qcnotes,4000,rec.notelength))<=3999 then 
            Dbms_Output.PUT_LINE('Note length too long: ' || REC.GROUPNAME);
            
            clobnotes:=substr(rec.qcnotes,4000,rec.notelength);
            --CLOBNOTES := EMPTY_CLOB();
            --DBMS_LOB.CREATETEMPORARY(CLOBNOTES, TRUE);
            --DBMS_LOB.WRITEAPPEND(CLOBNOTES, LENGTH(REC.QCNOTES), REC.QCNOTES);
            
            GRPNM := REC.GROUPNAME;
            INSERT INTO ZZZ_DROP_RESULT_718001 (
                loggeddate, category, groupname, payer, datatype, qcnotes, ATTACHMENT, QCCONCERN
            ) VALUES (
                REC.LOGGEDDATE, REC.CATEGORY, REC.GROUPNAME, REC.PAYER, NULL, CLOBNOTES, REC.ATTATCHMENT, REC.QCCONCERN
            );
            COMMIT;
            update ZZZ_DROP_RESULT_718001 set qcnotes=qcnotes||clobnotes where groupname=grpnm;
            commit;
        END IF;
        EXCEPTION WHEN OTHERS THEN Dbms_Output.PUT_LINE('Note length too long: ' || REC.GROUPNAME);
    end;
    END LOOP;
END;```

got error:
`Error report -
ORA-01489: result of string concatenation is too long
ORA-06512: at line 7
ORA-06512: at line 7
01489. 00000 -  "result of string concatenation is too long"
*Cause:    String concatenation result is more than the maximum size.
*Action:   Make sure that the result is less than the maximum size.`
i want to insert data with more than 4000 character, i tried using substr and break and insert but it is not working. I have tried using dbms_lob,xmlagg
sql oracle plsql
1个回答
0
投票

尝试使用循环似乎使事情过于复杂,并且可以简单地使用单个

INSERT ... SELECT ...
语句:

BEGIN 
  EXECUTE IMMEDIATE 'TRUNCATE TABLE ZZZ_DROP_RESULT_718001';

  INSERT INTO ZZZ_DROP_RESULT_718001 (
    loggeddate, category, groupname, payer, datatype, qcnotes, ATTACHMENT, QCCONCERN
  )
  SELECT LOGGEDDATE, CATEGORY, GROUPNAME, PAYER, NULL, QCNOTES, ATTACHMENT, QCCONCERN
  FROM   zzz_vw_recentdrop;

  COMMIT;
END;
/

小提琴

© www.soinside.com 2019 - 2024. All rights reserved.