-2
UPDATE STG_ABS_DSD_RECEIPTS_PI_WRK1 A
SET
(
    RECEIPT_HEADER_KEY,
    ORIG_ACNTNG_EFF_DATE,
    GL_DEPT_ID,
    RECEIPT_DATE,
    RECEIPT_TIME,
    TOTAL_INVOICE_COST_HDR,
    SUM_EXTENDED_COST_AMT
) =
(SELECT
    HDR_RECEIPT_HEADER_KEY,
    HDR_ORIG_ACNTNG_EFF_DATE,
    HDR_GL_DEPT_ID,
    HDR_RECEIPT_DATE,
    HDR_RECEIPT_TIME,
    HDR_SUM_TOTAL_INVOICE_COST,
    PIEDW_EXTENDED_COST_AMT
FROM
    STG_ABS_DSD_RECEIPTS_PI_WRK4 B
WHERE
    A.SUPPLIER_KEY = B.PIEDW_SUPPLIER_KEY
AND
    A.STORE_KEY = B.PIEDW_STORE_KEY
AND
    RTRIM(LTRIM(A.SUPPLIER_INVOICE_NBR,0)) = RTRIM(LTRIM(B.PIEDW_SUPPLIER_INVOICE_NBR,0))
AND
    TO_DATE(A.PIEDW_INV_TRAN_DATE,'YYYYMMDD') = B.PIEDW_INVOICE_DATE
AND
    B.HDR_FOUND_FLAG IN ('N', 'MY'))
WHERE EXISTS
    (SELECT 1 FROM STG_ABS_DSD_RECEIPTS_PI_WRK4 B
     WHERE
         A.SUPPLIER_KEY = B.PIEDW_SUPPLIER_KEY
     AND
         A.STORE_KEY = B.PIEDW_STORE_KEY
     AND
         RTRIM(LTRIM(A.SUPPLIER_INVOICE_NBR,0)) = RTRIM(LTRIM(B.PIEDW_SUPPLIER_INVOICE_NBR,0))
     AND
         TO_DATE(A.PIEDW_INV_TRAN_DATE,'YYYYMMDD') = B.PIEDW_INVOICE_DATE
     AND
         B.HDR_FOUND_FLAG IN ('N', 'MY'));
4

1 回答 1

0

您应该确保子查询只返回您想要的行,方法是从您正在更新的表中提供正确的连接,或者如果您只想要可能返回的许多行中的一行,则使用“WHERE ROWNUM = 1”(或其他 RDBMS 或 Oracle 12c 中的 LIMIT 子句)

于 2013-09-18T08:49:10.677 回答