mysql 、oracle預存程序文法區別

來源:互聯網
上載者:User

標籤:mysql   預存程序   oracle   

mysql 、oracle預存程序文法區別

 

1、  條件陳述式:mysql使用elseif關鍵字,oracle是elsif關鍵字;

oracle:

if運算式 then 

運算式;

elsif

運算式;

       endif;

mysql:

if運算式then 

運算式;

elseif

運算式;

              endif;

2、 字串串連

       oracle使用 || ;

       mysql 使用concat函數;

 

3、 日期計算(年月日數)

mysql:

函數TimeStampDiff()是MySQL本身提供的可以計算兩個時間間隔的函數,文法為:TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2),其中unit單位有如下幾種,分別是:SECOND, MINUTE, HOUR, DAY,WEEK, MONTH, QUARTER, or YEAR。

目前時間:sysdate() 
字元轉日期:str_to_date() 分隔字元一致,年月日要一致;樣本:

select str_to_date(‘2008-4-2 15:3:28‘,‘%Y-%m-%d%H:%i:%s‘);

日期轉字元:DATE_FORMAT(date,format) 
SELECT DATE_FORMAT(sysdate(), ‘%Y-%m-%d %H:%i:%s‘);
數字轉字元:concat(num,’’)

oracle:

       months_between 求日期間隔月份,除以12即為間隔年份;

       天數,只需要日期直接相減;

       目前時間:sysdate

       字元轉日期:to_date()

日期轉字元:to_char(date,format) to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss‘)
數字轉字元:to_char(num)

 

4、 定義遊標

       oracel:

       CURSOR curPlanIndex is

    SELECT a.INDEX_SCORE

          ,c.enum_value,c.dn_value,c.up_value,c.score,c.score_desc

    FROM eval_plan_index  a

         JOIN eval_index_score c onc.index_id=a.index_id and a.plan_id = c.plan_id

    WHERE a.plan_id = V_PLAN_ID and a.index_id= V_INDEX_ID

order by dn_value;

MYSQL:

declare  curPlanIndex cursor for

    SELECT a.INDEX_SCORE

          ,c.enum_value,c.dn_value,c.up_value,c.score,c.score_desc

    FROM eval_plan_index  a

         JOIN eval_index_score c onc.index_id=a.index_id and a.plan_id = c.plan_id

    WHERE a.plan_id = V_PLAN_ID and a.index_id= V_INDEX_ID

order by dn_value;

 

5、 selectinto 賦值

oracle 有exception錯誤處理

 begin

    select value_name into vc_num_unit fromsys_dict

      where dict_code = ‘szdw‘ and value_code =v_num_unit  and rownum <=1 ;

 exception

    when no_data_found then

      vc_num_unit := ‘‘;

 end;

mysql 如果select 沒有資料,則不執行into操作,變數值保持為上次結果,需要手工重設。最好能limit 1;只返回一條資料;

mysql 、oracle預存程序文法區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.