如何在oracle中插入日期和时间? [英] how to insert date and time in oracle?
问题描述
我无法在表格中插入行.这是插入语句和表的创建.这是uni作业的一部分,因此简单,我在做什么错?我使用的是oracle SQL开发人员版本3.0.04.'
Im having trouble inserting a row in my table. Here is the insert statement and table creation. This is part of a uni assignment hence the simplicity, what am i doing wrong? Im using oracle SQL developer Version 3.0.04.'
我遇到的问题是它仅插入dd/mon/yy而不是时间.我该如何同时插入时间?
The problem i am having is that it is only inserting the dd/mon/yy but not the time. How do i get it to insert the time as well?
INSERT INTO WORKON (STAFFNO,CAMPAIGNTITLE,DATETIME,HOURS)
VALUES ('102','Machanic Summer Savings',TO_DATE('22/April/2011 8:30:00AM','DD/MON/YY HH:MI:SSAM'),'3')
;
CREATE TABLE WorkOn
(
StaffNo NCHAR(4),
CampaignTitle VARCHAR(50),
DateTime DATE,
Hours VARCHAR(2)
)
;
感谢您的帮助.
这没有任何意义,我仅在字段中输入一个时间来测试时间是否在工作,并且它输出日期为WTF?这真的很奇怪,我可能不使用日期字段而只输入时间,我意识到这将导致操作数据时出现问题,但这毫无意义...
This is making no sense, i enter just a time in the field to test if time is working and it outputs a date WTF? This is really weird i may not use a date field and just enter the time in, i realise this will result in issues manipulating the data but this is making no sense...
推荐答案
通过使用to_date函数并指定时间,您可以正确地进行所有操作.时间在数据库中.问题在于,当您从数据库中选择DATE数据类型的列时,默认格式掩码没有显示时间.如果您发出
You are doing everything right by using a to_date function and specifying the time. The time is there in the database. The trouble is just that when you select a column of DATE datatype from the database, the default format mask doesn't show the time. If you issue a
alter session set nls_date_format = 'dd/MON/yyyy hh24:mi:ss'
或类似的东西(包括时间部分),您将看到时间成功地进入了数据库.
or something similar including a time component, you will see that the time successfully made it into the database.
这篇关于如何在oracle中插入日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!