1

为什么我会收到此错误以及未解析语句是什么意思。

 ORA-01003: no statement parsed 

这是代码:

PROCEDURE ORIGINAL_TABLE.UPDATE_GROUPS   IS
-- cursor loaded with the swam groups
CURSOR cursor1 IS
    SELECT ID, NEW_DESCRIPTION
    FROM NEW_TABLE.NEW_GROUP_TABLE@DB_LINK.X;

BEGIN
    FOR C1_REC IN cursor1 LOOP
        UPDATE
            ORIGINAL_TABLE."GROUPS"
        SET
            GROUP_ID = C1_REC.ID
        WHERE
            ORIGINAL_TABLE."GROUPS".DESCRIPTION = C1_REC.NEW_DESCRIPTION;

        IF (SQL%ROWCOUNT = 0) THEN
           INSERT INTO
                  ORIGINAL_TABLE.GROUPS("GROUP_ID", "DESCRIPTION")
           VALUES (C1_REC.ID, C1_REC.NEW_DESCRIPTION);
        END IF;

    END LOOP;

    EXCEPTION
    WHEN OTHERS THEN
         dbms_output.put_line(SQLERRM);
END;

我尝试用上面的代码做的是用新表中的值更新旧表,如果新组不存在,请插入它。

更新:将 %ROWCOUNT > 0 更改为 %ROWCOUNT = 0

4

1 回答 1

5

Use MERGE statement, it does update/insert stuff more efficiently and pay attention your plsql doesn't provide it is intended for. It tries to make an update statement and if a record found it inserts another record. In order to fix it use IF (SQL%ROWCOUNT = 0) I presume the reason of the issue is the . in DBLINK name.

Moreover I would suggest to get rid of quotes for tables/fields just in case as well as schema name.

Another words delete all ORIGINAL_TABLE.

merge into groups g
using (
SELECT ID, NEW_DESCRIPTION
FROM NEW_TABLE.NEW_GROUP_TABLE@DB_LINK.X
) nt
on (nt.NEW_DESCRIPTION = g.description  )
when matched then update set g.group_id = nt.id
when non matched then insert(GROUP_ID, DESCRIPTION)
                      values(nt.id, nt.NEW_DESCRIPTION)
于 2012-09-03T19:18:21.333 回答