日期:2014-05-17  浏览次数:20872 次

Oracle如果设置当天的某个时间
如我要执行Insert into table1 (NowDate) values ('2012-02-09 13:12:10')
要怎么写?
2012-02-09 这个日期为每天的当天时间,13:12:10这个则是固定的时间

------解决方案--------------------
select to_date(to_char(sysdate,'yyyy-mm-dd') || '13:12:10','YYYY-MM-DD HH24:MI:SS') from dual
------解决方案--------------------
SQL code

SQL> show user
USER 为 "SCOTT"

SQL> ed
已写入 file afiedt.buf

  1  CREATE TABLE test(
  2     nowdate DATE
  3* )
SQL> /

表已创建。

SQL> ed
已写入 file afiedt.buf

  1  Insert into test
  2* values (to_date(to_char(sysdate,'yyyy-mm-dd') || '13:12:10','YYYY-M
4:MI:SS'))
SQL> /

已创建 1 行。

SQL> select * from test;

NOWDATE
--------------
09-2月 -12

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

会话已更改。

SQL> select * from test;

NOWDATE
-------------------
2012-02-09 13:12:10