PLS-00103:遇到错误时遇到符号“文件结尾”

时间:2018-11-02 17:09:07

标签: oracle plsql

我不是数据库管理员,我正在尝试运行提供给我的SQL脚本,这将引发以下错误。有人可以让我知道如何解决它。预先感谢

[6550] ORA-06550: line 27, column 10:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the 
following:

   begin function pragma procedure

我正在Oracle v12.1上运行它,如果您需要任何其他信息,请告诉我。

此外,我尝试在v12.2实例上执行相同的操作,但仍然收到相同的错误。

这是我正在执行的SQL

DECLARE 
   type ah_cursor IS REF CURSOR;
   ah_cur ah_cursor;
   ah_unmatched_cur ah_cursor;
   PROCEDURE insertAHFromCursor(cur IN ah_cursor) 
        IS 
        type ah_row is record("ISSUE_ID" NUMBER(38,0),
        "SEQNUMBER" NUMBER(38,0),
        "ATTRGUID" VARCHAR2(255 BYTE),
        "AUDITTIME" NUMBER(19,0),
        "PROJECTVERSION_ID" NUMBER(38,0),
        "USERNAME" VARCHAR2(255 BYTE),
        "CONFLICT" CHAR(1 BYTE) DEFAULT 'N',
        "OLDVALUE" VARCHAR2(500 BYTE),
        "NEWVALUE" VARCHAR2(500 BYTE));
        type TObjectTable is table of ah_row;
        ObjectTable$ TObjectTable;
      BEGIN
        LOOP
        fetch cur BULK COLLECT INTO ObjectTable$ LIMIT 1000;
        EXIT WHEN ObjectTable$.COUNT < 1;
        forall x in ObjectTable$.First..ObjectTable$.Last
        insert into audithistory(issue_id, seqNumber, attrGuid, auditTime, projectVersion_id, userName, conflict, oldValue, newValue)
        values (ObjectTable$(x).issue_id, ObjectTable$(x).seqNumber, ObjectTable$(x).attrGuid, ObjectTable$(x).auditTime, ObjectTable$(x).projectVersion_id, ObjectTable$(x).userName,  ObjectTable$(x).conflict, ObjectTable$(x).oldValue, ObjectTable$(x).newValue);
        commit;
        END LOOP;
      END;

      BEGIN
        OPEN ah_cur FOR
          SELECT aho.issue_id issue_id, aho.seqNumber seqNumber, aho.attrGuid attrGuid, aho.auditTime auditTime, 
            aho.projectVersion_id projectVersion_id, aho.userName userName, aho.conflict conflict,
            (CASE WHEN aho.oldValue IS NULL THEN 'NULL'
                WHEN alOld.lookupValue IS NULL THEN CAST(aho.oldValue as varchar2(500))
                ELSE CAST(alOld.lookupValue as varchar2(500)) END) oldValue,
            (CASE WHEN aho.newValue IS NULL THEN 'NULL'
                WHEN alNew.lookupValue IS NULL THEN CAST(aho.newValue as varchar2(500))
                ELSE CAST(alNew.lookupValue as varchar2(500)) END) newValue
        FROM audithistory_old aho
            INNER JOIN attr a ON aho.attrGuid = a.guid
            LEFT JOIN attrlookup alNew ON alNew.attrGuid = aho.attrGuid AND aho.newValue = alNew.lookupIndex
            LEFT JOIN attrlookup alOld ON alOld.attrGuid = aho.attrGuid AND aho.oldValue = alOld.lookupIndex
        WHERE a.attrType = 'CUSTOM'   
    insertAHFromCursor(ah_cur);
    close ah_cur;
    open ah_unmatched_cur for
        SELECT aho.issue_id issue_id, aho.seqNumber seqNumber, aho.attrGuid attrGuid, aho.auditTime auditTime, 
            aho.projectVersion_id projectVersion_id, aho.userName userName, aho.conflict conflict,
            (CASE WHEN aho.oldValue IS NULL THEN NULL ELSE CAST(aho.oldValue AS varchar2(500)) END) oldValue,
            (CASE WHEN aho.newValue IS NULL THEN NULL ELSE CAST(aho.newValue AS varchar2(500)) END) newValue
        FROM audithistory_old aho 
        WHERE NOT EXISTS (SELECT 1 
            FROM audithistory ah 
            WHERE aho.issue_id = ah.issue_id AND aho.seqNumber = ah.seqNumber);
     insertAHFromCursor(ah_unmatched_cur);
    close ah_unmatched_cur;
END;
/

1 个答案:

答案 0 :(得分:0)

我希望您有过程insertAHFromCursor,它应该首先在数据库中编译,然后在块内使用该过程

步骤:1

 PROCEDURE insertAHFromCursor(cur IN ah_cursor) 
        IS 
        type ah_row is record("ISSUE_ID" NUMBER(38,0),
        "SEQNUMBER" NUMBER(38,0),
        "ATTRGUID" VARCHAR2(255 BYTE),
        "AUDITTIME" NUMBER(19,0),
        "PROJECTVERSION_ID" NUMBER(38,0),
        "USERNAME" VARCHAR2(255 BYTE),
        "CONFLICT" CHAR(1 BYTE) DEFAULT 'N',
        "OLDVALUE" VARCHAR2(500 BYTE),
        "NEWVALUE" VARCHAR2(500 BYTE));
        type TObjectTable is table of ah_row;
        ObjectTable$ TObjectTable;
      BEGIN
        LOOP
        fetch cur BULK COLLECT INTO ObjectTable$ LIMIT 1000;
        EXIT WHEN ObjectTable$.COUNT < 1;
        forall x in ObjectTable$.First..ObjectTable$.Last
        insert into audithistory(issue_id, seqNumber, attrGuid, auditTime, projectVersion_id, userName, conflict, oldValue, newValue)
        values (ObjectTable$(x).issue_id, ObjectTable$(x).seqNumber, ObjectTable$(x).attrGuid, ObjectTable$(x).auditTime, ObjectTable$(x).projectVersion_id, ObjectTable$(x).userName,  ObjectTable$(x).conflict, ObjectTable$(x).oldValue, ObjectTable$(x).newValue);
        commit;
        END LOOP;
      END;

第2步:

DECLARE 
   type ah_cursor IS REF CURSOR;
   ah_cur ah_cursor;
   ah_unmatched_cur ah_cursor;

      BEGIN
        OPEN ah_cur FOR
          SELECT aho.issue_id issue_id, aho.seqNumber seqNumber, aho.attrGuid attrGuid, aho.auditTime auditTime, 
            aho.projectVersion_id projectVersion_id, aho.userName userName, aho.conflict conflict,
            (CASE WHEN aho.oldValue IS NULL THEN 'NULL'
                WHEN alOld.lookupValue IS NULL THEN CAST(aho.oldValue as varchar2(500))
                ELSE CAST(alOld.lookupValue as varchar2(500)) END) oldValue,
            (CASE WHEN aho.newValue IS NULL THEN 'NULL'
                WHEN alNew.lookupValue IS NULL THEN CAST(aho.newValue as varchar2(500))
                ELSE CAST(alNew.lookupValue as varchar2(500)) END) newValue
        FROM audithistory_old aho
            INNER JOIN attr a ON aho.attrGuid = a.guid
            LEFT JOIN attrlookup alNew ON alNew.attrGuid = aho.attrGuid AND aho.newValue = alNew.lookupIndex
            LEFT JOIN attrlookup alOld ON alOld.attrGuid = aho.attrGuid AND aho.oldValue = alOld.lookupIndex
        WHERE a.attrType = 'CUSTOM'   
    insertAHFromCursor(ah_cur);
    close ah_cur;
    open ah_unmatched_cur for
        SELECT aho.issue_id issue_id, aho.seqNumber seqNumber, aho.attrGuid attrGuid, aho.auditTime auditTime, 
            aho.projectVersion_id projectVersion_id, aho.userName userName, aho.conflict conflict,
            (CASE WHEN aho.oldValue IS NULL THEN NULL ELSE CAST(aho.oldValue AS varchar2(500)) END) oldValue,
            (CASE WHEN aho.newValue IS NULL THEN NULL ELSE CAST(aho.newValue AS varchar2(500)) END) newValue
        FROM audithistory_old aho 
        WHERE NOT EXISTS (SELECT 1 
            FROM audithistory ah 
            WHERE aho.issue_id = ah.issue_id AND aho.seqNumber = ah.seqNumber);
     insertAHFromCursor(ah_unmatched_cur);
    close ah_unmatched_cur;
END;