sql语句如何查日期字段的某天的数据?

如题所述

第1个回答  2022-11-16

1、创建测试表,

create table test_date(id varchar2(20), v_date date);

2、插入测试数据

insert into test_date values(1, to_date('2010-9-23 10:10:10','yyyy-mm-dd hh24:mi:ss'));

insert into test_date values(2, to_date('2010-9-24 10:10:10','yyyy-mm-dd hh24:mi:ss'));

insert into test_date values(3, to_date('2010-9-25 10:10:10','yyyy-mm-dd hh24:mi:ss'));

insert into test_date values(4, to_date('2010-9-26 10:10:10','yyyy-mm-dd hh24:mi:ss'));

insert into test_date values(5, to_date('2010-9-27 10:10:10','yyyy-mm-dd hh24:mi:ss'));

commit;


3、查询表中全量数据,select t.*, rowid from test_date t;

4、编写sql,查询日期为2010-9-23的数据;

   select t.* from test_date t where to_char(v_date,'yyyymmdd') = 20100923;

相似回答