一、编写存储过程
DELIMITER // -- //代表分隔符
DROP PROCEDURE IFEXISTS proc_name; //
CREATE PROCEDUREproc_oper_art
(
in i_is_auto integer, --是否是自动创建标识 1:自动 0:手动
in i_art_id integer, -- 文章ID
out o_is_succ integer -- 是否操作成功 0:成功 1:失败
)
begin
declare v_createtime datetime; -- 文章创建时间,这个是带时分秒的
-- 异常捕获
declareexit handler for sqlexception
begin
seto_is_succ = 1;
end;
--给年、月、日赋值
set v_year = date_format(curdate(), '%Y');
select a.creatime, -- into给变量是这样写的
b.html_path,
a.is_recoving,
a.auto_create_cycle
into v_createtime,
v_path,
v_is_recoving,
v_cycle
from cms_article a,
cms_column b
where a.col_id = b.id
and a.id = i_art_id;
-- 拼接path
setv_rel_path = concat(v_path, '/', v_day, '/', i_art_id, '.html'); -- 字符串拼接是用concat()
end;
//
二、测试存储过程
call proc_name();
上例中存储过程有in有out,调用时为
call proc_oper_art(1,2, @a); -- out参数需要用@加变量
执行后可用select @a查询返回的结果