https://blog.csdn.net/weixin_38673554/article/details/86503982#_1

oracle与使用mysql的区别

 

https://www.cnblogs.com/nr-zhang/p/10553646.html

1.Like模糊查询有字符串拼接
所有用 str1||str2 拼接的字符串都要改成CONCAT(str1,str2)
'%'||#{zbmc}||'%'改成CONCAT('%',#{zbmc},'%')
a.fpdm||'-'||a.fphm 改成CONCAT(a.fpdm,'-',a.fphm)

Oracle中concat与||区别(以及与mysql中concat函数区别)

2. 分页查询
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}
1
2
3
改成

SELECT A.* from FX_PZ A
order by ${sort} ${order} limit #{startRow},#{rows}
1
2
注意limt关键字是最后才用到的。以下条件的出现顺序一般是:where->group by->having-order by->limit

Oracle与Mysql的分页比较
MySQL的Limit详解

3.Oracle中to_date/to_char函数改成MySql中的函数
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) (总结)

4.Oracle中nvl/decode函数改成MySql中的函数
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
)
1
2
3
4
5
6
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的使用

5.Oracle中substr/to_number函数改成MySql中的函数
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)) /浮点型/

6.Oracle中MERGE INTO批量更新/插入改成MySql的批量更新插入
Mybatis批量新增或更新(mysql数据库)

<update id="updateFlbmBatch" parameterType="java.util.List">
MERGE INTO TAB_FLBM A
USING
<foreach collection="list" item="item" index="index"
separator="union">
(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
</foreach>
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)

</update>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
改成

<update id="updateFlbmBatch" parameterType="java.util.List">
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
<foreach collection="list" item="item" index="index"
separator=",">
(
#{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}
)
</foreach>
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
</update>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
2019-01-10 补充
7.数据库类型 Oracle中number 改成 mysql中decimal
Oracle 版 类型是number 但是oracle中是直接 number 而没有写成 NUMBER(14,2) 还是会有小数位啊
Mysql版 类型是decimal 不添加小数位 小数部分就会四舍五入 所以这点需要注意

8.Oracle中is not null 和 mysql 中有区别
mysql 对 空字符串 和 null 有区分
is not null 在mysql中 如果该字段为 空字符串 那么就是 true 不会过滤掉
null 会被过滤掉
1
2
3
oracle对空字符串和null没有区分
is not null 在oracle中 如果该字段为 空字符串或 null 那么就是 false 会过滤掉
1
2
所以请注意 如果在MySQL中需要用到 is not null 不要设置字段默认值为 Empty String而是设置成null

MySQL中NULL与空字符串
————————————————
版权声明:本文为CSDN博主「csdn_yfqs」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/csdn_yfqs/article/details/83992739