drop table if exists stblname ; create table stblname(tbl_id integer, Tbl_Name varchar(30)); DELIMITER $$ DROP PROCEDURE IF EXISTS `Gen_Table_Name`$$ CREATE PROCEDURE `Gen_Table_Name`( OUT o_TableName VARCHAR(30)) BEGIN DECLARE v_Tbl_Name VARCHAR(30); DECLARE v_TName VARCHAR(30); DECLARE v_TINT INTEGER; DECLARE v_TNint INTEGER; DECLARE V_No_Data INTEGER DEFAULT 1; DECLARE No_Data_Found CONDITION FOR 1329; DECLARE CONTINUE HANDLER FOR No_Data_Found SET v_No_Data = -1; BEGIN SELECT Tbl_Name INTO v_Tbl_Name FROM stblname WHERE Tbl_Id IN (SELECT MAX(Tbl_Id) FROM Stblname); IF V_NO_DATA = -1 THEN SET V_No_Data = 1; SET v_TINT = 123456789; ELSE SET v_TINT = SUBSTR(v_Tbl_Name,8,30); END IF; SET v_TNint = v_TINT + 1; SET v_TName = Concat(Upper('SN_TEMP'),v_TNint); INSERT INTO stblname(Tbl_Name) VALUES(Upper(v_TName)); SET o_TableName = v_TName; END; END$$ DROP PROCEDURE IF EXISTS `Genrate_Table`$$ CREATE PROCEDURE `Genrate_Table` ( OUT o_Table_Name VARCHAR(30), OUT o_OutputStatus INTEGER, OUT o_OutputMessage VARCHAR(100) ) BEGIN DECLARE v_Table_Name VARCHAR(30); DECLARE v_Tbl_Name VARCHAR(30); DECLARE v_TName VARCHAR(30); DECLARE v_TINT INTEGER; DECLARE v_TNint INTEGER; DECLARE o_TableName VARCHAR(30); DECLARE v_INTableName VARCHAR(30); DECLARE V_No_Data INTEGER DEFAULT 1; DECLARE No_Data_Found CONDITION FOR 1329; DECLARE CONTINUE HANDLER FOR No_Data_Found SET v_No_Data = -1; # SET o_OutputMessage = 'LEFT FROM PROC'; BEGIN CALL Gen_Table_Name(v_INTableName); SET v_Table_Name = v_INTableName; END; set @s = concat('CREATE TABLE ', upper(v_Table_Name), '(USER_ID VARCHAR(20),USER_IP VARCHAR(20), Login_Time DATE, Logout_Time DATE, Session_Id VARCHAR(20), Server_Ip VARCHAR(20))'); SET o_Table_Name = v_Table_Name; SET o_OutputStatus = 0; SET o_OutputMessage = 'SUCCESS'; prepare stmt from @s; execute stmt; deallocate prepare stmt; END $$ DELIMITER ; call Genrate_Table (@o_Table_Name,@o_OutputStatus,@o_OutputMessage);