Home > Blockchain >  How can I add the rows and copy the value?
How can I add the rows and copy the value?

Time:08-05

The table looks like

Person Employee
p_key e_key
e_name

I want to add the value of e_name into Person.

I added the p_name column to Person table by using "ALTER TABLE PERSON ADD P_NAME CHAR(25)"

but I don't know how to put the values into them. p_name is all empty.

How can I copy the value from e_name to p_name in Person. Or is there any other way to copy the value?

CodePudding user response:

Looks like merge would do, if matching columns are p_key and e_key.

merge into person p
  using employee e
  on (e.e_key = p.p_key)
  when matched then update set
    p.p_name = e.e_name;

BTW, don't use char datatype, it'll right-pad all values with spaces up to full column length. Use varchar2 instead.

  • Related