Return a computed value from SQL code.

Section: stored procedures and functions

Create a scalar function

sql
sql
DELIMITER $$
CREATE FUNCTION full_label(p_first VARCHAR(100), p_last VARCHAR(100))
RETURNS VARCHAR(255)
DETERMINISTIC
BEGIN
  RETURN CONCAT(p_first, ' ', p_last);
END $$
DELIMITER ;
Explanation

Stored functions can be used inside SELECTs and other expressions.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing stored procedures and functions
Change the statement delimiter
Define routines containing semicolons.
OpenIn sheetsqlsame section
Call a stored procedure
Execute a procedure with input arguments.
OpenIn sheetsqlsame section
List stored procedures
Display procedures visible in a schema.
OpenIn sheetsqlsame section
Show procedure definition
Display the CREATE PROCEDURE statement for an existing routine.
OpenIn sheetsqlsame section
Create a BEFORE INSERT trigger
Normalize row data before insert.
List triggers
Display triggers defined in the current schema.