Mysql and Oracle difference (2)

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qq125281823/article/details/88288145

1. Time subtraction

Oracle Mysql
Subtraction time = days (possibly fractional) Subtraction time, not the time value
实际是mysql的时间相减是做了一个隐式转换操作,将时间转换为整数,但并不是用unix_timestamp转换,而是直接把年月日时分秒拼起来,如2013-04-21 16:59:33 直接转换为20130421165933,由于时间不是十进制,所以最后得到的结果没有意义

要得到正确的时间相减秒值,有以下3种方法:
1、time_to_sec(timediff(t2, t1)),
2、timestampdiff(second, t1, t2),
3、unix_timestamp(t2) -unix_timestamp(t1)

2. Data Conversion

Oracle Mysql
to_char(,‘fm999999990,9999’) convert()/cast()/format()
format()函数返回类型是字符串,满三位会加一个逗号。
针对数字类型转换建议使用 convert或者cast函数,用法如下:
format(param, 2) (不建议)
convert(param, decimal(12,2))(建议)
cast(param as decimal(12,2))(建议)

select 0+convert(11.2,decimal(12,2)) ;  -- 12.20,严格按照格式来转换
select 0+covert(11.2,char); -- 11.2

Tip: sometimes can not distinguish between queries or convert from digital or other Mysql data type, you can select which side of the window to see when looking at digital partial query data show.

3. string interception

Oracle Mysql
substr () / substr () can have spaces substr () / no spaces

Mysql's substr function can not be written with spaces between the parentheses and function names, but you can oracle.
Oracle of substr function can start from 0 or 1, both effects were the same, but Mysql can only start from 1 interception, 0 beginning with an empty

4.insert statement

Oracle Mysql
'' / Null can be inserted '' / Null mean the same

When the query and insert special attention

5.Mysql case of the string

Mysql default case-insensitive

MySql默认查询是不区分大小写的,如果需要区分他,必须在建表的时候,Binary标示敏感的属性.

CREATE TABLE NAME(
name VARCHAR(10) BINARY
);

2、 在SQL语句中实现 SELECT * FROM TABLE NAME WHERE BINARY name='Clip';

3、 设置字符集:

utf8_general_ci --不区分大小写

utf8_bin--区分大小写

Guess you like

Origin blog.csdn.net/qq125281823/article/details/88288145