Delimiter //
/**
 * Author:  armen
 * Created: 26 oct. 2018
 * usage: 
 * call CASH_CHECK_TABLE_EXISTENCE('MyTableName', @tableExistResult);
 */
Drop Procedure if exists CASH_CHECK_TABLE_EXISTENCE//
CREATE PROCEDURE CASH_CHECK_TABLE_EXISTENCE (
            IN tableName varchar(64)
            , out table_exists Int
        )
BEGIN
    DECLARE CONTINUE HANDLER FOR SQLSTATE '42S02' SET @cte_err = 1;
    SET @cte_err = 0;
    SET @cte_table_name = tableName;
    SET @cte_sql_query = CONCAT('SELECT NULL FROM ', @cte_table_name, ' Limit 1');
    PREPARE stmt1 FROM @cte_sql_query;
    IF (@cte_err = 1) THEN
        SET @cte_table_exists = 0;
    ELSE
        SET @cte_table_exists = 1;
        DEALLOCATE PREPARE stmt1;
    END IF;
    Set table_exists = @cte_table_exists;
END //
Delimiter ;