• mysq 存储过程 插入测试数据


    CREATE DEFINER = 'root'@'%' PROCEDURE `proc_InsertTestData`(
            
    IN iPatientIdBegin INTEGER(11),
            
    IN iPersonsCount INTEGER(11),
            
    IN dStartDate DATE,
            
    IN dEndDate DATE,
            
    IN iRecordCountPerDay INTEGER(11)
        )
        
    NOT DETERMINISTIC
        
    CONTAINS SQL
        SQL SECURITY DEFINER
        COMMENT 
    ''
    BEGIN
    declare tempPatientId int;
    declare iPatientIndex int;
    declare tempDateTimeDesc varchar(100);

    declare tempDate date;
    declare tempIndex int;

    declare tempFiledATime DateTime;
    declare tempSymptoms varchar(200);
    declare tempIncentives varchar(200);
    declare tempDrugs varchar(200);

    declare tempGatherTime DateTime;
    declare tempFiledB Int;
    declare tempFiledC float(9,2);
    declare tempFTimeFlag varchar(5);
    declare tempFAVailFlag tinyint;

    declare tempTime1 varchar(6);
    declare tempTime2 varchar(200);

    set tempDateTimeDesc = '03:00|07:00|13:00|17:00|19:00';
    set tempTime2 = concat(tempDateTimeDesc , '|');
    set tempSymptoms = '1|2';
    set tempIncentives = '1|2';
    set tempDrugs = '4|3|Ƭ;5|5|ml';

    /* 0 from first to last patientId */
    set iPatientIndex = 1;
    while iPatientIndex <= iPersonsCount do
        
    set tempPatientId = iPatientIdBegin + iPatientIndex;
        
    set iPatientIndex = iPatientIndex + 1;
        
    insert into gathertimesFiledB (PatientID,DateTimeDesc , RecordCreateTime)
        
    values(tempPatientId , tempDateTimeDesc ,dStartDate);
    end while/* 0 from first to last patientId */

    /* 1 from first to last date */
    set tempDate = dStartDate;
    while tempDate <= dEndDate do
        
        
    /* 1.1 from first to last patientId */
        
    set iPatientIndex = 1;
        
    while iPatientIndex <= iPersonsCount do
            
    set tempPatientId = iPatientIdBegin + iPatientIndex;
            
    set iPatientIndex = iPatientIndex + 1;
            
            
    /* 1.2 record a day */
            
    set tempIndex = 1;
            
    while tempIndex <= iRecordCountPerDay do
                
                
    /* Filed */
                
    set tempFiledATime = cast(concat(tempDate,' ',tempIndex,':05:00'as datetime);
                
    insert into tableA (PatientID , FiledATime ,Symptoms
                       ,SymptomsOther , Incentives , IncentivesOther , Drugs)
                 
    values(tempPatientId ,tempFiledATime ,tempSymptoms
                      ,
    '',tempIncentives, '' ,tempDrugs);
                    
                
    /* FiledB unvalid */
                
    set tempFTimeFlag = concat(lpad(tempIndex,2,'0'),':00');
                
                
    if FIND_IN_SET(tempFTimeFlag,tempDateTimeDesc) <= 0 then             
                    
    set tempGatherTime = cast(concat(tempDate,' ',lpad(tempIndex,2,'0'),':10:00'as datetime);
                    
    set tempFiledB = FLOOR(250 + ( RAND() * 51 ) );
                       
    set tempFiledC = Round(1 + (RAND() * 2) ,1);            
                    
    set tempFAVailFlag = "0";
                    
    insert into tableB(PatientID , GatherTime , FiledB , FiledC , FTimeFlag , FAVailFlag)
                    
    VALUES(tempPatientId, tempGatherTime , tempFiledB , tempFiledC , tempFTimeFlag , tempFAVailFlag);
                
    end if;
                
                
    set tempIndex = tempIndex + 1;           
                
            
    end while/* 1.2 record a day */
            
            
    /* 1.3 FiledB valid */
            
    while LENGTH(tempTime2) > 0 do            
                
    set tempTime1 = substring(tempTime2,1,5);
                
    set tempTime2 = substring(tempTime2,7);  
                
    set tempFiledB = FLOOR(250 + ( RAND() * 51 ) );
                
    set tempFiledC = Round(1 + (RAND() * 2) ,1);  
                
    set tempGatherTime = cast(concat(tempDate,' ',tempTime1,':00'as datetime);
                
    set tempFTimeFlag = tempTime1;
                
    set tempFAVailFlag = "1";
                
    insert into tableB(PatientID , GatherTime , FiledB , FiledC , FTimeFlag , FAVailFlag)
                
    VALUES(tempPatientId, tempGatherTime , tempFiledB , tempFiledC , tempFTimeFlag , tempFAVailFlag);
            
    end while/* 1.3 FiledB valid */
            
        
    end while/* 1.1 from first to last patientId */

        
    set tempDate = date_add(tempDate, interval 1 day);
    end while/* 1 from first to last date */

    END;
  • 相关阅读:
    15.[JavaScript]第8章对象和数组[上,下, 中]
    centos 7 firewall(防火墙)开放端口/删除端口/查看端口
    Docker使用docker-compose.yml构建Asp.Net Core和Mysql镜像并与Mysql数据库通信
    Docker使用Dockerfile构建Asp.Net Core镜像
    Docker使用Mysql镜像命令
    指定的 CGI 应用程序遇到错误,服务器终止了该进程。
    常见SMTP发送失败原因列表
    MVC View中获取action、controller、area名称、参数
    status 返回当前请求的http状态码
    asp:GridView控件使用FindControl方法获取控件的问题
  • 原文地址:https://www.cnblogs.com/freeliver54/p/2096102.html
Copyright © 2020-2023  润新知