为什么我的sql查询没有返回记录?

时间:2018-03-14 11:15:16

标签: sql oracle

架构:

创建了表部门

CREATE table dept
(dept_id varchar (20) default 'department' NOT NULL,
locat varchar (25) default 'location' NOT NULL,
nme varchar (20) default 'name' NOT NULL);

插入值

INSERT INTO dept(dept_id, locat, nme)
VALUES (1, 'dublin', 'payroll');

INSERT INTO dept(dept_id, locat, nme)
VALUES (2, 'galway', 'manufacturing');

INSERT INTO dept(dept_id, locat, nme)
VALUES (3, 'cork', 'sales');

创建了表emp

create table emp
(emp_id varchar (20) default 'id' NOT NULL,
NME varchar (20) default 'name' NOT NULL,
job_title varchar (25) default 'job' NOT NULL,
HIRE_DATE DATE,
SALARY INT (25) default '0' NOT NULL,
dept_id varchar (20) default 'dept' NOT NULL);

插入值

INSERT INTO emp
VALUES (123, 'byrne', 'clerical', DATE ('2012-06-12'), 28000, 1);

INSERT INTO emp 
VALUES (124, 'barry', 'operater', DATE ('11-07-11'), 33000,2);

INSERT INTO emp
VALUES (125, 'hynes', 'senior_operator', DATE ('26-09-13'), 36500,2);

INSERT INTO emp
VALUES (126, 'WILLIAMS', 'manager', DATE ('30-10-13'), 51000,3);

以下查询没有退回记录

SELECT NME FROM emp
where HIRE_DATE between ('01-01-10') AND ('01-01-14');

如何更改代码以获得所需的输出。

1 个答案:

答案 0 :(得分:2)

您正确的日期格式。在Oracle中,您可以使用date关键字引入常量:

INSERT INTO emp (emp_id, NME, job_title , HIRE_DATE, SALARY, dept_id)
  VALUES (123, 'byrne', 'clerical', DATE '2012-06-12', 28000, 1);

INSERT INTO emp (emp_id, NME, job_title , HIRE_DATE, SALARY, dept_id)
  VALUES (124, 'barry', 'operater', DATE '2011-07-11', 33000, 2);

INSERT INTO emp (emp_id, NME, job_title , HIRE_DATE, SALARY, dept_id)
  VALUES (125, 'hynes', 'senior_operator', DATE '2013-09-26', 36500, 2);

INSERT INTO emp (emp_id, NME, job_title , HIRE_DATE, SALARY, dept_id)
  VALUES (126, 'WILLIAMS', 'manager', DATE '2013-10-30', 51000, 3);

select NME
from emp
where HIRE_DATE between date '2010-01-01' and date '2014-01-01';

我认为在1999年出现两位数的年份。甲骨文可能不像你那样解释两位数的年份。

此外,在插入时包括列列表。