码迷,mamicode.com
首页 > 数据库 > 详细

MySQL PLSQL Demo - 003.静态游标

时间:2015-07-01 20:28:27      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

 

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();

 

MySQL PLSQL Demo - 003.静态游标

标签:

原文地址:http://www.cnblogs.com/nick-huang/p/4614282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!