Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213602
  • 博文数量: 57
  • 博客积分: 1376
  • 博客等级: 中尉
  • 技术积分: 658
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-09 09:51
文章分类

全部博文(57)

文章存档

2012年(1)

2011年(56)

分类: Oracle

2011-03-06 18:47:12


今天在 建立一个表的时候,没注意,把一个字段置成了date类型, 然后, 以后查看的时候都要to_char觉得麻烦,想把默认值改成to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss'), 然后,就碰到了这个问题:
  1. SQL> alter table emp_monitor modify modify_date varchar2(30) default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss');
  2. alter table emp_monitor modify modify_date varchar2(30) default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')
  3.                                *
  4. ERROR at line 1:
  5. ORA-01439: column to be modified must be empty to change datatype

意思是说, 这个字段里的必须为空才可以修改这个字段类型。


后来才用了,字段交换的方式完成了字段类型修正,费劲。。。。

  1. SQL> alter table emp_monitor add (tmp_col varchar2(30) default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'));

  2. Table altered.

  3. SQL> update emp_monitor set tmp_col=to_char(modify_date, 'yyyy-mm-dd hh24:mi:ss');

  4. 2 rows updated.

  5. SQL> select action_type,modify_date, tmp_col from emp_monitor;

  6. ACTION_TYP MODIFY_DA TMP_COL
  7. ---------- --------- ------------------------------
  8. Insert 06-MAR-11 2011-03-06 17:05:22
  9. delete 06-MAR-11 2011-03-06 18:31:59

  10. SQL> update emp_monitor set modify_date=null;

  11. 2 rows updated.

  12. SQL> alter table emp_monitor modify modify_date varchar2(30) default to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss');

  13. Table altered.

  14. SQL> update emp_monitor set modify_date=tmp_col;

  15. 2 rows updated.

  16. SQL> select action_type, modify_date, tmp_col from emp_monitor;

  17. ACTION_TYP MODIFY_DATE TMP_COL
  18. ---------- ------------------------------ ------------------------------
  19. Insert 2011-03-06 17:05:22 2011-03-06 17:05:22
  20. delete 2011-03-06 18:31:59 2011-03-06 18:31:59


  21. SQL> alter table emp_monitor drop column tmp_col;

  22. Table altered.

  23. SQL> select tmp_col from emp_monitor;
  24. select tmp_col from emp_monitor
  25.        *
  26. ERROR at line 1:
  27. ORA-00904: "TMP_COL": invalid identifier


  28. SQL> select modify_date from emp_monitor;

  29. MODIFY_DATE
  30. ------------------------------
  31. 2011-03-06 17:05:22
  32. 2011-03-06 18:31:59

阅读(4951) | 评论(0) | 转发(0) |
0

上一篇:A find script

下一篇:Undo的ORA-30036

给主人留下些什么吧!~~