oracle和mysql的学习

Oracle和mysql的部分语法区别mysql

1、WM_CONCAT对应GROUP_CONCAT;sql

2、 ronum可用limit代替;oracle

3、sys_guid()用uuid()代替app

4、add_months(t2.maxTime,-12)用date_add(t2.maxTime,interval -12 month)代替;函数

  date_format(date,'%Y-%m-%d')-->oracle中的to_char();ui

  str_to_date(date,'%Y-%m-%d')-->oracle中的to_date();spa

  %Y:表明4位的年份code

  %y:表明2为的年份orm

  %m:表明月, 格式为(01……12)xml

  %c:表明月, 格式为(1……12)

  %d:表明月份中的天数,格式为(00……31)

  %e:表明月份中的天数, 格式为(0……31)

  %H:表明小时,格式为(00……23)

  %k:表明 小时,格式为(0……23)

  %h: 表明小时,格式为(01……12)

  %I: 表明小时,格式为(01……12)

  %l :表明小时,格式为(1……12)

  %i: 表明分钟, 格式为(00……59)

  %r:表明 时间,格式为12 小时(hh:mm:ss [AP]M)

  %T:表明 时间,格式为24 小时(hh:mm:ss)

  %S:表明 秒,格式为(00……59)

  %s:表明 秒,格式为(00……59)

例子:

select case when add_months(t2.maxTime,-12)>t1.minTime then to_char(add_months(t2.maxTime,-12),'yyyy-MM') else to_char(t1.minTime,'yyyy-MM') end as startTime,to_char(t2.maxTime,'yyyy-MM') as endTime from(select min(t.log_time) as minTime from t_lm_operlog t) t1,(select max(t.log_time) as maxTime from t_lm_operlog t)t2

转为:

select case when date_add(t2.maxTime,interval -12 month)>t1.minTime then date_format(date_add(t2.maxTime,interval -12 month),'%Y-%m') else date_format(t1.minTime,'%Y-%m') end as startTime,date_format(t2.maxTime,'%Y-%m') as endTime from(select min(t.log_time) as minTime from t_lm_operlog t) t1,(select max(t.log_time) as maxTime from t_lm_operlog t)t2

5、oracle中:to_char(number)把number转成varchar2,在mysql中用concat(number)

6、oracle中:to_number在mysql中能够用cast或者convert 

7、Oracle中记录行号用Rownum RN;

  在mysql中:Select UID,(@rowNum:=@rowNum+1) as rowNo From a,(Select (@rowNum :=0) ) b Order by a.Money Desc;

8、SmRappfucauthEntityMapper.xml中的insert:merge into 

9、Oracle中:to_date(#{createtime ,jdbcType=VARCHAR },'yyyy-MM-dd hh24:mi:ss')

  Mysql中:  str_to_date(#{createtime ,jdbcType=VARCHAR },'%Y-%m-%d %T')

10、 Oracle中有递归:start with ...connect by prior;

  在mysql中没有写个方法,但能够用函数来实现mysql递归;

例如:

  Oracle递归:

    select s.sysfuncid from T_SM_SYSFUNC s where s.sysfuncid!=t.sysfuncid start with s.sysfuncid = t.sysfuncid connect by prior s.sysfunccode=s.psysfuncid

  Mysql递归:

    select s.sysfuncid from T_SM_SYSFUNC s where s.sysfuncid!=t.sysfuncid and FIND_IN_SET(s.sysfuncid,FOO3(t.sysfuncid))

相关文章
相关标签/搜索