A "hello world" to learn procedure


/ Published in: SQL
Save to your folder(s)

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');`


Copy this code and paste it in your HTML
  1. DELIMITER $$
  2.  
  3. DROP PROCEDURE IF EXISTS `hello` $$
  4. CREATE PROCEDURE `hello`()
  5. SQL SECURITY DEFINER
  6. COMMENT 'Hello World!'
  7. BEGIN
  8. DECLARE str VARCHAR(50);
  9. SET str = '你好!';
  10.  
  11. SELECT str AS 'HELLO';
  12. END $$
  13.  
  14.  
  15. DROP PROCEDURE IF EXISTS `globalHello` $$
  16. CREATE PROCEDURE `globalHello`(IN lang VARCHAR(10))
  17. COMMENT 'Say hello with multi-language'
  18. BEGIN
  19. DECLARE str VARCHAR(50);
  20.  
  21. SET lang = LOWER(TRIM(lang));
  22. CASE lang
  23. WHEN 'zh' THEN
  24. SET str = '你好!';
  25. WHEN 'en' THEN
  26. SET str = 'Hello!';
  27.  
  28. ELSE
  29. SET str = '[Hello]!';
  30. END CASE;
  31.  
  32. SELECT str AS 'HELLOWORLD' ;
  33. END $$
  34.  
  35. DELIMITER ;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.