Mybatis的oracle的经典SQL语句(分页-新增的id自增-批量新增-动态修改-union all)
分页:
新增的id自增
批量新增:
修改动态sql:
union all连接三张不同表格不同搜索条件获取三行相同类型的数据
分页:
<!-- 获取维权信息 -->
<select id="getAdviceList" resultMap="adviceRVO">
select *
from (select t.*,rownum rn
from (select id,
trueName,
createDate
from t_sp_advice
where delflag = '0' and STORE_ID=#{store_id}
<if test="status != null and status != ''">
and status = #{status}
</if>
<if test="content !=null and content != ''">
and content like '%'||#{content}||'%'
</if>
<if test="startDate != null and startDate != ''">
and createdate >= to_date(#{startDate},'yyyy-MM-dd')
</if>
<if test="endDate != null and endDate != ''">
and createdate <= to_date(#{endDate},'yyyy-MM-dd')
</if>
order by status,createdate desc) t
where rownum <=#{page}*#{count}) t1
where t1.rn >(#{page}-1)*#{count}
</select>
新增的id自增
<!-- 新增轮播图信息 -->
<insert id="addBanner" parameterMap="bannerDto">
<selectKey keyProperty="id" resultType="int" order="BEFORE">
SELECT
SEQ_T_SP_BANNER.NEXTVAL id FROM DUAL
</selectKey>
INSERT INTO T_SP_BANNER(
id,
banner_name,
createdate,
)
VALUES(
#{id},
#{banner_name},
sysdate
</insert>
批量新增:
<!-- 批量新增热门目的地 -->
<insert id="addDestination" parameterType="java.util.List">
INSERT INTO t_sp_hot_county t
(t.id,
t.county_name,
t.createDate
)
SELECT seq_t_sp_hot_county.NEXTVAL id, A.*
FROM(
<foreach collection="list" item="item" index="index"
separator="UNION ALL">
SELECT
#{item.county_name},
sysdate createDate
FROM dual
</foreach>
)A
</insert>
修改动态sql:
<!-- 修改密码或者角色-->
<update id="updateManager">
update T_SP_SYSUSER
<set>
<if test="password != null and password != ''">
password=#{password},
</if>
<if test="role_id != null and role_id != ''">
role_id=#{role_id}
</if>
</set>
where id=#{id}
and delflag = '0'
</update>
union all连接三张不同表格不同搜索条件获取三行相同类型的数据
<!-- 获取总金额 -->
<select id="getAllData" resultMap="orderSumRVO">
select '景点' tableName, sum(p.totalprice) totalPrice
from t_poi_orderrecord p
where p.delflag = '0'
and p.sp_store_id=#{store_id}
and p.orderdate >= to_date(#{startDate},'yyyy-mm-dd')
and p.poiType=1
union all
select '酒店' tableName, sum(p.totalprice) totalPrice
from t_poi_orderrecord p
where p.delflag = '0'
and p.sp_store_id=#{store_id}
and p.orderdate >= to_date(#{startDate},'yyyy-mm-dd')
and p.poiType=5
union all
select '线路' tableName,sum(f.totalprice) totalPrice
from t_f1_order f
where f.delflag = '0'
and f.sp_store_id=#{store_id}
and f.createdate >= to_date(#{startDate},'yyyy-mm-dd')
</select>