Chinaunix首页 | 论坛 | 博客
  • 博客访问: 598295
  • 博文数量: 825
  • 博客积分: 5000
  • 博客等级: 大校
  • 技术积分: 4980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-27 14:19
文章分类

全部博文(825)

文章存档

2011年(1)

2008年(824)

我的朋友

分类:

2008-10-27 14:28:35


  9i安装默认的日期格式是‘DD-MM-RR’,这个可以通过
  select * from sys.nls_database_parameters;
  
  进行查看。
  
  因此对于输入参数为DATE类型的过程就出现问题了,其中查询基本表(tranficstat)里记录日期格式为‘yyyy-mm-dd’。原码如下:
  
  --比较某两个车站相同时间段的运力情况
  
  create or replace procedure HY_CONTRAST_PERIOD(
  depotcode1 in varchar2,
  depotcode2 in varchar2,
  startdate1 in date,
  enddate1 in date,
  cur_return out CUR_DEFINE.GB_CUR) is --CUR_DEFINE.GB_CUR 是自定义的游标类型
  begin
  case
  when (depotcode1 is null) or (depotcode2) is null then
  return;
  else
  open cur_return for
  select
  sum(NORMAL_SCHEMES) as 正班班次,
  sum(OVERTIME_SCHEMES) as 加班班次,
  sum(NORMAL_SEATS) as 正班座位数,
  sum(OVERTIME_SEATS) as 加班座位数
  from tranficstat
  where senddate >= startdate1
  and senddate < enddate1+ 1
  and depot = depotcode1
  group by depot
  
  union
  
  select
  sum(NORMAL_SCHEMES) as 正班班次,
  sum(OVERTIME_SCHEMES) as 加班班次,
  sum(NORMAL_SEATS) as 正班座位数,
  sum(OVERTIME_SEATS) as 加班座位数
  from tranficstat
  where senddate >= startdate1
  and senddate < enddate1 + 1
  and depot = depotcode2
  group by depot;
  end case;
  end HY_CONTRAST_PERIOD;
  
  通过union,你期望返回两条记录,却发现永远总是只返回一条记录。问题症结发生在日期格式转换上,参数传进的格式为‘dd-mm-rr’,而条件左侧的记载格式为‘yyyy-mm-dd’,只要把所有右侧条件更改成如
  
  where senddate >= to_date(to_char(startdate1,'yyyy-mm-dd'),'yyyy-mm-dd')
  and senddate < to_date(to_char(enddate1,'yyyy-mm-dd'),'yyyy-mm-dd') + 1;
  
  即可消除症状。
  
  当然也可以修改左侧的格式,总之使两边的日期格式匹配;另外当然也可以直接修改系统的NLS_DATE_FORMAT 。
【责编:admin】

--------------------next---------------------

阅读(454) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~