oracle 日期比较,只比较年月日怎么写?
1、创建测试表,
create table test_date_1(id number, v_date date);
create table test_date_2(id number, v_date date);
2、插入测试数据,
insert into test_date_1
select level, sysdate-level from dual connect by level<200;
insert into test_date_2
select level, sysdate-level from dual connect by level<100;
3、创建索引,
-- Create/Recreate indexes
create index idx_date_1 on TEST_DATE_1 (v_date);
-- Create/Recreate indexes
create index idx_date_2 on TEST_DATE_2 (v_date);
4、执行SQL,
select /*+use_index(t idx_date_1) use_index(b idx_date_2)*/
*
from TEST_DATE_1 t, TEST_DATE_2 b
where t.v_date < b.v_date + 1
and t.v_date > b.v_date - 1
5、按[F5]查看执行计划,可以看到索引是起到了。