insert table tab1 set id = (select id + 40 from tab1)

解决方案 »

  1.   

    update dept set dept_id = dept+40;
      

  2.   

    不对呀,它说缺少values关键詞
      

  3.   

    to 走不动了:不行,报错:
    update dept
    *
    ERROR 位于第 1 行:
    ORA-02292: 违反完整约束条件 (SCOTT.FK_DEPTNO) - 已找到子记录日志
      

  4.   

    insert table tab1 
    (select id + 40 from tab1);
    commit ;
      

  5.   

    update table_name set table_col = table_col + 40 where table_col = 123;
    commit;
      

  6.   

    dept这个表有个外键约束SCOTT.FK_DEPTNO
      

  7.   

    dept 表有三个域:deptno,deptment,loc.
    deptno有10,20,30,40四行
    现在要用一句话将四行中的10,20,30,40改为40,50,60,70,怎么办?
      

  8.   

    用一个触发器,同时更新子表create trigger name_tri
    before update on tablea
    for each row 
    begin
    update tableb set table_col:=:new.table_col where id=:new.id;
    end;
    /
      

  9.   

    declare
        strsql varchar2(1000);
        sec_balc number;
    begin
        for sec_balc in 500..1000 loop
         strsql := 'update table_name set table_col = table_col + 40 where table_col = :sec_balc';
         execute immediate strsql using sec_balc;
        end loop;     commit;
    end;
      

  10.   

    "现在要用一句话将四行中的10,20,30,40改为40,50,60,70,怎么办?"
    这是每个部门号加40吗,不是加30吗?而且你更改前后的部门号40这里有重复,需要先将部门号为40的先更改,然后才能用他们的SQL,这样才不会出现主键冲突。
      

  11.   

    1、先做个行触发器,修改相关表,然后使用update dept set dept_id = dept+40或者2、删除外键,然后用update修改2个表的dept_id,加上40,然后重建外键
      

  12.   

    DEPT
      DEPTNO
      DEPTNAME
      LOCATION假设有主键PK_DEPTNO(DEPTNO),且表DEPT无子表
    那么在UPDATE之前先使PK_DEPTNO(DEPTNO)失效ALTER TABLE DEPT DISABLE CONSTRAINT PK_DEPTNO;UPDATE DEPT SET DEPTNO = DEPTNO + 40;ALTER TABLE DEPT ENABLE CONSTRAINT PK_DEPTNO;