为什么在oracle服务器apres logging上直接输入命令行的结果不一样
/u01/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus
*vis/passwd@10.252.41.123:1521/AA*
SQL> select count(*) from dispo where period = to_date('2017-10-01','YYYY-MM-DD') ;
result : 0
当我使用 Oracle sql developper 软件与 vis /passwdv@10.252.41.123:1521 / AA 相同的连接时?
select count(*) from dispo where period = to_date('2017-10-01','YYYY-MM-DD')
result : 20000
答案 0 :(得分:0)
您的SQL * Plus和SQL Developer会话位于或认为它们位于不同的时区。
您用于过滤器的静态日期将隐式转换为本地时区。当在SQL * Plus会话/时区中发生这种情况时,它仍然与您存储的时间戳匹配。在SQL Developer会话/时区中执行此操作时,它不匹配。
您可以通过更改会话设置在单个会话中演示此内容,并在UTC会话中创建一个虚拟行:
create table dispo (id number, period timestamp(6) with local time zone);
alter session set time_zone = 'UTC';
insert into dispo (id, period) values (1, timestamp '2017-10-01 00:00:00');
然后在同一时区查询会看到该数据:
alter session set time_zone = 'UTC';
select cast(date '2017-01-01' as timestamp with local time zone) as local_time from dual;
LOCAL_TIME
-------------------
2017-01-01 00:00:00
select * from dispo where period = date '2017-10-01';
ID PERIOD
---------- -------------------
1 2017-10-01 00:00:00
但是在不同的时区查询不会:
alter session set time_zone = 'Europe/London';
select cast(date '2017-01-01' as timestamp with local time zone) as local_time from dual;
LOCAL_TIME
-------------------
2017-01-01 00:00:00
select * from dispo where period = date '2017-10-01';
no rows selected
您可以通过指定固定值所在的时区来避免这种情况:
alter session set time_zone = 'UTC';
select * from dispo where period = timestamp '2017-10-01 00:00:00 UTC';
ID PERIOD
---------- -------------------
1 2017-10-01 00:00:00
alter session set time_zone = 'Europe/London';
select * from dispo where period = timestamp '2017-10-01 00:00:00 UTC';
ID PERIOD
---------- -------------------
1 2017-10-01 00:00:00
显然使用数据实际创建的时区...