最好不要这么写: begin_date:=to_date('20030101','yyyymmdd'); end_date:=to_date('20030201','yyyymmdd'); 应该这么写: select to_date('20030101','yyyymmdd'),to_date('20030101','yyyymmdd') into :begin_date,:end_date from dual;
and a.proc_date>=begin_date and a.proc_date<(end_date+1)或 a.proc_date between begin_date and (end_date+1)
给你查了一下,begin_date,end_date均不是关键字。SQL> select tname from col where cname='BEGIN_DATE' or cname='END_DATE';no rows selected.
and to_date(to_char(a.proc_date, 'yyyymmdd'),'yyyymmdd') >= begin_date
and to_date(to_char(a.proc_date, 'yyyymmdd'),'yyyymmdd') < end_date
不同,正确值是8条,可用了变量就会3条,过了一段时间又变成了22条
数据库里的记录肯定没变。
and to_char(a.proc_date, 'yyyymmdd') >= to_char(begin_date,'yyyymmdd')
and to_char(a.proc_date, 'yyyymmdd') < to_char(end_date,'yyyymmdd')
然后to_char(a.proc_date, 'yyyymmdd') >= begin_date ...
begin_date:=to_date('20030101','yyyymmdd');
end_date:=to_date('20030201','yyyymmdd');
应该这么写:
select to_date('20030101','yyyymmdd'),to_date('20030101','yyyymmdd') into :begin_date,:end_date from dual;
and a.proc_date<(end_date+1)或
a.proc_date between begin_date and (end_date+1)
end_date event_info .proc_date%type;
begin_date event_info .proc_date%type;
to: shuipipi(水皮皮) 没有报错,就是结果不对,
不一样。
就是和to_date不一样,我真的开始怀疑to_date错了
这个错误我查出来后肯定告诉大家,最大的魔鬼就是:
让你开始怀疑自己的眼睛!
1、begin_date 和end_date被你定义为全局变量了,而且会经常发生变化。出现这种情况最有可能的是使用了PACKAGE,而且在PACKAGE 头的部分定义了着两个变量。
测试:将变量名(begin_date,end_date)改一改(Bda,Eda),看结果是否正确,如果正确,则基本上可以验证我的推断。
2、Oracle设置了默认的日期型变量的格式或数据库列的格式不是DATE型。
测试:采用 lynx(lynx)的方法,重新定义变量,如果结果正确,基本上可以断定是这个原因。
end_date event_info .proc_date%type;
begin_date event_info .proc_date%type;
3、Oracle系统出现问题,Pl/sql机制遭到破坏。(可能不大)
测试:在存储过程前面加几个空行,或其他什么语句,将查询的Where的条件颠倒顺序,再查看结果是否正确了。(将语句再写一便也可,但不要粘贴)
4、Oracle问题,说明给变量赋值的to_date与sql中的to_date不是一个函数。
测试:分别写赋值语句和查询语句得到to_date的值,看两者是否一样。
begin_date:=to_date('20030101','yyyymmdd');
Select to_date('20030101','yyyymmdd') into end_date from dual;
比较两个变量的值是否一样(注意分秒)
4、病毒你说的确实很奇怪,好好检查一下,是不是写错了,比如:给变量赋值的to_date是不是跟sql语句中的to_date写的一样。