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。
select str_to_date('2008-4-2 15:3:28','%Y-%m-%d%H:%i:%s');
oracle: months_between 求日期间隔月份,除以12即为间隔年份; 天数,只需要日期直接相减; 当前时间:sysdate 字符转日期:to_date()
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;只返回一条数据; |
|