字符串相关函数

1
2
3
select concat('hello ', 'mysql ', 'haha ', 'hehe ') from dual;   
Oracle默认只能拼两个,如需多个拼接可以使用嵌套。
select 'hello ' || 'mysql ' from dual; ‘||’ 在 MySQL不可以使用。

image-20220515024812461

1
2
3
4
5
6
7
8
9
10
11
日期转字符串:
在MySQL中没有to_date函数,进行日期转换需使用date_format()来代替。

select date_format('2013-5-11', 'yyyy-mm-dd') from dual; 在Oracle中的‘yyyy-mm-dd’MySQL下不支持。
select date_format(now(), '%Y-%m-%d') from dual; y和Y不一样。
select date_format(now(), '%Y-%c-%d %h:%i:%s') from dual; c和m、M不一样

所以yyyy-mm-dd hh24:mi:ss格式在MySQL中对应'%Y-%c-%d %h:%i:%s'

字符串转日期:
select str_to_date('2013-6-04 05:14:15' , '%Y-%c-%d %h:%i:%s') from dual;