Home > Software design >  How do I UPDATE from a SELECT of same table
How do I UPDATE from a SELECT of same table

Time:01-31

I should update a column of table by converting other column of same table in oracle. something like this:

update table1 set colum1=(select TO_CHAR(column2) from table1)

but I have this error

single-row subquery returns more than one row

could I do this?

CodePudding user response:

It's just

update table1 set
  column1 = to_char(column2);

CodePudding user response:

If you ever need it for more dynamic value generation, use WHERE to match a specific record

update table1 a
set colum1 = (select TO_CHAR(column2) from table1 b where b.id = a.id)
where a.id = .... -- <-- optional, for specific records
  • Related