Total Pageviews

2014/02/27

Oracle: how to do insert if data doesn't exist

Here is my database schema:

Requirement
If we cannot find data via ROC_YM, primary key, in FMS415FA, then it should insert specific ROC_YM data into this table

How to do to fulfill this requirement
INSERT INTO FMS451FA(ROC_YM)
SELECT :ROC_YM
FROM dual
WHERE NOT EXISTS
    (SELECT ROC_YM
     FROM FMS451FA
     WHERE ROC_YM = :ROC_YM)

No comments: