update test set birthday=to_date(sysdate,'yyyy-mm-dd') where test_id=100;
birthday是date类型,原值2008-10-16 上午 11:35:40报错:ora-01861 literal does not match format string

解决方案 »

  1.   

    sysdate本身就是date类型
    直接update test set birthday = sysdate where test_id = 100;
      

  2.   

    update test set birthday=sysdate where test_id=100;
      

  3.   

    sysdate的输入格式是2008-10-16 上午 11:35:40,我想用简单点的时间yyyy-mm-dd格式,怎么写啊,谢谢哦
      

  4.   

    查询的时候用select to_char(birthday,'yyyy-mm-dd') from test;
      

  5.   

    那就用trunc(sysdate)
    不过不管怎么样date类型是到毫秒的
    所以就算你用trunc(sysdate)也只是置成当天的0点0分0秒而已
    除非你不用date 类型的
      

  6.   

    date类型是到毫秒的 ,你要想查询出来的显示就用to_char(birthday,'yyyy-mm-dd')
      

  7.   

    恩,查询可以的
    那我怎么修改表里的值呢
    update test set birthday=to_date('2008-10-16 11:35:40','yyyy-mm-dd') where test_id=100;
    也会报错
      

  8.   

    1. use varchar2 type to store your date.
    2. use date type to store, but use to_char to display your date format with char string.
       select to_char(datefield,'yyyy-mm-dd') from tablename;
    3. if you just want to store date not include time in date field, do like the following:
      update test set birthday=to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd') where test_id=100;
      

  9.   

    1. use varchar2 type to store your date.
    2. use date type to store, but use to_char to display your date format with char string.
       select to_char(datefield,'yyyy-mm-dd') from tablename;
    3. if you just want to store date not include time in date field, do like the following:
      update test set birthday=to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd') where test_id=100;
      

  10.   

    1. use varchar2 type to store your date.
    2. use date type to store, but use to_char to display your date format with char string.
       select to_char(datefield,'yyyy-mm-dd') from tablename;
    3. if you just want to store date not include time in date field, do like the following:
      update test set birthday=to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd') where test_id=100;
      

  11.   

    修改
    update test set birthday=to_date('2008-10-16 11:35:40','yyyy-mm-dd hh24:ss') where test_id=100; 
      

  12.   

    谢谢楼上几位的提示哦
    看来我是不能一句话解决这个问题
    麻烦了一下,用个小过程解决了declare 
      old_date varchar2(20);
    begin
      select to_char(birthday,'yyyy-mm-dd') into old_date from test where test_id=100;
      update test set birthday=to_date(old_date,'yyyy-mm-dd') where test_id=100;
      commit;
      
    end;
      

  13.   

    update test set birthday=trunc(birthday) where test_id=100;