mysql在同一过程中使用返回值
我的查询执行并返回一个值,我需要在同一个过程中使用返回值,如何使用它 我的代码是mysql在同一过程中使用返回值,mysql,Mysql,我的查询执行并返回一个值,我需要在同一个过程中使用返回值,如何使用它 我的代码是 set @table_name_count = CONCAT('SELECT COUNT(*) into @xcount ', CONCAT( ' FROM ' ) , concat( table_name),concat( ' where issueNumber=',concat('30030'),concat( ' and ISSNcode='),CONCAT('112640402'))); P
set @table_name_count = CONCAT('SELECT COUNT(*) into @xcount ', CONCAT( ' FROM ' ) , concat( table_name),concat( ' where issueNumber=',concat('30030'),concat( ' and ISSNcode='),CONCAT('112640402')));
PREPARE statement from @table_name_count;
EXECUTE statement;
DEALLOCATE PREPARE statement;
select 'hello4' from dual;
IF xcount > 0 and xcount<>NULL THEN
DELETE from table_name where issueNumber='30030' and ISSNcode='112640402' ;
END IF ;
将@table_name_count=CONCAT('SELECT count(*)设置为@xcount',CONCAT('FROM'),CONCAT(table_name)),CONCAT('where issueNumber='、CONCAT('30030')、CONCAT('and ISSNcode=')、CONCAT('112640402');
从@table\u name\u count准备语句;
执行语句;
解除分配准备报表;
从dual中选择“hello4”;
如果xcount>0且xcountNULL,则
从表_name中删除,其中issueNumber='30030'和ISSNcode='112640402';
如果结束;
这里我需要在条件中使用@xcount
IF xcount > 0 and xcount<>NULL THEN
DELETE from table_name where issueNumber='30030' and ISSNcode='112640402' ;
END IF ;
如果xcount>0且xcountNULL,则
从表_name中删除,其中issueNumber='30030'和ISSNcode='112640402';
如果结束;
您只是忘记了变量名前面的@
,因为您正在处理用户(会话)变量。您的IF
语句应该是这样的
IF @xcount > 0 THEN
^
您不需要检查NULL
,因为COUNT()
总是返回一个值
这里是演示
现在在发出
删除之前,对记录是否存在进行这样的检查是没有意义的。
如果在DELETE
语句的WHERE
子句中没有匹配条件的行,它就不会做任何事情,也不会产生任何错误
因此,除了DELETE
语句之外,您可以删除所有代码