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