how to insert date and time in oracle?

前端 未结 5 925
清歌不尽
清歌不尽 2020-12-08 00:23

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?

相关标签:
5条回答
  • 2020-12-08 00:50

    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.

    0 讨论(0)
  • 2020-12-08 00:55

    Just use TO_DATE() function to convert string to DATE.

    For Example:

    create table Customer(
           CustId int primary key,
           CustName varchar(20),
           DOB date);
    
    insert into Customer values(1,'Vishnu', TO_DATE('1994/12/16 12:00:00', 'yyyy/mm/dd hh:mi:ss'));
    
    0 讨论(0)
  • 2020-12-08 01:07

    You can use

    insert into table_name
    (date_field)
    values
    (TO_DATE('2003/05/03 21:02:44', 'yyyy/mm/dd hh24:mi:ss'));
    

    Hope it helps.

    0 讨论(0)
  • 2020-12-08 01:10

    Try this:

    ...(to_date('2011/04/22 08:30:00', 'yyyy/mm/dd hh24:mi:ss'));

    0 讨论(0)
  • 2020-12-08 01:13
    create table Customer(
           CustId int primary key,
           CustName varchar(20),
           DOB date);
    
    insert into Customer values(1,'kingle', TO_DATE('1994-12-16 12:00:00', 'yyyy-MM-dd hh:mi:ss'));
    
    0 讨论(0)
提交回复
热议问题