2011년 10월 6일 목요일

데이타가 있으면 update, 없으면 insert

  
MERGE INTO TB_EDU_TEST_SUBMIT TA
     USING DUAL
     ON (
               TA.CRCL_NO = :crcl_no
              AND TA.YEAR = :year
              AND TA.TERM = :term
              AND TA.USER_ID = :user_id
              AND TA.TEST_NO = :test_no
                      )
     WHEN MATCHED THEN
     UPDATE SET LIMIT_MIN=:limit_min, LIMIT_SEC=:limit_sec, TEST_DATE=:test_date, TEST_SCORE=:test_score
     WHEN NOT MATCHED THEN
     INSERT ( CRCL_NO, YEAR, TERM, USER_ID, TEST_NO, LIMIT_MIN, LIMIT_SEC, TEST_DATE, TEST_SCORE )
     VALUES ( :crcl_no, :year, :term, :user_id, :test_no, :limit_min, :limit_sec, TO_CHAR(SYSDATE, 'YYYYMMDD'), :test_score )

댓글 없음:

댓글 쓰기