lundi 31 juillet 2017

How can I insert Oracle SQL IF ELSE in to UPDATE statement ?

I am trying to join 3 tables and I have the following sql without IF ELSE.

update transaction t
set t.lid= (
select l.id rom list l
inner join distance d
on l.uid=d.uid
inner join transaction t2
on t2.id=d.id
)

The only problem is the statement

select l.id rom list l
    inner join distance d
    on l.uid=d.uid
    inner join transaction t2
    on t2.id=d.id

returns more than one value and I wasn't able to assign it to t.gid. With our business rule, if it returns more than one value I have to set t.gid to be null. How can I incorporate if else statement in this sql ? I have seen other posts on the net but they are mostly procedures or functions.

Aucun commentaire:

Enregistrer un commentaire