oracle 下面的查询有什么问题以及如何更正

5t7ly7z5  于 2023-10-16  发布在  Oracle
关注(0)|答案(1)|浏览(159)

下面的oracle查询给出了一个语法错误。我无法纠正它。假设表名、列和相应的值都是正确的,那么语法中有什么错误呢?

MERGE INTO AI_IMAGE_EVENT AIE
USING AI_PRODUCT_IMAGE API
    ON API.IMAGE_ID = '172c86a216304dbwks02'
    AND API.ZONE = '03'
WHEN MATCHED THEN
    INSERT (AI_IMAGE_EVENT_SQID,
    AI_PRODUCT_IMAGE_SQID,
    AI_EVENT_TYPE,
    AI_PROC_START_TIME,
    AI_PROC_END_TIME,
    AI_IMAGE_SERV_TIME,
    FACILITY_ID,
    ZONE,
    CREATED_DATE,
    CREATED_BY,
    LAST_UPDATED_DATE,
    LAST_UPDATED_BY)
    VALUES('910000008201', API.AI_PRODUCT_IMAGE_SQID, 2, SYSDATE, SYSDATE, null, '68731', 10, SYSDATE, '68731', SYSDATE, '68731')

这就是我得到的错误。
命令行错误:9列:9错误报告- SQL错误:ORA-00969:缺少ON关键字00969。00000 -“缺少ON关键字”* 原因:

  • 行动:
    我在sql developer中运行了上面的代码。
ldioqlga

ldioqlga1#

有几个问题:

  • ON子句需要括号(尽管该消息没有帮助);
  • BY API是假的,应该是WHEN MATCHED THEN;
  • 你正在做一个插入而不是更新,所以它应该是WHEN NOT MATCHED THEN

所以:

MERGE INTO AI_IMAGE_EVENT AIE
USING AI_PRODUCT_IMAGE API
    ON (API.IMAGE_ID = '172c86a216304dbwks02' AND API.ZONE = '03')
WHEN NOT MATCHED THEN
    INSERT (AI_IMAGE_EVENT_SQID,
...

db<>fiddle显示各种错误。(最后一个版本仍然错误,与ORA-00942,因为我没有你的表.)
我需要在源表中匹配时插入。如果该行存在于源表中,我需要插入到目标表中。
合并系统不允许这样做。
您可能正在寻找INSERT ... SELECT ...,类似于:

INSERT INTO AI_IMAGE_EVENT (
    AI_IMAGE_EVENT_SQID,
    AI_PRODUCT_IMAGE_SQID,
    AI_EVENT_TYPE,
    AI_PROC_START_TIME,
    AI_PROC_END_TIME,
    AI_IMAGE_SERV_TIME,
    FACILITY_ID,
    ZONE,
    CREATED_DATE,
    CREATED_BY,
    LAST_UPDATED_DATE,
    LAST_UPDATED_BY
)
SELECT '910000008201', API.AI_PRODUCT_IMAGE_SQID, 2, SYSDATE, SYSDATE, null,
    '68731', 10, SYSDATE, '68731', SYSDATE, '68731'
FROM AI_PRODUCT_IMAGE API
WHERE API.IMAGE_ID = '172c86a216304dbwks02'
AND API.ZONE = '03'

相关问题