MySQL dynamically generates test data

Source: Internet
Author: User

I. Problems
To generate two types of data:
Class A: 01 02 03 of two digits... 09 10 11... 19 20 21... 98 99
Another Class B: The third-digit 100 101 102... 110 111 112... 998 999
Ii. Solution
1. Create a table CopyCode The Code is as follows: Create Table 'test'. 'ta '(
'A' varchar (45) not null
) Engine = InnoDB default charset = utf8;

2. Create a stored procedureCopy codeThe Code is as follows: delimiter $
Drop procedure if exists 'test'. 'proc _ TP '$
Create definer = 'root' @ 'localhost' procedure 'proc _ TP '(in prex int, in Max INT)
Begin
Declare I int default 0;
Declare s varchar (500 );
While (I <10 and prex <max) Do
Select Concat (prex, I) into S;
Insert into TA (a) values (s );
Set I = I + 1;
If (I = 10 and prex <max) then
Set prex = prex + 1;
Set I = 0;
End if;
End while;
End $
Delimiter;

3. respectively call and execute the Stored Procedure
Call proc_tp () to create Class A Data
Call proc_tp (10,100) to create Class B data
4. query results
Select * From ta t order by cast (A as signed) ASC;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.