首先进程查询:
select ename,sal, newsal,hiredate,working_age from emp2 where ename='SCOTT';
显示的结果为:
日期格式:01-4月 -88
因此进行数据更新的时候:
update emp2 set hiredate= date'1987-04-01' where ename='SCOTT';
我们需要在更新的日期字符串前增加date代表当前字符串是日期信息。
或者使用以下的方式:即需要确保系统把当前的字符串识别为日期才可以。
update emp2 set hiredate= to_date('1986-04-01','YYYY-MM-DD') where ename='SCOTT';
上述不能修改的原因是因为系统默认现实的日期格式与我们插入的不同。
我们修改系统的默认显示格式:
数据库的日期显示格式是 ‘14-10月-11’
使用 alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
或 alter system set nls_date_format='yyyy-mm-dd hh24:mi:ss' scope=spfile;
更改后可以显示'yyyy-mm-dd hh24:mi:ss'的格式。但是下次打开就会恢复。需要永久设置请自行查询。
这个时候我们在使用一下的方式去更新的时候,就是可以成功的。
update emp2 set hiredate= '1985-04-01' where ename='SCOTT';
但是为了保险,避免以后的问题,最好还是使用:
update emp2 set hiredate= date '1985-04-01' where ename='SCOTT';