本文将举例演示游标的嵌套用法,首先建造表结构,如下:
drop table if exists `tb_user`;
create table tb_user (
id bigint(22) not null auto_increment primary key,
name varchar(20) not NULL,
age tinyint(3),
gmt_create date,
gmt_modified date
);
drop table if exists `tb_user_param`;
create table tb_user_param (
id bigint(22) not null auto_increment primary key,
user_id bigint(22) not null,
code varchar(100) not null,
value varchar(1000),
gmt_create DATE,
gmt_modified date
);
drop procedure if exists `sp_init_data`;
create procedure `sp_init_data`()
begin
declare v_i bigint(22) default 0;
declare v_uid bigint(22);
declare v_nick varchar(20) default 'lanbo_';
declare v_code_1 varchar(20) default 'address'