mysql 存储过程例子

浅浅的花香味﹌ 2022-04-17 04:17 294阅读 0赞

mysql 存储过程例子(当前我使用的是mysql 5.5)

这是我平身第一次写mysql的存储过程,不外乎先照着别人写的模仿呗!
汗!

存储过程如下:

  1. create procedure proc_name(in parameter integer)
  2. BEGIN
  3. declare variable varchar(20);
  4. if parameter=1 THEN
  5. set variable='mysql';
  6. ELSE
  7. set variable='java';
  8. end if;
  9. insert into tb(name) values (variable);
  10. end
  11. 测试语句:
  12. call proc_name(3);
  13. create procedure abin(in parameter int)
  14. BEGIN
  15. if parameter=1 THEN
  16. select * from tb order by id asc;
  17. ELSE
  18. select * from test order by id asc;
  19. end if;
  20. end;
  21. 测试语句:
  22. call abin(2);
  23. create procedure abin_1(in parameter int)
  24. BEGIN
  25. declare variable varchar(20);
  26. if parameter=1 THEN
  27. set variable='windows';
  28. ELSE
  29. set variable='linux';
  30. end if;
  31. select parameter;
  32. end;
  33. 测试语句:
  34. call abin_1(1);
  35. call abin_1(2);
  36. create procedure bing()
  37. BEGIN
  38. DECLARE temp int;
  39. set temp='java';
  40. update tb set name='abin' where id=1;
  41. end;

发表评论

表情:
评论列表 (有 0 条评论,294人围观)

还没有评论,来说两句吧...

相关阅读