MySQL dynamically generates test data _mysql

Source: Internet
Author: User
I. Problems
To generate two types of data:
Class A: two-digit 01 02 03 ... 09 10 11 ... 19 20 21 ... 98 99
Another class B: three-digit 100 101 102 ... 110 111 112 ... 998 999
Ii. Solutions
1, build the table
Copy Code code as follows:

CREATE TABLE ' test '. ' Ta ' (
' A ' varchar not NULL
) Engine=innodb DEFAULT Charset=utf8;

2. Create a stored procedure
Copy Code code as follows:

DELIMITER $$
DROP PROCEDURE IF EXISTS ' test '. ' Proc_tp ' $$
CREATE definer= ' root ' @ ' localhost ' PROCEDURE ' proc_tp ' (in Prex 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. Call execution stored procedure separately
Call PROC_TP (0,10) creates Class A data
Call PROC_TP (10,100) 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.