我有一个像这样的Oracle表
|---------------------------------|
|EMPNO | HIREDATE | INDEX_NUM |
|---------------------------------|
|1 | 2012-11-13 | 1 |
|2 | 2 | 1 |
|3 | 2012-11-17 | 1 |
|4 | 2012-11-21 | 1 |
|5 | 2012-11-24 | 1 |
|6 | 2013-11-27 | 1 |
|7 | 2 | 2 |
|---------------------------------|
我正在尝试对此表执行此query
SELECT hiredate
FROM admin_emp
WHERE TO_DATE('hiredate','yyyy-mm-dd') >= TO_DATE('2012-05-12','yyyy-mm-dd');
但是得到了错误
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
任何想法..?这是什么问题?
查询库:
CREATE TABLE admin_emp (
empno NUMBER(5) PRIMARY KEY,
hiredate VARCHAR(255),
index_num NUMBER(5));
insert into admin_emp(empno,hiredate,index_num) values
(1,'2012-11-13',1);
insert into admin_emp(empno,hiredate,index_num) values
(2,'2',1);
insert into admin_emp(empno,hiredate,index_num) values
(3,'2012-11-17',1);
insert into admin_emp(empno,hiredate,index_num) values
(4,'2012-11-21',1);
insert into admin_emp(empno,hiredate,index_num) values
(5,'2012-11-24',1);
insert into admin_emp(empno,hiredate,index_num) values
(6,'2013-11-27',1);
insert into admin_emp(empno,hiredate,index_num) values
(7,'2',2);
答案 0 :(得分:3)
SQL中的单引号('
)表示字符串文字。因此'hiredate'
不在hiredate
列,它只是一个varchar,当然,它不符合您指定的日期格式。只需删除引号就可以了:
SELECT hiredate
FROM admin_emp
WHERE TO_DATE(hiredate,'yyyy-mm-dd') >= -- No quotes
TO_DATE('2012-05-12','yyyy-mm-dd');
答案 1 :(得分:0)
使用'rrrr'格式表示年份:
SELECT hiredate
FROM admin_emp
WHERE TO_DATE(hiredate,'rrrr-mm-dd') >= TO_DATE('2012-05-12','rrrr-mm-dd');