개발/데이터베이스

[Oracle] mybatis sequence 값 return 받기

JaeHoist 2022. 12. 27. 15:42

selectKey 활용

<insert id="insertFTETemplate" parameterType="kr.co.crscube.ctms.model.manage.FTETemplate" useGeneratedKeys="true" keyProperty="templateKey">
        <selectKey keyProperty="templateKey" resultType="int" order="BEFORE">
            SELECT SEQ_SPO_TMPL_KEY.NEXTVAL FROM DUAL
        </selectKey>
 
        INSERT
          INTO SPO_FTE_TMPL
        VALUES (#{templateKey}, #{sponsorKey}, #{templateName}, #{description}, #{reason}, 'N', SYSDATE, #{userKey})
    </insert>

parmeterType을 지정해 주지 않으면 계속 1 반환

parmeterType의 keyProperty 변수에 값 받는다.