PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 23, 2022

[FIXED] How can I add the rows and copy the value?

 October 23, 2022     oracle, sql, sql-update     No comments   

Issue

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?


Solution

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.



Answered By - Littlefoot
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing