怎么修改下面这个存储过程

eimhee 2008-07-16 12:26:03
怎么修改下面这个存储过程

create proc p_chk
(n1 int,
n2 int,
out ifCanInsert int
)
if exists(select 1 from t where n1 between number1 and number2 or
n2 between number1 and number2 )
set ifCanInsert =0
else
set ifCanInsert =1
//

出现错误为
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'proc
p_chk
(n1 int,
n2 int,
out ifCanInsert int
)
if exists(select 1 from t wher' at line 1
...全文
82 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyz0832 2008-07-16
  • 打赏
  • 举报
回复
delimiter $;
create proc p_chk (n1 int, n2 int, out ifCanInsert int)
begin
if exists(select 1 from t where n1 between number1 and number2 or
n2 between number1 and number2 ) then
set ifCanInsert =0;
else
set ifCanInsert =1;
end if;
end

delimiter ;
WWWWA 2008-07-16
  • 打赏
  • 举报
回复
DELIMITER $$

CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE `zz`.`ee`(n1 int,
n2 int,
out ifCanInsert int )
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
if (select count(*) from t where n1 between number1 and number2 or
n2 between number1 and number2)>0 then
set ifCanInsert =0;
else
set ifCanInsert =1 ;
end if;
END$$

DELIMITER ;

or

DELIMITER $$

CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE `zz`.`ee`(n1 int,
n2 int,
out ifCanInsert int )
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
if exists(select 1 from t where n1 between number1 and number2 or
n2 between number1 and number2 ) then
set ifCanInsert =0;
else
set ifCanInsert =1 ;
end if;
END$$

DELIMITER ;

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧