数据都有date(thedate)这一栏属性,我需要怎么做实现获得指定date范围内的数据呢?
我使用select * from tb where thedate > to_date(开始时间,格式) and thedate < to_date(结束时间,格式)
不行,暂时没有找到类似的例子,请哪位指点一下,谢谢。
我使用select * from tb where thedate > to_date(开始时间,格式) and thedate < to_date(结束时间,格式)
不行,暂时没有找到类似的例子,请哪位指点一下,谢谢。
select * from tb
where thedate>to_date('2011-01-01','yyyy-mm-dd') and
thedate<to_date('2011-04-09','yyyy-mm-dd')
order by thedate;
SQL> select * from emp
2 order by hiredate;EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7369 SMITH CLERK 7902 1980-12-17 800.00 20
7499 ALLEN SALESMAN 7698 1981-2-20 1600.00 300.00 30
7521 WARD SALESMAN 7698 1981-2-22 1250.00 500.00 30
7566 JONES MANAGER 7839 1981-4-2 2975.00 20
7698 BLAKE MANAGER 7839 1981-5-1 2850.00 30
7782 CLARK MANAGER 7839 1981-6-9 2450.00 10
7844 TURNER SALESMAN 7698 1981-9-8 1500.00 0.00 30
7654 MARTIN SALESMAN 7698 1981-9-28 1250.00 1400.00 30
7839 KING PRESIDENT 1981-11-17 5000.00 10
7900 JAMES CLERK 7698 1981-12-3 950.00 30
7902 FORD ANALYST 7566 1981-12-3 3000.00 20
7934 MILLER CLERK 7782 1982-1-23 1300.00 10
7788 SCOTT ANALYST 7566 1987-4-19 3000.00 20
7876 ADAMS CLERK 7788 1987-5-23 1100.00 20SQL> select * from emp
2 where hiredate >= to_date('1981-05-01','yyyy-mm-dd') and
3 hiredate <= to_date('1982-02-01','yyyy-mm-dd')
4 order by hiredate;EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7698 BLAKE MANAGER 7839 1981-5-1 2850.00 30
7782 CLARK MANAGER 7839 1981-6-9 2450.00 10
7844 TURNER SALESMAN 7698 1981-9-8 1500.00 0.00 30
7654 MARTIN SALESMAN 7698 1981-9-28 1250.00 1400.00 30
7839 KING PRESIDENT 1981-11-17 5000.00 10
7900 JAMES CLERK 7698 1981-12-3 950.00 30
7902 FORD ANALYST 7566 1981-12-3 3000.00 20
7934 MILLER CLERK 7782 1982-1-23 1300.00 10
1/2/2011 4:15:20 pm
这样的格式,不知道那个pm该怎么处理格式呢,如果楼上的朋友看到,请告知一下,谢谢哦
--使用to_timestamp函数将sysdate转换为这种格式:dd/mm/yyyy hh24:mi:ss pm[am]
select to_timestamp(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') from dual;
TO_TIMESTAMP(TO_CHAR(SYSDATE,
--------------------------------------------------------------------------------
10-4月 -11 07.32.15.000000000 上午
--localtimestamp()函数可以做到
SQL> select localtimestamp from dual;LOCALTIMESTAMP
--------------------------------------------------------------------------------
10-4月 -11 08.24.09.750000 上午