drop procedure if exists p_hello_world;

create procedure p_hello_world()
begin
    declare id integer;
    declare username varchar(256);
    declare result varchar(4000) default '';
    /* don't work */
    /*declare cur_user cursor for select id from p_user where id is not null and name is not null order by id;*/
    declare cur_user cursor for select t.id, t.name from p_user t where t.id is not null and t.name is not null order by t.id;
    declare continue handler for SQLSTATE '02000' set id = null; 
    open cur_user;
    fetch cur_user into id, username;
    while (id is not null) do
        set result = concat(result, 'id:', id, 'username:', username, ';');
        fetch cur_user into id, username;
    end while;
    close cur_user;
    select result;
end;

call p_hello_world();

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2022-02-01
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
猜你喜欢
  • 2021-05-01
  • 2021-11-14
  • 2021-08-22
  • 2021-05-12
  • 2022-12-23
  • 2022-02-16
相关资源
相似解决方案