<insert id="acctitleWrite">
<selectKey resultType="string" keyProperty="detail_account_cd" order="BEFORE">
SELECT lpad(cast((IFNULL(MAX(cast(detail_account_cd as unsigned)),0) + 1) as char),3,'0')
FROM tb_account
where account_cd = #{bigSelect2}
</selectKey>
insert into tb_account (
account_cd
,detail_account_cd
,detail_account_nm
,note
,account_type
,use_yn
) values (
#{bigSelect2}
,#{detail_account_cd} <!-- seelctKdy의 keyProperty -->
,#{accSmall2}
,#{accContents2}
,#{payment2}
,'Y'
)
</insert>
<selectKey resultType="string" keyProperty="detail_account_cd" order="BEFORE">
SELECT lpad(cast((IFNULL(MAX(cast(detail_account_cd as unsigned)),0) + 1) as char),3,'0')
FROM tb_account
where account_cd = #{bigSelect2}
</selectKey>
resultType으로 최종반환형은 string
keyProperty에 임의로 지정해주는 값은 values에 들어갈 변수명을 지정해주는것
order="BEFORE"는 insert가 되기전 selectKey를 지정해준다는 뜻이다
먼저 SELECT구문을 순서대로 살펴보겠다