Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如果参数不';表中不存在吗?_Mysql_Sql_Stored Procedures_Error Handling - Fatal编程技术网

Mysql 如果参数不';表中不存在吗?

Mysql 如果参数不';表中不存在吗?,mysql,sql,stored-procedures,error-handling,Mysql,Sql,Stored Procedures,Error Handling,我有一个存储过程: delimiter // create procedure sp_finish_campaign(in c_title varchar(30)) begin update campaign set CAMPAIGNFINISHDATE = CURDATE() where TITLE = c_title; end// delimiter ; 我想知道如果活动表中不存在c_title参数,如何抛出带有消息的错误处理程序。我试过使用 为SQLSTATE“4200

我有一个存储过程:

delimiter //
create procedure sp_finish_campaign(in c_title varchar(30))
begin 
    update campaign set CAMPAIGNFINISHDATE = CURDATE()
    where TITLE = c_title;
end//
delimiter ;
我想知道如果活动表中不存在c_title参数,如何抛出带有消息的错误处理程序。我试过使用

为SQLSTATE“42000”声明退出处理程序
选择“错误!”

和一些if语句,但要么语法错误,要么在fieldlist中出现错误1054未知列标题。

使用以下代码:

create procedure sp_finish_campaign(in c_title varchar(30))
begin 
    update campaign set CAMPAIGNFINISHDATE = CURDATE()
    where TITLE = c_title;

    if @@rowcount=0
    begin
      DECLARE @ErrorMessage  NVARCHAR(4000);
      DECLARE @V_ErrorCode   INT;
      DECLARE @ErrorState    INT;

      SELECT @V_ErrorCode   = 50000 ,
             @ErrorMessage  = c_title+ ' is not exists' ,
             @ErrorState    = 1
      THROW @V_ErrorCode,@ErrorMessage,@ErrorState

    end
end//

似乎根本不起作用,到处都是语法错误