当我处理DATE数据类型时,where子句没有区别。以下代码显示所有107行。它应该显示大约5行。也没有语法错误。 Where子句在数字,字符等方面正常工作
select last_name,hire_date
from employees
where hire_date < '01-JAN-90'
答案 0 :(得分: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'
答案 1 :(得分:1)
永远不要依赖隐式转换。使用方法:
where hire_date < to_date('01-JAN-1990', 'DD-MON-YYYY')