1. 程式人生 > >GHGL用到的sql,Oracle資料庫

GHGL用到的sql,Oracle資料庫

1.union  與  union all

union 會把兩個集合中的相同項合併,union all 則不會

2.連字典表,查字典含義

		select BF.Bfdm,BF.Qybm,
		(select zdhy from gh_zd where zdlx = 'BFZT' and zddm = BF.Bfzt) as bfzt
		from 
		gh_fp_bfqd BF
		where BF.Fpdm = #{payTerm,jdbcType=VARCHAR}

3.日期型欄位轉換為字串輸出

to_char(欄位,'yyyy-MM-dd HH24:mi:ss')

4.模糊匹配  like
like '%'||#{引數名,jdbcType=VARCHAR}||'%'

5.引數傳遞

		<if test="payResult != null and payResult != '7'.toString()">
		and BF.Zfjg = #{payResult,jdbcType=VARCHAR}
		</if>

6.批量更新,注意分段提交
  <update id="updateCBbf" parameterType="map">
	update gh_fp_bfqd set sfsd = '1',sdfpdm = #{fpdm,jdbcType=VARCHAR}
	where bfdm in
	<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
		#{item.bfdm,jdbcType=VARCHAR}
	</foreach>
  </update>

7.批量插入,注意分段提交
  <insert id="buildPayForm" parameterType="java.util.List">
	insert into gh_fp_bfqd
	(BFDM,JBFDM,FPDM,JFPDM,QYBM,BFJE,FY,CZRYDM,BFZT,BFLB,CBCS,SBXH,HXMXID,JFLSDM,BZ,SFGH,LY)
	select Seq_ywls.Nextval,A.* from (   
	<foreach collection="list" item="item" index="index" separator="union all">
    select 		
    	#{item.jbfdm ,jdbcType=VARCHAR},
		#{item.fpdm ,jdbcType=VARCHAR},
		#{item.jfpdm ,jdbcType=VARCHAR},
   		#{item.qybm ,jdbcType=VARCHAR}, 
    	#{item.bfje ,jdbcType=DECIMAL}, 
    	#{item.fy ,jdbcType=VARCHAR}, 
    	#{item.czrydm ,jdbcType=VARCHAR}, 
    	#{item.bfzt ,jdbcType=VARCHAR},
    	#{item.bflb ,jdbcType=VARCHAR},
    	#{item.cbcs ,jdbcType=VARCHAR},
    	#{item.sbxh ,jdbcType=VARCHAR},
    	#{item.hxmxid ,jdbcType=VARCHAR},
    	#{item.jflsdm ,jdbcType=VARCHAR},
    	#{item.bz ,jdbcType=VARCHAR},
    	#{item.sfgh ,jdbcType=VARCHAR},
    	#{item.ly ,jdbcType=VARCHAR}
    from dual
	</foreach> 
	) A
  </insert>

8.將null值轉換為空
nvl(QY.Khmc,' ') as khmc