I am (fairly new to) using PL/SQL with Oracle 12c, and am having trouble with a procedure I am trying to implement. I've looked up a lot of tutorials and similar questions here, but so far I've had no luck finding anything that could help me. The situation is this:
I have three tables: table1, table2, and table3.
Table1 has the attributes detailA and detailB.
Table2 has the attributes detailB and detailC.
Table3 has the attributes detailC and detailD.
My goal is to update the value of detailA in table1 to be equal to detailD in table2. I'm aware that in order to do that I need to join table1 and table2 on detailB, then join table2 and table3 on detailC. Actually implementing that, though, is giving me trouble.
So far, everything I've tried goes off-rails about halfway through—I'm having a very hard time implementing all the conditions I need to check while still keeping it within the structure of PL/SQL.
Here's an (obviously very wrong) example of something I've tried:
UPDATE (SELECT table1.detailB, table2.detailB, table2.detailC,
table3.detailC, table3.detail4 FROM table1
JOIN table2 on table1.detailB = table2.detailB
JOIN table3 on table2.detailC = table3.detailD)
SETtable1.detailA = table3.detail4;
If anyone could help me understand this better, I'd be very grateful.
EDIT: And for an example with some actual data, if I inserted the following, it should replace the 100 in table1 with the 1000 in table4 when I run my query:
INSERT INTO table1(detailA, detailB) VALUES (100, 200);
INSERT INTO table2(detailB, detailC) VALUES (200, 400);
INSERT INTO table3(detailC, detailD) VALUES(400, 1000);