[英]SQL date format query
I'm trying to insert a data into a table, but I face a problem in date syntax, I need to present the year with 4 digit.我正在尝试将数据插入表中,但我在日期语法中遇到问题,我需要用 4 位数字表示年份。
This is what I have done:这就是我所做的:
create table ee
(
empno number(3),
ename VARCHAR2(24),
sal number(4),
hiredate Date
);
Insert into ee (empno, ename, sal, hiredate)
Values (200, 'Ahmed', 4000, to_date('01/01/2008', 'dd/mm/yyyy'));
and the result is that (01-JAN-08)结果是 (01-JAN-08)
How can I fix it?我该如何解决?
You code is fine.你的代码很好。 That is just the default format for query results.
这只是查询结果的默认格式。 That said, I would recommend a date constant:
也就是说,我会推荐一个日期常数:
Insert into ee (empno, ename, sal, hiredate)
Values (200, 'Ahmed', 4000, date '2008-01-01');
If you want to see the result differently, you can use to_char()
:如果您想以不同的方式查看结果,可以使用
to_char()
:
to_char(hiredate, 'YYYY-MM-DD')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.