MySQL stored procedure notation for dynamically passing in table name parameters

Source: Internet
Author: User
Delimiter//create procedure OneKey (in NewName varchar (+), in oldname varchar (+), in Idnum INT) beginset @sqlStmt = CONCA T (' insert INTO ', NewName, ' (' Name ', ' age ', ' sex ', ' major ', ' Pass ', ' photo ') Select ' name ', ' age ', ' sex ', ' major ', ' Pass ', ' Photo ' from ', Oldname, ' where id = ', idnum); PREPARE stmt from @sqlStmt; executestmt; End;//delimiter; call OneKey (' stu1 ', ' Student ', 5);

The SQL statement in Begin,end cannot directly recognize the table name by concatenation of the "+" number (the parameters after the where condition can be spliced by the "+" sign, can be recognized!) The premise is not to write in the concat () Method! ), so you need to use the concat () method, in parentheses to write SQL statements, splicing use "," comma to join, at the same time remember one thing: "Stitching place to leave a space!! "For example, concat (' insert INTO ') here to leave a space after entering, otherwise it will not be able to recognize the name of the table passed in!

MySQL stored procedure notation for dynamically passing in table name parameters

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.