Oracle: copy row while updating one field

后端 未结 3 1063
忘了有多久
忘了有多久 2021-02-07 12:53

Please note: I am asking the question I want answered. I know this question means the database is set up poorly. So I will vote down any answers that suggest changing

相关标签:
3条回答
  • 2021-02-07 13:27

    Will this do it?

    INSERT INTO yourtable
           (SELECT name, col1, 'a'
              FROM yourtable 
             WHERE col2 is NULL);
    
    0 讨论(0)
  • 2021-02-07 13:30

    Use:

    INSERT INTO table
      (name, col1, col2)
    SELECT t.name, t.col1, 'a'
      FROM TABLE t
     WHERE t.col2 IS NULL
    

    That's assuming neither the name or col1 columns are a primary key or have a unique constraint on either.

    0 讨论(0)
  • 2021-02-07 13:52

    If the number of columns is large, you could copy the data you want into a temporary table, alter the data in the temporary table as you wanted, then copy the contents of the temporary table back into the original, and delete the temporary table.

    0 讨论(0)
提交回复
热议问题