Monday, March 5, 2018

Upate a column based on the results of multiple tables in oracle

below is the generic select..

select b.abc,c.abc,c.abc,p.abc ,w.abc from table_A a,((c.abc*abc)*p.abc) as "normal"
table_A b, table_A c,table_A p, table_A w
where b.tab_A=f.tab_A
and b.tab_A=p.tab_A
and b.tab_A=w.tab_A
and p.tab_A=xxx
and c.tab_A >0
and c.tab_A >0
and rownum <10;

to update a table column based on mutiple tables result... use Merge Statement:


merge into table_A s
using
(select ((c.abc*abc)*p.abc)  as normal,w.abc  from
table_A f, table_A b,table_A p,table_A w
where b.tab_A=f.tab_A
and b.tab_A=p.tab_A
and b.tab_A=w.tab_A
and p.tab_A=xxx
and c.tab_A >0
and c.tab_A >0
and ((c.abc*abc)*p.abc) <> w.abc and rownum <10) z
on (s.abc=z.abc)
when matched then update set s.abc=z.abc;

No comments:

Post a Comment

PostgreSql: Useful Commands-

 1)   ************************* Users ***************************  -- List of users with roles assigned: SELECT usename AS role_name,   CASE...