mysql stored procedure to create a table (I searched so many but none of them can be used)

Recently, you need to create a table you need in a stored procedure. There is a requirement that the name of the table needs to be dynamic! ! ! !

So I started looking for a certain blog site, but found that many things were not available directly. I felt very angry, so I found some information myself and actually performed the operation. Adhering to the attitude that knowledge is used to share rather than mislead others, I sneered at those who copied other people's information and turned it into their own blog.

Below I share not only the code, but also the running effect. If you have any problems during the operation, you can leave a message to contact me in time, and we will discuss the results of the operation together:

The stickers are proof, and the code is placed below. Please note the name of the original author when you share the blog here too! ! ! !

CREATE DEFINER=`root`@`%` PROCEDURE `NewProc`(IN `tablename` varchar(200))BEGIN	#Routine body goes here...	set @sqlstr = concat('CREATE TABLE IF NOT EXISTS ',tablename,' (		`LOG_NR_` bigint(20) NOT NULL AUTO_INCREMENT,		`TYPE_` varchar(64) COLLATE utf8_bin DEFAULT NULL,		`PROC_DEF_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,		`PROC_INST_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,		`EXECUTION_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,		`TASK_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,		`TIME_STAMP_` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),		`USER_ID_` varchar(255) COLLATE utf8_bin DEFAULT NULL,		`DATA_` longblob DEFAULT NULL,		`LOCK_OWNER_` varchar(255) COLLATE utf8_bin DEFAULT NULL,		`LOCK_TIME_` timestamp NULL DEFAULT NULL,		`IS_PROCESSED_` tinyint(4) DEFAULT 0,		PRIMARY KEY (`LOG_NR_`)	) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;');	prepare sqlstr from @sqlstr;	execute sqlstr;END

Screenshot of the execution process:

Results of the:

Written at the back:

Knowledge sharing is not manual labor, if you are unsure, don't mistake your children! ! ! ! !

If you find your solution in my article, please give me a thumbs up and don't let the wrong knowledge run rampant! ! ! !