例子:发送短信(存储过程)

  1. BEGIN
  2. DECLARE Done INT DEFAULT 0;
  3. DECLARE exdate datetime;
  4. DECLARE textdata text;
  5. DECLARE m_time datetime;
  6. DECLARE b_num varchar(20);
  7. DECLARE telwq varchar(20);
  8. DECLARE telhb varchar(20);
  9. DECLARE telsj varchar(20);
  10. DECLARE cc int;
  11. DECLARE rs CURSOR FOR SELECT
  12. a.F25 AS b_num,
  13. b.F11 AS m_time
  14. FROM S62.T6230 AS a,S62.T6231 as b
  15. WHERE a.F01=b.F01 AND b.F11 BETWEEN DATE_SUB(NOW(),INTERVAL 30 minute) AND NOW();
  16. DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1;
  17. SET telwq=13760836670;
  18. SET telhb=15920149039;
  19. SET telsj=13808870034;
  20. SET exdate = (SELECT DATE_ADD(NOW(),INTERVAL 30 minute));
  21. IF (SELECT COUNT(a.F01) FROM S62.T6230 AS a,S62.T6231 as b WHERE a.F01=b.F01 AND b.F11 BETWEEN DATE_SUB(NOW(),INTERVAL 30 minute) AND NOW()) > 0
  22. THEN
  23. OPEN rs;
  24. FETCH NEXT FROM rs INTO b_num,m_time;
  25. REPEAT
  26. SET textdata = (SELECT CONCAT('标编号为"',b_num,'"的标已于"',m_time,'"满标,请登录后台进行放款操作。'));
  27. -- WQ
  28. INSERT INTO
  29. S10._1040 (F02,F03,F04,F05,F06)
  30. VALUES (0,textdata,NOW(),'W',exdate);
  31. SET cc =(SELECT @@IDENTITY);
  32. INSERT INTO
  33. S10._1041 (F01,F02)
  34. VALUES (cc,telwq);
  35. -- HB
  36. INSERT INTO
  37. S10._1040 (F02,F03,F04,F05,F06)
  38. VALUES (0,textdata,NOW(),'W',exdate);
  39. SET cc =(SELECT @@IDENTITY);
  40. INSERT INTO
  41. S10._1041 (F01,F02)
  42. VALUES (cc,telhb);
  43. -- SJ
  44. INSERT INTO
  45. S10._1040 (F02,F03,F04,F05,F06)
  46. VALUES (0,textdata,NOW(),'W',exdate);
  47. SET cc =(SELECT @@IDENTITY);
  48. INSERT INTO
  49. S10._1041 (F01,F02)
  50. VALUES (cc,telsj);
  51. FETCH NEXT FROM rs INTO b_num,m_time;
  52. UNTIL Done END REPEAT;
  53. CLOSE rs;
  54. END IF;
  55. END





posted @ 2017-01-17 14:27  糖饼好吃  阅读(416)  评论(0编辑  收藏  举报