首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 网络资源 > MySQL中这样创建存贮过程(procedure)
【标  题】:MySQL中这样创建存贮过程(procedure)
【关键字】:MySQL,procedure
【来  源】:http://blog.csdn.net/iqueen/archive/2006/06/12/792306.aspx

MySQL中这样创建存贮过程(procedure)

  1. DROP PROCEDURE IF EXISTS sp_unit_by_sec_class;
  2. delimiter //
  3. CREATE PROCEDURE sp_unit_by_sec_class(DICT_ID INT,ORDER_BY INT)
  4. BEGIN
  5.     IF (ORDER_BY = 1)
  6.         THEN
  7.             SELECT * FROM
  8.             (
  9.                 SELECT e.unit_id,e.unit_price,e.cr_date,e.USER_NAME,e.unit_memo,e.unit_status
  10.                 FROM t_units e
  11.                 WHERE e.dict_id = DICT_ID
  12.                
  13.                 UNION
  14.                 SELECT c.unit_id,d.drop_fee-d.grow_fee,d.drop_date,d.USER_NAME,drop_memo,c.unit_status
  15.                 FROM t_units c
  16.                 RIGHT JOIN t_drop d ON c.unit_id = d.unit_id
  17.                 WHERE c.dict_id = DICT_ID
  18.  
  19.                 UNION
  20.                 SELECT a.unit_id,b.grow_fee,b.grow_date,b.USER_NAME,b.grow_memo,2
  21.                 FROM t_units a
  22.                 RIGHT JOIN t_grow b ON a.unit_id = b.unit_id
  23.                 WHERE a.dict_id = DICT_ID
  24.             ) t1 ORDER BY 1,3;
  25.         ELSE
  26.             SELECT * FROM
  27.             (
  28.                 SELECT e.unit_id,e.unit_price,e.cr_date,e.USER_NAME,e.unit_memo,e.unit_status
  29.                 FROM t_units e
  30.                 WHERE e.dict_id = DICT_ID
  31.                
  32.                 UNION
  33.                 SELECT c.unit_id,d.drop_fee-d.grow_fee,d.drop_date,d.USER_NAME,drop_memo,c.unit_status
  34.                 FROM t_units c
  35.                 RIGHT JOIN t_drop d ON c.unit_id = d.unit_id
  36.                 WHERE c.dict_id = DICT_ID
  37.  
  38.                 UNION
  39.                 SELECT a.unit_id,b.grow_fee,b.grow_date,b.USER_NAME,b.grow_memo,2
  40.                 FROM t_units a
  41.                 RIGHT JOIN t_grow b ON a.unit_id = b.unit_id
  42.                 WHERE a.dict_id = DICT_ID
  43.             ) t1 ORDER BY 3,1;
  44.     END IF;
  45. END
  46. ;
  47. //
  48. delimiter ;
上周技术关注:O/R Mapping乱弹:【上一篇】
关于我的发展方向:【下一篇】
【相关文章】
  • 将图片储存在MySQL数据库里
  • apache2.2+mysql5.0+php5.1+Discuz!4.1配置完全手册
  • 终于解决了jsp连接mysql的中文编码问题!
  • MySQL性能优化
  • MySQL的加密函数
  • RedHatAS4下Apache2+MySQL+Php+Tomcat整合及虚拟主机配置
  • MySQL的日期时间函数
  • 提高MySQL 数据库性能的思路
  • konds-apache1.3.31-php2.4.8-resin2.-mysql.conf
  • Cold-installation procedure step by step
  • 【随机文章】
  • 邂逅
  • 经典C程序100例==31--40
  • 网站开发简单规范
  • 如何编写有效测试用例
  • 突破QQ端口封锁
  • 新开传奇世界私服
  • 漫谈IBM pSeries的逻辑分区和动态逻辑分区(一)
  • [Javascript] CSDN的错误页面跳转
  • Tripwire应用
  • netfilter效率真的好差
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.