所有用 str1||str2 拼接的字符串都要改成CONCAT(str1,str2)
'%'||#{zbmc}||'%'
改成CONCAT('%',#{zbmc},'%')
a.fpdm||'-'||a.fphm
改成CONCAT(a.fpdm,'-',a.fphm)
Oracle中concat与||区别(以及与mysql中concat函数区别)
oracle中的ROWNUM
SELECT * FROM (SELECT ROWNUM rn,a.* from ( SELECT
A.* from FX_PZ A
) a where ROWNUM<=#{endRow} ) WHERE rn>#{startRow} order by ${sort} ${order}
改成
SELECT A.* from FX_PZ A
order by ${sort} ${order} limit #{startRow},#{rows}
注意limt关键字是最后才用到的。以下条件的出现顺序一般是:where->group by->having-order by->limit
Oracle与Mysql的分页比较
MySQL的Limit详解
to_date(#{kprqs},'yyyy-MM-dd')
改成 str_to_date(#{kprqs},'%Y-%m-%d')
to_char(kprq,'yyyy-MM')
改成date_format(kprq,'%Y-%m')
to_char(kprq,'q')
改成 FLOOR((date_format(kprq, '%m')+2)/3))
mysql和oracle中的to_date()/to_char()互换
Oracle中的时间函数用法(to_date、to_char) (总结)
nvl(sum(a.je),0)
改成ifnull(sum(a.je),0)
nvl、ifnull 用法(将null转代为0)
decode(trim(s.fpzt),'0','正常','2','作废','3','红冲','')
改成
( case trim(s.fpzt)
when '0' then '正常'
when '2' then '作废'
when '3' then '红冲'
else '' end
)
decode(sum(sl), null, 0.00, sum(sl)) as sl,
改成
IFNULL(SUM(sl),0.00)
或者( case when sum(je) is null then 0.00 else sum(je) end)
oracle/MySQL 中的decode的使用
substr(kprq,0,8)
改成 substr(kprq,1,8)
mysql函数substr 注意脚标从1开始
Oracle中的substr()函数 详解及应用
to_number(b.field1)
改成 cast(b.field1 as unsigned int)
select cast(11 as unsigned int) /整型/
select cast(11 as decimal(10,2)) /浮点型/
Mybatis批量新增或更新(mysql数据库)
MERGE INTO TAB_FLBM A
USING
(select
#{item.ssflbm,jdbcType=VARCHAR},
#{item.bb,jdbcType=VARCHAR},
#{item.qysj,jdbcType=VARCHAR},
#{item.gdqjzsj,jdbcType=VARCHAR}, #{item.spbm,jdbcType=VARCHAR},
#{item.spmc,jdbcType=VARCHAR},
#{item.sm,jdbcType=VARCHAR},
#{item.zzssl,jdbcType=VARCHAR},
#{item.gjz,jdbcType=VARCHAR},
#{item.hzx,jdbcType=CHAR},
#{item.kyzt,jdbcType=CHAR},
#{item.zzstsgl,jdbcType=VARCHAR},
#{item.zzszcyj,jdbcType=VARCHAR},
#{item.zzstsnrdm,jdbcType=VARCHAR}, #{item.xfsgl,jdbcType=VARCHAR},
#{item.xfszcyj,jdbcType=VARCHAR},
#{item.xfstsnrdm,jdbcType=VARCHAR},
#{item.tjjbm,jdbcType=VARCHAR},
#{item.pid,jdbcType=VARCHAR},
#{item.gxsj,jdbcType=VARCHAR}, #{item.bbh,jdbcType=VARCHAR},
#{item.spbmjc,jdbcType=VARCHAR},
#{item.hgjcksppm,jdbcType=CLOB} from
dual) b
on (a.ssflbm=b.ssflbm)
when matched then
update set a.BB = b.BB,
a.QYSJ = b.QYSJ,
a.GDQJZSJ = b.GDQJZSJ,
a.SPBM = b.SPBM,
a.SPMC = b.SPMC,
a.SM = b.SM,
a.ZZSSL = b.ZZSSL,
a.GJZ = b.GJZ,
a.HZX = b.HZX,
a.KYZT = b.KYZT,
a.ZZSTSGL = b.ZZSTSGL,
a.ZZSZCYJ = b.ZZSZCYJ,
a.ZZSTSNRDM = b.ZZSTSNRDM,
a.XFSGL = b.XFSGL,
a.XFSZCYJ = b.XFSZCYJ,
a.XFSTSNRDM = b.XFSTSNRDM,
a.TJJBM = b.TJJBM,
a.PID = b.PID,
a.GXSJ = b.GXSJ,
a.BBH = b.BBH,
a.SPBMJC = b.SPBMJC
when
not matched then
insert into TAB_FLBM (SSFLBM, BB, QYSJ,
GDQJZSJ, SPBM,
SPMC,
SM, ZZSSL, GJZ, HZX,
KYZT, ZZSTSGL, ZZSZCYJ,
ZZSTSNRDM, XFSGL,
XFSZCYJ,
XFSTSNRDM, TJJBM, PID,
GXSJ, BBH, SPBMJC)
values
(b.ssflbm, b.bb,
b.qysj,
b.gdqjzsj, b.spbm, b.spmc,
b.sm, b.zzssl,
b.gjz,
b.hzx,jdbcType=CHAR},
b.kyzt,jdbcType=CHAR}, b.zzstsgl,
b.zzszcyj,
b.zzstsnrdm, b.xfsgl, b.xfszcyj,
b.xfstsnrdm, b.tjjbm,
b.pid,
b.gxsj,
b.bbh, b.spbmjc)
改成
insert into TAB_FLBM
(SSFLBM, BB, QYSJ,
GDQJZSJ, SPBM,
SPMC,
SM, ZZSSL, GJZ, HZX,
KYZT, ZZSTSGL, ZZSZCYJ,
ZZSTSNRDM, XFSGL,
XFSZCYJ,
XFSTSNRDM, TJJBM, PID,
GXSJ, BBH, SPBMJC)
values
(
#{item.ssflbm,jdbcType=VARCHAR},
#{item.bb,jdbcType=VARCHAR},
#{item.qysj,jdbcType=VARCHAR},
#{item.gdqjzsj,jdbcType=VARCHAR}, #{item.spbm,jdbcType=VARCHAR},
#{item.spmc,jdbcType=VARCHAR},
#{item.sm,jdbcType=VARCHAR},
#{item.zzssl,jdbcType=VARCHAR},
#{item.gjz,jdbcType=VARCHAR},
#{item.hzx,jdbcType=CHAR},
#{item.kyzt,jdbcType=CHAR},
#{item.zzstsgl,jdbcType=VARCHAR},
#{item.zzszcyj,jdbcType=VARCHAR},
#{item.zzstsnrdm,jdbcType=VARCHAR}, #{item.xfsgl,jdbcType=VARCHAR},
#{item.xfszcyj,jdbcType=VARCHAR},
#{item.xfstsnrdm,jdbcType=VARCHAR},
#{item.tjjbm,jdbcType=VARCHAR},
#{item.pid,jdbcType=VARCHAR},
#{item.gxsj,jdbcType=VARCHAR}, #{item.bbh,jdbcType=VARCHAR},
#{item.spbmjc,jdbcType=VARCHAR},
#{item.hgjcksppm,jdbcType=CLOB}
)
ON DUPLICATE KEY UPDATE
BB = BB,
QYSJ = QYSJ,
GDQJZSJ = GDQJZSJ,
SPBM = SPBM,
SPMC = SPMC,
SM = SM,
ZZSSL = ZZSSL,
GJZ = GJZ,
HZX = HZX,
KYZT = KYZT,
ZZSTSGL = ZZSTSGL,
ZZSZCYJ = ZZSZCYJ,
ZZSTSNRDM = ZZSTSNRDM,
XFSGL = XFSGL,
XFSZCYJ = XFSZCYJ,
XFSTSNRDM = XFSTSNRDM,
TJJBM = TJJBM,
PID = PID,
GXSJ = GXSJ,
BBH = BBH,
SPBMJC = SPBMJC
Oracle 版 类型是number 但是oracle中是直接 number 而没有写成 NUMBER(14,2) 还是会有小数位啊
Mysql版 类型是decimal 不添加小数位 小数部分就会四舍五入 所以这点需要注意
mysql 对 空字符串 和 null 有区分
is not null 在mysql中 如果该字段为 空字符串 那么就是 true 不会过滤掉
null 会被过滤掉
oracle对空字符串和null没有区分
is not null 在oracle中 如果该字段为 空字符串或 null 那么就是 false 会过滤掉
所以请注意 如果在MySQL中需要用到 is not null 不要设置字段默认值为 Empty String而是设置成null
MySQL中NULL与空字符串