mysql:存储过程样例

drop  PROCEDURE  if EXISTS PK_out_patient_test;
CREATE PROCEDURE PK_out_patient_test()

begin

---定义变量并赋初值

DECLARE num int DEFAULT 0; 
DECLARE name2 int DEFAULT 1;
DECLARE idno int DEFAULT 43000000;
DECLARE tel_no int DEFAULT 1350000000;
DECLARE patientid int DEFAULT 2000;
DECLARE devicesn int DEFAULT 10100;
DECLARE teamid VARCHAR(32);

DECLARE done int ;


--定义游标

DECLARE c_outpat_teamid cursor for select team_id from sys_team;
/* 异常处理 */
declare CONTINUE HANDLER FOR SQLSTATE '02000' SET done=1;
truncate table BG_OUTPAT_MASTER_INDEX;
while num<100 do
open c_outpat_teamid;---打开游标
set done=0;

while done<>1 do

                        ---打开游标

fetch c_outpat_teamid into teamid;
 
set @dates= CONCAT(FLOOR(2016 + (RAND() * 1)),'-',LPAD(FLOOR(1 + (RAND() * 11)),2,0),'-',LPAD(FLOOR(3 + (RAND() * 8)),2,0));
set @times= CONCAT(LPAD(FLOOR(0 + (RAND() * 23)),2,0),':',LPAD(FLOOR(0 + (RAND() * 59)),2,0),':',LPAD(FLOOR(0 + (RAND() * 59)),2,0));

  ---循环插入数据
insert into ……;--插入数据,变量需要用@符号

set devicesn=devicesn+1;
set name2=name2+1;
set idno=idno+1;
set tel_no=tel_no+1;
set patientid=patientid+1;
end while;
set num=num+1;
CLOSE c_outpat_teamid;
end while;
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值