Skip to content

PROCEDURE

DELIMITER //
CREATE PROCEDURE GetCount(
IN table_name VARCHAR(50)
)
BEGIN
SET @s = CONCAT('SELECT COUNT(*) FROM ',table_name);
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END //
DELIMITER ;
Terminal window
Query OK, 0 rows affected (0.00 sec)

The above SQL code block creates a stored procedure named ‘GetCount’ that accepts a table name and returns the count of rows in the table. In this procedure, a SQL query is prepared as a string and then executed to get the desired output. In the output block shows the successful creation of the procedure.