oracle和mysql的學習

來源:互聯網
上載者:User

標籤:concat   rac   rtti   perl   har   to_char   uid   case when   sys_guid   

Oracle和mysql的部分文法區別

一、WM_CONCAT對應GROUP_CONCAT;

二、 ronum可用limit代替;

三、sys_guid()用uuid()代替

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

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

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

  %Y:代表4位的年份

  %y:代表2為的年份

  %m:代表月, 格式為(01……12)

  %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

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

六、oracle中:to_number在mysql中可以用cast或者convert 

七、Oracle中記錄行號用Rownum RN;

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

八、SmRappfucauthEntityMapper.xml中的insert:merge into 

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

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

十、 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))

oracle和mysql的學習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.