Skip to main content

Using Parameters

Procedures Without Parameters

If a stored procedure does not require input, define it with empty parentheses following the procedure name.

drop procedure if exists sp_DBR_hello_world
$$
create procedure sp_DBR_hello_world()
begin

select 'hello world!';

end
$$

call sp_DBR_hello_world();
+--------------+
| Hello World! |
+--------------+
| Hello World! |
+--------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Procedures With Parameters

Input parameters are defined as a comma-separated list of "name type" pairs within the parentheses. It is recommended to use a prefix (such as in_) to distinguish parameters from column names and improve code readability.

drop procedure if exists sp_DBR_show_value$$
create procedure sp_DBR_show_value( in_value int )
begin

select concat('The value is ', in_value) as 'Value';

end
$$

call sp_DBR_show_value(1971);
+-------------------+
| Value |
+-------------------+
| The value is 1971 |
+-------------------+