我想在数据库中查询有无给定条件的记录,如果有就返回FALSE如果无就返回TRUE,然后再用IF语句控制执行下面的程序。
create procedure st1(in xuehao varchar(10),in xingming varchar(50),in academyno smallint(2),in banji varchar(20),in email varchar(20),in passwd varchar(20),out flag bool)
begin
declare a varchar(10);
declare getstudentno cursor for select studentno from user where studentno=xuehao;
set flag=false;
open getstudentno;
fetch getstudentno into a;
if a!=null || a!="" then
insert into user(studentno,name,academyno,usertype,class,email,passwd) values
(xuehao,xingming,academyno,banji,email,passwd);
set flag=true;
end if;
close getstudentno;
end我用这个试了一下 错误提示是说FETCH是空值
很痛苦
我想我问一下大家MYSQL存储过程中是否有判断游标内是否为空的函数啊
最好能给个例子谢谢
create procedure st1(in xuehao varchar(10),in xingming varchar(50),in academyno smallint(2),in banji varchar(20),in email varchar(20),in passwd varchar(20),out flag bool)
begin
declare a varchar(10);
declare getstudentno cursor for select studentno from user where studentno=xuehao;
set flag=false;
open getstudentno;
fetch getstudentno into a;
if a!=null || a!="" then
insert into user(studentno,name,academyno,usertype,class,email,passwd) values
(xuehao,xingming,academyno,banji,email,passwd);
set flag=true;
end if;
close getstudentno;
end我用这个试了一下 错误提示是说FETCH是空值
很痛苦
我想我问一下大家MYSQL存储过程中是否有判断游标内是否为空的函数啊
最好能给个例子谢谢
解决方案 »
- 疯了、postgresql才接触、语法完全七窍六通。。求教这条sql怎么改。。
- 求高手指导 急!!!
- 2台机器冷备份数据迁移出错
- 高手们快来帮帮关于mysql游标的忙吧
- 请问如何才能在linux的shell脚本中创建数据库和表?
- 讨论下,严格按关系表规范设计,订单表只保存客户表的客户id的弊端!
- 两表一对多(一个问题对应多个选项)不知道能否一行记录直接查询出来
- win2000 server 下能不能装apache,和mysql?
- 我想用一句MYSQL语句,将id 2的日期0000-00-00变为id 1的日期2002-12-12
- 求大神帮看条分组排名语句。An error occured in multi-table update。没分了。。。
- 一个mysql dump命令,直接跑和用crontab跑,结果竟然不同
- 只剩下frm文件了,还能恢复么?
参考:
DECLARE _item_in_used INT;
SELECT COUNT(*) INTO _item_in_used FROM order_detail WHERE item_id = _item_id;/* do not update name,
UI should protected changing name
but we protected it again in the proc ...
*/
IF _item_in_used >0 THEN
UPDATE items SET cat_id = _cat_id, code = _code, price = _price WHERE item_id = _item_id;
ELSE
UPDATE items SET cat_id = _cat_id, code = _code, name = _name, price = _price WHERE item_id = _item_id;
END IF;