Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.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_Stored Procedures - Fatal编程技术网

Mysql 尝试为使用存储过程检索的所有行向列中的现有值添加附加值

Mysql 尝试为使用存储过程检索的所有行向列中的现有值添加附加值,mysql,stored-procedures,Mysql,Stored Procedures,我花了很长时间才弄明白。。因此,我的update语句将影响0行,尽管我知道它至少会影响多行,因为我已经尝试将其作为独立语句。代替update语句,我尝试了select语句,它正在工作,这是否意味着update语句不应该在存储过程中工作。。我有点怀疑。。所以我想得到第二个意见 my stored procedure code here: DELIMITER $$ CREATE PROCEDURE updateKeywordsInRIConsole(in retailerId int ) BEG

我花了很长时间才弄明白。。因此,我的update语句将影响0行,尽管我知道它至少会影响多行,因为我已经尝试将其作为独立语句。代替update语句,我尝试了select语句,它正在工作,这是否意味着update语句不应该在存储过程中工作。。我有点怀疑。。所以我想得到第二个意见

my stored procedure code here: 
DELIMITER $$
CREATE PROCEDURE updateKeywordsInRIConsole(in retailerId int )

BEGIN

declare key_words varchar(200) default null;

declare grpid bigint(20);

declare finished bool default false;

declare cur1 cursor for 
    select Keywords, GRPID  
    from RIConsole 
    where RetailerID = retailerId 
    and  DateCreated > date(now()) - interval 1 year 
    and INSTR(Keywords, "offer_page") = false;

declare continue handler for not found set finished = 1;


declare exit handler for sqlexception
begin
        show errors;
end;

declare exit handler for sqlwarning
begin
        show warnings;
end;

open cur1;

    start_loop: loop

        fetch cur1 into key_words, grpid;

        if finished = 1 then 

            leave start_loop;

        end if;

      update RIConsole set Keywords = concat(key_words, " ", 
      "offer_page") where GRPID = cast(grpid as signed); <-- this code not working...I called it with cast function to make sure.. and i also tried without it. 




    end loop start_loop;

close cur1;


END $$

DELIMITER ;
DROP PROCEDURE updateKeywordsInRIConsole;
此处是我的存储过程代码:
分隔符$$
创建过程updateKeywordsInRIConsole(在retailerId int中)
开始
声明关键字varchar(200)默认为空;
声明grpid bigint(20);
声明完成的bool默认值为false;
将cur1游标声明为
选择关键字,GRPID
来自RIConsole
其中RetailerID=RetailerID
和DateCreated>date(现在())-间隔1年
和INSTR(关键字,“报价页”)=false;
未找到集合的声明继续处理程序finished=1;
为sqlexception声明退出处理程序
开始
显示错误;
结束;
为sqlwarning声明退出处理程序
开始
显示警告;
结束;
开放cur1;
开始循环:循环
将cur1提取到关键字grpid中;
如果finished=1,则
离开start_循环;
如果结束;
更新RIConsole集合关键字=concat(关键字“,

“报价页”),其中GRPID=cast(GRPID签字) 是的,您可以在存储过程中执行更新

如果您对SELECT感到满意,那么可以在一条语句中执行while操作。e、 g

CREATE PROCEDURE updateKeywordsInRIConsole(IN retailerId INT)

BEGIN
  UPDATE  RIConsole 
  SET Keywords = CONCAT(Keywords, " ",  "offer_page") 
  WHERE where RetailerID = retailerId 
  AND DateCreated > DATE(NOW()) - INTERVAL 1 YEAR 
  AND INSTR(Keywords, "offer_page") = false;
END 
;

是的,您可以在存储过程中执行更新

如果您对SELECT感到满意,那么可以在一条语句中执行while操作。e、 g

CREATE PROCEDURE updateKeywordsInRIConsole(IN retailerId INT)

BEGIN
  UPDATE  RIConsole 
  SET Keywords = CONCAT(Keywords, " ",  "offer_page") 
  WHERE where RetailerID = retailerId 
  AND DateCreated > DATE(NOW()) - INTERVAL 1 YEAR 
  AND INSTR(Keywords, "offer_page") = false;
END 
;