深入mysql存储过程中表名使用参数传入的详解
begin
declare date_str varchar(8);
declare table_prefix varchar(20);
set table_prefix='mail_rare_visit_';
set date_str = date_format(current_date(),'%y%m%d');
set @table_name = concat(table_prefix, date_str);
set @s = concat('create table ', @table_name, '(
`id` int(11) not null auto_increment,
`user_id` int(11) not null,
`city_id` int(11) not null,
`email` varchar(300) not null,
`channel_id` int(11) default null,
`w_revenue` decimal(7,6) not null default 0.000000,
`w_buy` decimal(7,6) not null default 0.000000,
`w_browse` decimal(7,6) not null default 0.000000,
`rec_goods` varchar(800) default null,
`update_time` timestamp not null default current_timestamp on update current_timestamp,
primary key (`id`),
key `idx_user_id` (`user_id`),
key `idx_city_id` (`user_id`),
key `idx_email` (`email`),
key `idx_channel_id` (`channel_id`)
) engine=myisam default charset=utf8;');
prepare stmt from @s;
execute stmt;
deallocate prepare stmt;
end
上一篇: CSS定义通用透明效果