Inserting from a SELECT but changing one column?

前端 未结 6 770
忘了有多久
忘了有多久 2021-02-05 02:35

Wondering if there is a way to insert a row into a table from another, with exception of one column?

This is of course easy with a limitied amount of columns, but gets k

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 02:53

    using Oracle

    DECLARE
    CURSOR CUR_D IS
      SELECT *
      FROM TABLE
      WHERE id = some id;
    ROW_D CUR_D%ROWTYPE;
    
    BEGIN
      OPEN CUR_D;
      FETCH CUR_D INTO ROW_D;
      CLOSE CUR_D;
    
      ROW_D.column := 'some data';
    
      INSERT INTO some table
      VALUES ROW_D;
    
    END;
    /
    

提交回复
热议问题