0

I'm new to oracle so don't laugh if I ask a stupid question:)
Here's my problem
Consider I have two tables
t1. in inserts

insert into `t1` (`iss_id`, `tr_type`, `perc`) values('1','26','1');
insert into `t1` (`iss_id`, `tr_type`, `perc`) values('2','26','4');

and t2 in insert

insert into `t2` (`id`, `perc`) values('1','0');
insert into `t2` (`id`, `perc`) values('2','0');

(the rows in tables are much more)

I want to update t2 so that the result was like this:

insert into `t2` (`id`, `perc`) values('1','1');
insert into `t2` (`id`, `perc`) values('2','4');

How can I write a proper update for this? I tried with decode function, but the rows in tables are more than it allows.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
arminrock
  • 525
  • 1
  • 7
  • 23
  • 1
    What exactly are you trying to achieve with your update? Are you trying to update t2.perc with t1.perc where t2.id = t2.iss_id? – Drumbeg Dec 22 '13 at 21:29
  • yes exactly, and i see the answer from your comment))) UPDATE t2 SET perc = (SELECT perc FROM t1 WHERE t2.'id' = t1.'iss_id') this will work for me right? – arminrock Dec 22 '13 at 21:35
  • It looks Ok to me. Have you tested it? – Drumbeg Dec 22 '13 at 21:46
  • why not insert into t2 select iss_id, perc from t1? after insert into t1, instead of insert into t2 values() – Sumit Dec 22 '13 at 21:53
  • @Drumbeg right now i could do the test on MySql, it worked as needed, and i see no reasons for it not to work on Oracle. Thank you. – arminrock Dec 22 '13 at 22:13
  • @Sumit to answer to your question i have to explain the whole process of my work. It just needs to be with an update like this)) thanks to you too for the response :)) – arminrock Dec 22 '13 at 22:14
  • Of course you would not have backticks in the Oracle SQL – David Aldridge Dec 22 '13 at 23:20
  • @arminrock You can test whether your solution works with Oracle 11gR2 using http://sqlfiddle.com/. – Drumbeg Dec 23 '13 at 08:33
  • Possible duplicate of [Update statement with inner join on Oracle](https://stackoverflow.com/questions/2446764/update-statement-with-inner-join-on-oracle) – Mureinik May 16 '19 at 08:08

0 Answers0