Return to Snippet

Revision: 67785
at October 30, 2014 02:24 by jacktan


Initial Code
DELIMITER $$

DROP PROCEDURE IF EXISTS `hello` $$
CREATE PROCEDURE `hello`()
  SQL SECURITY DEFINER
  COMMENT 'Hello World!'
BEGIN
  DECLARE str VARCHAR(50);
  SET str = '你好!';
  
  SELECT str AS 'HELLO';
END $$


DROP PROCEDURE IF EXISTS `globalHello` $$
CREATE PROCEDURE `globalHello`(IN lang varchar(10))
  COMMENT 'Say hello with multi-language'
BEGIN
  DECLARE str VARCHAR(50);
  
  SET lang = LOWER(TRIM(lang));
  CASE lang
    WHEN 'zh' THEN
      SET str = '你好!';
    WHEN 'en' THEN
      SET str = 'Hello!';
    
    ELSE
      SET str = '[Hello]!';
  END CASE;
  
  SELECT str AS 'HELLOWORLD' ;
END $$

DELIMITER ;

Initial URL

                                

Initial Description
Before calling the PROCEDUREs you created, use `SHOW PROCEDURE status;` to confirm.

To use these procedure, use the script like `CALL hello();` and `CALL globalHello('EN');`

Initial Title
A "hello world" to learn procedure

Initial Tags

                                

Initial Language
SQL