mysql 、oracle存储过程语法区别
2015-05-28 08:12
513 查看
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;只返回一条数据;
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的触发器与存储过程语法差异
- Oracle与MySQL存储过程以及游标使用的区别
- 数据库Oracle与Mysql语法对比:存储过程
- Mysql与Oracle存储过程语法对比
- Oracle存储过程基本语法
- 转:oracle存储过程的基本语法
- Oracle-存储过程语法
- oracle 存储过程的基本语法 收藏
- oracle 存储过程基本语法
- oracle 存储过程的基本语法
- oracle存储过程语法回顾及注意事项
- oracle中函数和存储过程的区别和联系
- oracle 存储过程语法实例以及调用方法
- oracle 存储过程的基本语法
- oracle 存储过程的基本语法_数据库技巧
- 认识下mysql中的存储过程使用以及语法
- oracle 存储过程的基本语法
- oracle 存储过程的基本语法
- oracle 存储过程的基本语法 及注意事项
- oracle存储过程的基本语法