Database Reference
In-Depth Information
INTO var_country_name
FROM country
WHERE code = param_country_code;
RETURN var_country_name;
END
//
We should note that our newly created function can be seen on the database's
Structure page, along with its friend, the add_page procedure:
Testing the function
On testing this function:
SELECT CONCAT('ca->', get_country_name('ca'), ', zz->',
get_country_name('zz')) as test;
We get this result:
ca->Canada, zz->not found
Exporting stored procedures and functions
When exporting a database, procedures and functions do not appear (by default) in
an SQL export. A checkbox, Add CREATE PROCEDURE / FUNCTION / EVENT ,
exists in the Structure dialog of the Export page, to include those in the SQL export
file. If we try it, we obtain:
DELIMITER $$
--
-- Procedures
--
CREATE DEFINER=`marc`@`%` PROCEDURE `add_page`(IN param_isbn
VARCHAR(25), IN param_pages INT, OUT param_message VARCHAR(100))
BEGIN
IF param_pages > 100 THEN
SET param_message = 'the number of pages is too big';
ELSE
UPDATE book SET page_count = page_count + param_pages WHERE
isbn=param_isbn;
SET param_message = 'success';
 
Search WWH ::




Custom Search