0

I have two tables as followed:

Table A (with Column 1A and Column 2A) Table B (with Column 1B and Column 2B)

I want to write a procedure that helps me do the following:

  1. Find matched rows of Table A and Table B, where 1A = 1B
  2. After that, for each of the matched rows, if 2B is null, then update it with 2A; if it is not null, then not update it.

I am a newbie in SQL and Oracle, I would appreciate any help.

Thank you in advance

Eric Do
  • 5
  • 3

2 Answers2

1

Try this MERGE statement:

MERGE INTO TABLE_B B
USING (SELECT 1A, 2A FROM TABLEA) A
ON (A.1A = B.1B)
WHEN MATCHED THEN
UPDATE 
SET B.2B = COALESCE(B.2B, A.2A);

Cheers!!

Popeye
  • 35,427
  • 4
  • 10
  • 31
  • Thank you! I tried it and actually for the USING it says that ON is missing – Eric Do Aug 09 '19 at 03:11
  • If that answer solved your question then please [accept](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) it, so that your question is marked as resolved. – Popeye Aug 10 '19 at 07:03
0

UPDATE TABLEA A SET A.2A = ( SELECT 2B FROM B WHERE B.1B= A.1A ) WHERE A.2A IS NULL;

this is what worked for me! Thanks for all the inputs guys!

Eric Do
  • 5
  • 3