Oracle兼容-存储过程-CREATE OR REPLACE


1. 语法

  1. CREATE OR REPLACE PROCEDURE proc_name ...
  2. CREATE OR REPLACE FUNCTION func_name ...

2. 定义和用法

GreatSQL支持 CREATE OR REPLACE 创建存储过程/存储函数,无论是在 DEFAULT 还是 ORACLE 模式均支持。

3. 示例

  1. -- 1. DEFAULT模式
  2. greatsql> DELIMITER //
  3. greatsql> SET sql_mode = DEFAULT; //
  4. greatsql> CREATE OR REPLACE PROCEDURE p1()
  5. BEGIN
  6. SELECT 3306 AS PORT FROM DUAL;
  7. END;//
  8. greatsql> CALL p1()//
  9. +------+
  10. | PORT |
  11. +------+
  12. | 3306 |
  13. +------+
  14. -- DEFAULT模式下还支持不带BEGIN ... END语句
  15. greatsql> CREATE OR REPLACE PROCEDURE p1()
  16. SELECT 3306 AS PORT FROM DUAL; //
  17. greatsql> CALL p1()//
  18. +------+
  19. | PORT |
  20. +------+
  21. | 3306 |
  22. +------+
  23. -- 2. ORACLE模式
  24. greatsql> SET sql_mode = ORACLE; //
  25. greatsql> CREATE OR REPLACE PROCEDURE p2()
  26. AS
  27. BEGIN
  28. SELECT 3306 AS PORT FROM DUAL;
  29. END; //
  30. greatsql> CALL p2()//
  31. +------+
  32. | PORT |
  33. +------+
  34. | 3306 |
  35. +------+
  36. -- DEFAULT模式不同,在ORACLE模式下不支持不带BEGIN ... END语句
  37. greatsql> CREATE OR REPLACE PROCEDURE p2()
  38. AS
  39. SELECT 3306 AS PORT FROM DUAL;
  40. //
  41. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 3306 AS PORT FROM DUAL' at line 3

问题反馈

联系我们

扫码关注微信公众号

greatsql-wx