对于空字串的判断,其中MySQL只能对null过滤
oracle: 使用nvl(exp1,exp2) 函数
select nvl('',1) from dual; -- returns:1
select nvl(null,1) from dual; -- returns: 1
mysql:使用ifnull(exp1,exp2)函数
SELECT ifnull(null,1); -- returns: 1
SELECT ifnull('',1); -- returns: ''
对于日期时间操作
操作 | oracle | mysql |
---|
转字符 | TO_CHAR(exp,‘yyyy-MM-dd’) | date_format(exp,’%Y-%m-%d’) |
转字符 | TO_CHAR(exp,‘yyyy-MM-dd HH:mm:ss’) | date_format(exp,’%Y-%m-%d %T’) |
转时间 | TO_DATE(exp,‘yyyy-MM-dd’) | str_to_date(exp,’%Y-%m-%d’) |
转时间 | TO_DATE(exp,‘yyyy-MM-dd HH24:mi:ss’) | str_to_date(exp,’%Y-%m-%d %T’) |
取月份 | TO_CHAR(exp,‘MM’) | MONTH(exp) |
取时间 | sysdate | now() |
日期相减 | date1 - date2 | datediff(date1,date2) |
字符链接
oracle: 可使用 || 符号,可用concat(exp1,exp2)函数
select '1'||'2' from dual; -- returns '12'
select concat('1','2') from dual; -- returns '12'
select concat('1','2','3') from dual; -- returns error 参数个数无效
mysql: 只能用concat(exp1,exp2,...), || 符号在MySQL表示 或 ,MySQL的concat函数可有N个参数,Oracle只有两个参数
select concat('1','2') from dual; -- returns '12'
select concat('1','2','3') from dual; -- returns '123'
表连接(左右连接)
oracle:
oracle自带有表连接的(+)功能,也可用left(right) join on
mysql:
mysql 没有(+)使用功能,只能用left(right) join on,否则就会报错
换行回车符
Oracle : 换行符是chr(10),回车符是chr(13)
MySQL : 换行符是char(10),回车符是char(13)
注意
oracle : ORDER BY 默认排序时,空值在下;MySQL空值在上。