==================================== insert ==========================================
语句<insert id="insertKjtStoreOrderInfo" parameterType="com.goldenvista.kjt.entity.mapping.KjtStoreOrderInfo">
insert into KJT_STORE_ORDER_INFO
(
ORDER_ID,
ORDER_SN,
BALANCE_PAY
)
values
(
#{orderId,jdbcType=DECIMAL},
#{orderSn,jdbcType=VARCHAR},
#{balancePay,jdbcType=DECIMAL}
)
</insert>
==================================== update ==========================================
语句<update id="operModifyPassword" parameterType="java.util.Map">
update
kjt_store_opreator_info s
set
s.oper_password=#{newPassword}
where
s.oper_Id=#{operId}
</update>
==================================== select ==========================================语句1
<select id="queryKjtStoreCount" parameterType="java.util.Map" resultType="java.lang.Long">
select
count(*)
FROM
KJT_STORE_INFO S
where
s.status = ‘1‘
<if test="storeNo !=null">
and S.STORE_NO = #{storeNo}
</if>
<if test="longitude != null and latitude !=null">
AND GetDistance(#{longitude},#{latitude},S.STORE_LONGITUDE,S.STORE_LATITUDE)*1000 between 0 and 5000
</if>
</select># 自定义函数 计算经纬度距离
GetDistance(#{longitude},#{latitude},S.STORE_LONGITUDE,S.STORE_LATITUDE)create or replace
FUNCTION GetDistance(
lat1 number,
lng1 number,
lat2 number,
lng2 number)
RETURN NUMBER is
earth_padius number := 6378.137;
radLat1 number := rad(lat1);
radLat2 number := rad(lat2);
a number := radLat1 - radLat2;
b number := rad(lng1) - rad(lng2);
s number := 0;
begin
s := 2 *
Asin(Sqrt(power(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * power(sin(b / 2), 2)));
s := s * earth_padius;
s := Round(s * 10000) / 10000;
return s;
end;语句2
<!-- 分页查询 -->
<select id="queryKjtStoreList" parameterType="java.util.Map" resultType="com.goldenvista.kjt.entity.message.KjtStoreInfoModel">
SELECT * FROM (
SELECT row_.*, rownum rownum_ FROM (
SELECT
S.STORE_ID AS storeId,
S.STORE_NAME AS storeName
FROM KJT_STORE_INFO S
WHERE s.status = ‘1‘
<if test="storeNo !=null">
and S.STORE_NO = #{storeNo}
</if>
<if test="longitude != null and latitude !=null">
AND GetDistance(#{longitude},#{latitude},S.STORE_LONGITUDE,S.STORE_LATITUDE)*1000 between 0 and 5000
</if>
<if test="longitude != null and latitude !=null">
ORDER BY GetDistance(#{longitude},#{latitude},S.STORE_LONGITUDE,S.STORE_LATITUDE)*1000 ASC
</if>
<if test="longitude == null and latitude ==null">
ORDER BY S.STORE_ID desc
</if>
<![CDATA[
) row_
WHERE rownum <=#{endRecord}
)
WHERE rownum_ >#{startRecord}
]]>
</select>语句3
<!-- 查询推荐门店商品列表数目 -->
<select id="queryKjtStoreGoodsCount" parameterType="java.util.Map" resultType="java.lang.Long">
select count(*)
from KJT_STORE_GOODS_INFO g
where g.STORE_ID = #{storeId}
and (g.GOODS_NAME like ‘%‘ || #{keyword} || ‘%‘ or g.GOODS_SN like ‘%‘ || #{keyword} || ‘%‘)
</select>模糊查询
g.GOODS_NAME like ‘%‘ || #{keyword} || ‘%‘语句4
<!-- 查询包含商品集合N的所有门店 -->
<select id="queryKjtStoreListByGoods" resultType="com.goldenvista.kjt.entity.message.KjtStoreInfoModel">
select
k.STORE_ID AS storeId,
k.STORE_NAME AS storeName
from
KJT_STORE_INFO k
where k.store_id in
(
SELECT S.STORE_ID
FROM KJT_STORE_INFO S, KJT_STORE_GOODS_INFO g
WHERE S.STORE_ID = g.STORE_ID
and S.status = ‘1‘
and g.goods_id in
<foreach item="item" index="index" collection="goodsIds" open="(" separator="," close=")">
#{item}
</foreach>
)
<if test="keyword != null">
and (k.STORE_NAME like ‘%‘ || #{keyword} || ‘%‘ or k.STORE_ADDRESS like ‘%‘ || #{keyword} || ‘%‘)
</if>
</select>语句5
<select id="getStoreInfo" parameterType="java.util.Map" resultType="com.goldenvista.kjt.entity.message.StoreInfo">
SELECT
s.store_id as store_id,
s.oper_no as oper_Id,
o.store_name as storeNmae,
to_char(s.create_date,‘yyyy-MM-dd HH24:mi:ss‘)
FROM
kjt_store_opreator_info s,kjt_store_info o
WHERE
s.store_id = o.store_id
and s.status=‘1‘ and s.oper_no = #{name} and s.oper_password =#{password}
</select>TO_CHAR 是把日期或数字转换为字符串
TO_CHAR(number, ‘格式‘)
TO_CHAR(date,’格式’)例如:
TO_CHAR(salary,’$99,999.99’)
TO_CHAR(newdate,’yyyy-mm-dd’)指定字符串的长度可以使用lpad或者rpad或者substring:
lpad(字段名,填充长度,填充的字符) 左填充
rpad(字段名,填充长度,填充的字符) 右填充
substr( string, start_position, [ length ] )取得字符串中指定起始位置和长度的字符串
oracle-myibatis-整理,布布扣,bubuko.com