我可以这样写吗?

时间:2019-01-09 06:56:53

标签: plsql

我当时想在满足特定条件时更新表,但是我没有写方法。请帮我

C_RXCLMS_SLCGT99是光标

BEGIN

FOR R_RXCLMS_SLCGT99 IN C_RXCLMS_SLCGT99 LOOP

IF SEQ_NUMBER_CLAIM = (select min(SEQ_NUMBER_CLAIM) from 

VENDORDB.ARC_RXSOL_CLAIM where RX_CLAIM_NUMBER = 

R_RXCLMS_SLCGT99.RX_CLAIM_NUMBER)

THEN                     

UPDATE VENDORDB.ARC_RXSOL_CLAIM
SET HIDDEN_USER_DEF_2 = NULL
WHERE STATE = R_RXCLMS_SLCGT99.STATE
AND TYPE_OF_CLAIM = R_RXCLMS_SLCGT99.TYPE_OF_CLAIM
AND RX_CLAIM_NUMBER = R_RXCLMS_SLCGT99.RX_CLAIM_NUMBER
AND BATCH_ID = R_RXCLMS_SLCGT99.BATCH_ID
AND HIDDEN_USER_DEF_2 IS NULL;
END IF

DBMS_OUTPUT.PUT_LINE('HIDDEN_USER_DEF_2 UPDATED FOR: ' || SQL%ROWCOUNT);
END LOOP;

如果条件满足,我希望HIDDEN_USER_DEF_2为NULL。

1 个答案:

答案 0 :(得分:0)

请在下面尝试。谢谢。

BEGIN

    FOR R_RXCLMS_SLCGT99 IN C_RXCLMS_SLCGT99 LOOP

        UPDATE VENDORDB.ARC_RXSOL_CLAIM
        SET HIDDEN_USER_DEF_2 = NULL
        WHERE STATE = R_RXCLMS_SLCGT99.STATE
        AND TYPE_OF_CLAIM = R_RXCLMS_SLCGT99.TYPE_OF_CLAIM
        AND RX_CLAIM_NUMBER = R_RXCLMS_SLCGT99.RX_CLAIM_NUMBER
        AND BATCH_ID = R_RXCLMS_SLCGT99.BATCH_ID
        AND HIDDEN_USER_DEF_2 IS NULL
        AND SEQ_NUMBER_CLAIM IN (select min(SEQ_NUMBER_CLAIM) 
                                   from VENDORDB.ARC_RXSOL_CLAIM 
                                  where RX_CLAIM_NUMBER = R_RXCLMS_SLCGT99.RX_CLAIM_NUMBER);

    DBMS_OUTPUT.PUT_LINE('HIDDEN_USER_DEF_2 UPDATED FOR: ' || SQL%ROWCOUNT);

    END LOOP;

END;