对于很多人来说,oracle中的时间处理,向来是一个很模糊的概念,我也是,记下来做参考。
1.建立一张含日期类型的表
create table test_user(
user_id number(15),
user_name varchar2(30),
start_date date,
end_date date,
p_is_validate varchar2(2)
);
2.插入数据,解决怎样插入日期格式的记录
insert into test_user values(1,'denny',to_date('2010-1-1','YYYY-MM-DD'),to_date('2010-10-1','YYYY-MM-DD'),'Y');
insert into test_user values(2,'anny',to_date('2010/7/11','YYYY/MM/DD'),to_date('2010/8/8','YYYY/MM/DD'),'Y');
insert into test_user values(3,'damon',to_date('2010-2','YYYY-MM'),to_date('2010-12','YYYY-MM'),'Y');
insert into test_user values(4,'anny',to_date('2010-7-11 11:20:20','YYYY-MM-DD HH:MI:SS'),to_date('2010-7-11 15:21:21','YYYY-MM-DD HH24:MI:SS'),'Y');
3.查询
select * from test_user;
select * from test_user where sysdate between start_date and end_date;
select to_char(start_date,'YYYY/MM/DD') from test_user;