0

可能重复:
在 Oracle SQL 中比较日期

当我处理 DATE 数据类型时,where 子句没有区别。以下代码显示所有 107 行。它应该显示大约 5 行。也没有语法错误。Where 子句适用于数字、字符等。

    select last_name,hire_date
    from employees
    where hire_date < '01-JAN-90'
4

2 回答 2

2

尝试适当的日期文字

select last_name,hire_date
from employees
where hire_date < DATE '1990-01-01'

这是一个正在运行的示例:http ://sqlfiddle.com/#!4/782c0/1

CREATE TABLE Employees (
  last_name VARCHAR(50),
  hire_date DATE
);

INSERT INTO Employees VALUES ('A', DATE '1985-01-01');
INSERT INTO Employees VALUES ('B', DATE '1986-01-01');
INSERT INTO Employees VALUES ('C', DATE '1987-01-01');
INSERT INTO Employees VALUES ('D', DATE '1988-01-01');
INSERT INTO Employees VALUES ('E', DATE '1989-01-01');
INSERT INTO Employees VALUES ('F', DATE '1990-01-01');
INSERT INTO Employees VALUES ('G', DATE '1991-01-01');
INSERT INTO Employees VALUES ('H', DATE '1992-01-01');
INSERT INTO Employees VALUES ('I', DATE '1993-01-01');
INSERT INTO Employees VALUES ('J', DATE '1994-01-01');
INSERT INTO Employees VALUES ('K', DATE '1995-01-01');
INSERT INTO Employees VALUES ('L', DATE '1996-01-01');
INSERT INTO Employees VALUES ('M', DATE '1997-01-01');
INSERT INTO Employees VALUES ('N', DATE '1998-01-01');


select last_name,hire_date
from employees
where hire_date < DATE '1990-01-01'
于 2013-01-22T17:15:44.740 回答
1

永远不要依赖隐式转换。利用:

where hire_date < to_date('01-JAN-1990', 'DD-MON-YYYY')
于 2013-01-22T17:16:12.770 回答