在Oracle SQL中:如何将当前日期和时间插入表中? [英] In Oracle SQL: How do you insert the current date + time into a table?

查看:398
本文介绍了在Oracle SQL中:如何将当前日期和时间插入表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了下面的代码,但是它似乎只插入当前日期而不是当前时间.有人知道该怎么做吗?

I've written below code, but it only seems to insert the current date and not the current time. Anyone knows how to do that?

insert into errortable
(dateupdated,table1id)
values
(TO_DATE(sysdate, 'dd/mm/yyyy hh24:mi:ss'),1083);

推荐答案

这似乎只是因为它正在打印出来.但是实际上,您不应该以这种方式编写逻辑.这是等效的:

It only seems to because that is what it is printing out. But actually, you shouldn't write the logic this way. This is equivalent:

insert into errortable (dateupdated, table1id)
    values (sysdate, 1083);

将系统日期转换为字符串,只是将其转换回日期,似乎很愚蠢.

It seems silly to convert the system date to a string just to convert it back to a date.

如果要查看完整日期,则可以执行以下操作:

If you want to see the full date, then you can do:

select TO_CHAR(dateupdated, 'YYYY-MM-DD HH24:MI:SS'), table1id
from errortable;

这篇关于在Oracle SQL中:如何将当前日期和时间插入表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆