oracle 为什么我收到 ORA-01003: no statement parsed 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12252792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:27:46  来源:igfitidea点击:

Why I'm getting the ORA-01003: no statement parsed error?

oraclestored-proceduresplsql

提问by M.Octavio

Why am I getting this error and what does it mean by no statement parsed.

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

 ORA-01003: no statement parsed 

Here is the code:

这是代码:

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;

What I try to do with the code above is to update and old table with the values from a new table and in case that the new group doesn't exist insert it.

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

Update: Changed %ROWCOUNT > 0 for %ROWCOUNT = 0

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

回答by Alexander Tokarev

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.

使用 MERGE 语句,它可以更有效地更新/插入内容,并注意您的 plsql 没有提供它的用途。它尝试进行更新语句,如果找到一条记录,则插入另一条记录。为了修复它,请使用 IF (SQL%ROWCOUNT = 0) 我认为问题的原因是 . 在 DBLINK 名称中。

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.

另外一句话删除所有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)