日期:2014-05-16 浏览次数:20764 次
mysql> delimiter // mysql> mysql> CREATE PROCEDURE login (uname varchar(64),upwd varchar(64),out counts int) -> BEGIN -> DECLARE iCount INT; -> DECLARE bExist INT DEFAULT 0; -> -> SET iCount = 10; -> -> SELECT 1 into bExist FROM t WHERE name=uname; #use the variable to check the IF EXISTS -> -> IF bExist>0 then -> SELECT iCount,'Record Found.'; -> ELSE -> SELECT iCount,'NOT EXISTS'; -> END IF; -> -> END; -> -> // Query OK, 0 rows affected (0.00 sec) mysql> mysql> delimiter ; mysql> call login('f3','pswd',@i); +--------+---------------+ | iCount | Record Found. | +--------+---------------+ | 10 | Record Found. | +--------+---------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.02 sec) mysql> call login('unkonw','pswd',@i); +--------+------------+ | iCount | NOT EXISTS | +--------+------------+ | 10 | NOT EXISTS | +--------+------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected, 1 warning (0.02 sec) mysql>
------解决方案--------------------
好像能用吧,我的存储过程就是是这样写的,没有报错呀
------解决方案--------------------
DECLARE iCount int;
begin
SET iCount = 10;
SELECT iCount;
MYSQ中是可以的
对了请问下 IF EXISTS(SELECT * FROM sysdatabases WHERE name='bookshop') 这样的语句 mysql 支持吗?就是
判断 有没有查出内容来??
select count(*) into @ee FROM sysdatabases WHERE name='bookshop'
if @ee>1 then
select 'OK';
ELSE
select 'NO';
END IF