본문 바로가기
Engineering WIKI/Database

[Oracle] selectKey 사용

by wonos 2020. 11. 29.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="Product">
        
<insert id="insertProduct-Oracle" parameterClass="com.domain.Product">
   
    INSERT INTO PRODUCT(PRD_ID, PRD_DESCRIPTION)
    VALUES(STOCKIDSEQUENCE.NEXTVAL, #description#)
    
</insert>
    
</sqlMap>

 

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="Product">
        
<insert id="insertProduct-Oracle" parameterClass="com.domain.Product">
   <selectKey keyProperty="id" resultClass="int">
       SELECT STOCKIDSEQUENCE.NEXTVAL AS ID FROM DUAL
   </selectKey>

    INSERT INTO PRODUCT(PRD_ID, PRD_DESCRIPTION)
    VALUES(#id#, #description#)
    
</insert>
    
</sqlMap>

 

 

 

출처 : hyeonstorage.tistory.com/280