This will work when you want to return multiple values.
DROP TABLE IF EXISTS Filename;
CREATE TABLE Filename(
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO Filename(name) VALUES ('AAA'), ('BBB'), ('CCC'), ('DDD'), ('EEE');
DELIMITER //
DROP PROCEDURE IF EXISTS GenerateFileNumber//
CREATE PROCEDURE GenerateFileNumber(p_name VARCHAR(255))
COMMENT 'Gets the file number associated with the given name'
BEGIN
DECLARE v_id BIGINT;
DROP TABLE IF EXISTS ReturnValues;
CREATE TEMPORARY TABLE ReturnValues (
val1 BIGINT(20) UNSIGNED,
str1 VARCHAR(255)
);
SELECT id INTO v_id FROM Filename WHERE name = p_name;
INSERT INTO ReturnValues(val1, str1) VALUES (v_id, 'Moop');
END;
//
DROP PROCEDURE IF EXISTS TestCall//
CREATE PROCEDURE TestCall(p_name VARCHAR(255))
COMMENT 'Tests function call within a procedure'
BEGIN
DECLARE v_id BIGINT;
DECLARE v_str VARCHAR(255);
CALL GenerateFileNumber(p_name);
SELECT val1, str1 INTO v_id, v_str FROM ReturnValues;
SELECT 'Returns: ' || COALESCE(v_id, 'none') || ', ' || v_str AS msg;
END;
//
DELIMITER ;
In general, though, the previous function-based answer should be used when possible. It runs faster, and you don't need to worry about accidentally clobbering your temp table.
mysql> call TestCall('AAA');
+------------------+
| msg |
+------------------+
| Returns: 1, Moop |
+------------------+
1 row in set (0.27 sec)
Query OK, 0 rows affected (0.27 sec)
mysql> call TestCall('CCC');
+------------------+
| msg |
+------------------+
| Returns: 3, Moop |
+------------------+
1 row in set (0.17 sec)
Query OK, 0 rows affected (0.17 sec)