我想选择'20-FEB-81'和'01 -MAY-81'之间的工作

时间:2011-09-10 16:17:57

标签: sql oracle sqlplus

我想要雇员的姓名,工作,在'20-FEB-81'和'01 -MAY-81'之间雇用,并按升序排列

查询我跑错了

SQL> select ename, job, hiredate where hiredate between '20-FEB-81' AND '01-MAY-81'   from emp;
select ename, job, hiredate where hiredate between '20-FEB-81' AND '01-MAY-81' from emp
                        *
 ERROR at line 1:
 ORA-00923: FROM keyword not found where expected


 SQL>

我的桌子      SQL>选择empno,ename,job,hiredate,sal from emp;

 EMPNO ENAME      JOB       HIREDATE         SAL
 ---------- ---------- --------- --------- ----------
  7839 KING       PRESIDENT 17-NOV-81       5000
  7698 BLAKE      MANAGER   01-MAY-81       2850
  7782 CLARK      MANAGER   09-JUN-81       2450
  7566 JONES      MANAGER   02-APR-81       2975
  7654 MARTIN     SALESMAN  28-SEP-81       1250
  7499 ALLEN      SALESMAN  20-FEB-81       1600
  7844 TURNER     SALESMAN  08-SEP-81       1500
  7900 JAMES      CLERK     03-DEC-81        950
  7521 WARD       SALESMAN  22-FEB-81       1250
  7902 FORD       ANALYST   03-DEC-81       3000
  7369 SMITH      CLERK     17-DEC-80        800

 EMPNO ENAME      JOB       HIREDATE         SAL
 ---------- ---------- --------- --------- ----------
  7788 SCOTT      ANALYST   09-DEC-82       3000
  7876 ADAMS      CLERK     12-JAN-83       1100
  7934 MILLER     CLERK     23-JAN-82       1300

 14 rows selected.

 SQL>

1 个答案:

答案 0 :(得分:6)

WHERE部分在之后 部分。

select ename, job, hiredate 
from emp
where hiredate between '20-FEB-81' AND '01-MAY-81'

请注意,如果NLS设置发生更改,您的日期文字可能并不总是有效。强烈建议使用to_date()。

select ename, job, hiredate 
from emp
where hiredate between to_date('20-FEB-81', 'DD-MON-RR') AND to_date('01-MAY-81', 'DD-MON-RR')

但这仍然受语言设置问题的影响,最好不要使用月份名称

select ename, job, hiredate 
from emp
where hiredate between to_date('20-02-81', 'DD-MM-RR') AND to_date('01-05-81', 'DD-MM-RR')