Question : Oracle query

The following query is throwing me a syntax error :

SQL>
SQL> /
           NULL;
           *
ERROR at line 16:
ORA-00905: missing keyword
MERGE INTO EWT_CLM_COV_TYPE_DIM   c
USING (select distinct b.C_CODE1,
                                  a.CCN_NG_CLAIM_COV_CD,
                                  a.CCN_LEG_CLAIM_COV_CD
                                  From
                                      TESTUC.KGT_SDM_CLAIM_COV_NG a,
            CODE_RELATIONS b,
            EWT_CLM_COV_TYPE_DIM c
                     where a.CCN_NG_CLAIM_COV_CD = b.C_CODE2
                           and b.C_CATEGORY1 = 881
                                          and b.C_CATEGORY2 = 20  ) e
           ON     (e.C_CODE1 = c.P10_CLM_COV_GRP_CD
                      and e.CCN_NG_CLAIM_COV_CD = c.p10_CLM_COV_TYPE_CD
                      and e.CCN_LEG_CLAIM_COV_CD = c.p10_LEG_CLM_COV_TYPE_CD)
           when MATCHED then
           NULL;
           WHEN NOT MATCHED
           THEN  INSERT (p10_cov_type_id,P10_CLM_COV_TYPE_CD,
           P10_LEG_CLM_COV_TYPE_CD,P10_ATOMIC_TS,P10_CLM_COV_GRP_CD)
           VALUES
           (select max(p10_cov_type_id)+1 from EWT_CLM_COV_TYPE_DIM, e.CCN_NG_CLAIM_COV_CD,
             e.CCN_LEG_CLAIM_COV_CD,systimestamp, e.C_CODE1);

Kindly help me resolve that.

Answer : Oracle query

I think you have two options:
1. Use "merge" but then you need the full syntax for "merge" which expects an update clause and an insert clause.  You may be able to use a "where" clause in the update so it doesn't actually do anything.

2. Use a PL\SQL procedure with a cursor loop to fetch each row, then check if it already exists, or not, in the destination table.  If yes, do nothing, if not, do an insert.  (This will be faster than trying an insert in all cases, but catching duplicates via a unique or primary key violation exception.)
Random Solutions  
 
programming4us programming4us