Ibatis insert語句中包含子查詢問題

insert語句中包含子查詢問題

Ibatis中的Insert語句,將values採用select代替

<insert id="insertFaqContinue">
        INSERT INTO FAQ ( 
        <dynamic prepend="">
            <isNotNull prepend="," property="topicID"> topicID </isNotNull>
            <isNotNull prepend="," property="listID"> listID </isNotNull>
            <isNotNull prepend="," property="topicID"> faqfloor </isNotNull>
        </dynamic>
        )
        SELECT 
        <dynamic prepend="">
            <isNotNull prepend="," property="topicID"> #topicID# </isNotNull>
            <isNotNull prepend="," property="listID"> #listID# </isNotNull>
            <isNotNull prepend="," property="title"> #title# </isNotNull>
            <isNotNull prepend="," property="topicID"> (SELECT count(faqID)+1 FROM FAQ WHERE topicID = #topicID#) </isNotNull>
        </dynamic>
        
        <selectKey resultClass="int" keyProperty="faqID" >
            SELECT @@IDENTITY AS faqID
        </selectKey>
    </insert>


分析:整體結構爲Insert into select 語句,select 語句中包含子查詢

 

<insert id="insertSubjectRelDemand" parameterClass="subjectreldemand">
    insert into dsp_subject_reldemand (no,subject_no,demand_no,version)
     select dsp_subject_reldemand_seq.nextval,#subject_no#,#demand_no#,(select version from dsp_subject where no = #subject_no#) from dual
 </insert>

<!-- 插入一條歷史編輯內容 -->
 <insert id="insertSubjectHistory" parameterClass="subjectHistory">
    insert into dsp_hstry (sub_no,editer_no,edit_date,descr,sqls,caliber,clasy,version,edit_des)
    (select no,cre_no,edit_date,descr,sqls,caliber,clasy,version,cre_des as edit_des from dsp_subject where no = #no#)
 </insert>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章