"The Blind Toss series" MySQL stored procedure initial contact

Source: Internet
Author: User

Start the "Blind Toss series", this series is purely blind toss, may have no practical significance.

MySQL Stored Procedure generation table:

Create a new user table that contains the ID, username, password, usertable fields.

Then create the stored procedure:

Create PROCEDUREcreate_table ()BEGINDECLARENint DEFAULT 0;DECLARET_errorINTEGER DEFAULT 0; DECLARE CONTINUEHANDLER forSQLEXCEPTIONSETT_error=1; Temp_loop:loopstartTRANSACTION; SET @m=Replace(UUID (),'-',"');Set @str=Concat'CREATE TABLE x',@m,'(id int)');Preparestmt from @str;EXECUTEstmt;Set @insertstr=Concat'INSERT INTO User (username,password,usertable) VALUES ("Test", "TESTP", "x',@m,'")');PrepareStmt1 from @insertstr;EXECUTESTMT1;IFT_error= 1  Then  ROLLBACK; ELSE              COMMIT; END IF; SetN=N+1;IFN>= -  ThenLEAVE Temp_loop;END IF;ENDLOOP;END

Get the UUID through the UUID () and then remove the-line, and then add an X to the front, why add X, because the table name directly with the UUID will sometimes error, specific reasons unknown.

Then generate the Username,password, and then insert the resulting table name into the Usertable field.

Execute a stored procedure by using call Creat_table ().

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.