0

我想在 oracle 数据库中插入日期和时间,我已经创建了带有列的表

create table myadmin 
(  employe_id number(5), 
  supervisor Varchar2(20),
  department Varchar2(20),
  action Varchar2(20),
  sdate date, 
  stime date) 
While inserting the values below it gives an error. Please tell me how to insert the time ?

insert into myadmin 
(  employe_id,supervisor,department,action,sdate,stime) values 
(83,'gaurav','helpdesk','pick','23-jan-2013','09:43:00');
4

2 回答 2

1

您必须像这样在 oracle 中使用关键字 to_date 进行日期插入。

to_date('23-01-2013','dd-mm-yyyy')

基本上你必须使用关键字 to_date('your date','your date format')。

如果需要,您还可以一起添加日期和时间,就像这样

 to_date('23-01-2013 09:43:00','dd-mm-yyyy hh24:mi:ss')
于 2013-09-24T11:26:20.833 回答
1

Oracle 中的日期总是有日期部分和时间部分。将日期和时间放在两个单独的列中才有意义,前提是日期为空而时间不为空。(而且,您仍然可以将日期设置为一个不太可能的值,例如 1.1.0001。)

但是,如果您想坚持这两个单独的字段,则使用 to_date 函数指定使用的格式将您的字符串设置为日期时间:

insert into myadmin 
(  employe_id,supervisor,department,action,sdate,stime) values 
(83,'gaurav','helpdesk','pick',to_date('23-01-2013','dd-mm-yyyy'), to_date('09:43:00', 'hh24:mi:ss'));
于 2013-09-24T11:29:37.350 回答