比如:create table tb(t1 int,t2 int,t3 int , t4 int)我想把t4改成计算列 t4=t1+t2+t3,怎么修改这列,修改语句怎么写

解决方案 »

  1.   

    update tb set t4=t1+t2+t3
      

  2.   

    update tb set t4=nvl(t1,0)+nvl(t2,0)+nvl(t3,0);
      

  3.   

    如果你需要的是建立一个虚拟列,那么只能先将这一列删除,然后再创建一个新的虚拟列
    SQL>  create table tb(t1 int,t2 int,t3 int , t4 int) ;Table created.
    SQL>  create table tb(t1 int,t2 int,t3 int , t4 int) ;Table created.SQL> commit ;Commit complete.SQL> alter table tb modify t4 as (t1+t2+t3) ;
    alter table tb modify t4 as (t1+t2+t3)
                          *
    ERROR at line 1:
    ORA-54026: Real column cannot have an expressionSQL> alter table tb drop column t4 ;Table altered.SQL> alter table tb add t4 as (t1+t2+t3) ;

    Table altered.SQL> select * from tb ;        T1         T2         T3         T4
    ---------- ---------- ---------- ----------
             1          1          1          3
             2          2          2          6
             3          3          3          9
             4          4          4         12
             5          5          5         15
             6          6          6         18
             7          7          7         21
             8          8          8         24
             9          9          9         27
            10         10         10         3010 rows selected.
      

  4.   


    --第二个
    SQL>  create table tb(t1 int,t2 int,t3 int , t4 int) ;Table created.
    --修改为
    SQL> insert into tb select level , level , level , level from dual connect by level <= 10 ;10 rows created.
      

  5.   

    提示无效数字 肯定是有字符或者空值不能转换层number类型咯 还没注意  LZ建表的字段类型是int? 玩的sql还是?