从oracle插入并提取每小时一小时 [英] insert and extract hour an minute from oracle
问题描述
我使用oracle
我想插入包含小时和分钟的数据
我有这个栏目: DATE_ARCH
此列的类型为日期
我有这个java代码应该在这个列中插入日期
transfers.setDateArch(new java.sql.Date (
System.currentTimeMillis()));
但当我尝试从 DATE_ARCH
使用此sql代码:
select to_char(transfers.DATE_ARCH,'HH :MM')来自转账,其中id_transfer ='TR-300'
我有这段时间的所有时间:
12:05
已更新:
我尝试使用此代码:
时间戳t =新时间戳( new Date()。getTime());
transfers.setDateArch(t);
我尝试使用以下代码提取小时和分钟:
从id_transfer ='TR-258'
但我在所有情况下都有这个值:
00:00
因为我已经说过 DATE_ARCH 的类型是日期
当我在sql中尝试:
UPDATE转移SET DATE_ARCH = SYSDATE
我使用正确的值
从转移中选择to_char(transfers.DATE_ARCH,'HH24:MI'),其中id_transfer ='TR-258'
现在我想知道如何使用java代码插入日期和小时和分钟
你是对的。我不太了解Oracle的Java接口知道正确的解决方案。但是,您的解决方案是立即插入日期。表达式:
to_char(transfers.DATE_ARCH,'HH:MM')
返回12,因为那是午夜和05,因为它是五月。分钟的正确表达式为:
to_char(transfers.DATE_ARCH,'HH:MI')
和24小时制:
to_char(transfers.DATE_ARCH,'HH24:MI')
我没有,唉,知道如何修复java代码。但也许你可以使用 DateTime
方法。
I work with oracle
I want to insert data which contains hour and minute
I have this column : DATE_ARCH
the type of this column is date
I have this java code which should insert date in this column
transfers.setDateArch(new java.sql.Date(
System.currentTimeMillis()));
but when I try to extract hour and minute from DATE_ARCH
using this sql code :
select to_char(transfers.DATE_ARCH , 'HH:MM') from transfers where id_transfer='TR-300'
I have all time this value :
12:05
Updated :
I try with this code :
Timestamp t = new Timestamp(new Date().getTime());
transfers.setDateArch(t);
I try to extract hour and minute using this code :
select to_char(transfers.DATE_ARCH , 'HH24:MI') from transfers where id_transfer='TR-258'
but I have in all case this value :
00:00
as I already said the type of DATE_ARCH is date
When I try in sql with :
UPDATE transfers SET DATE_ARCH = SYSDATE
I have the correct value using
select to_char(transfers.DATE_ARCH , 'HH24:MI') from transfers where id_transfer='TR-258'
now I want to know how can I insert date with hour and minute using java code
You are correct. I do not know enough about the java interface to Oracle to know the right solution. But, your solution is inserting the date with no time. The expression:
to_char(transfers.DATE_ARCH , 'HH:MM')
is returning "12" because that is midnight and "05" because it is May. The correct expression for minutes is:
to_char(transfers.DATE_ARCH , 'HH:MI')
and for a 24-hour clock:
to_char(transfers.DATE_ARCH , 'HH24:MI')
I do not, alas, know how to fix the java code. But perhaps there is a DateTime
method that you can use.
这篇关于从oracle插入并提取每小时一小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!