mysql存储过程

分100张表执行

#drop PROCEDURE idata;

delimiter ;;
create procedure iData()
begin
    declare i int;
    declare s varchar(2);
    set i = 0;
    set s = '';
    while (i <= 100)
        do
            set s = LPAD(i, 2, 0);
            ##每个表新增指定的num记录数
            set @sqlStr = concat('update user_card_0', s,
                                 ' set activity_limit_type=''10'',activity_id=''T13234612'' WHERE sale_order in (''00020200427001000075'',''XSD20200116001000352''); ');
            PREPARE stmt from @sqlStr;
            EXECUTE stmt;
            ##每个表新增指定的num记录数
            set @sqlStr2 = concat('update user_card_0', s,
                                 ' set activity_limit_type=''10'',activity_id=''T13234613'' WHERE sale_order in (''00020200708001000092''); ');
            PREPARE stmt from @sqlStr2;
            EXECUTE stmt;
            set i = i + 1;
        end while;
end;;
delimiter ;
call iData();

查询

drop PROCEDURE idata1;
delimiter ;;
create procedure iData1(OUT data_t VARCHAR(100))
begin
    declare i int;
    declare s varchar(2);
    set i = 0;
    set s = '';
    while (i <= 100)
        do
            set s = LPAD(i, 2, 0);
            ##每个表新增指定的num记录数
            set @sqlStr = concat(
                    'select activity_id,user_id,sale_order into @card_no_result, @user_id_result,@sale_order_result FROM user_card_0',
                    s,
                    ' WHERE sale_order in (''00020200427001000075'',''XSD20200116001000352'',''00020200708001000092'') limit 1; ');
            PREPARE stmt from @sqlStr;
            EXECUTE stmt;
            IF @card_no_result is not null THEN
                select @card_no_result, @user_id_result, @sale_order_result;
            END IF;

            SET data_t := @card_no_result;
            set i = i + 1;
        end while;
end;;
delimiter ;
call iData1(@data_t);
SELECT @data_t;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值