I have been working on an UPDATE query that will update one column based on results from a join select query.
[highlight #FCE94F]I am looking to update the column "stat_typ_cd='OPEN'" to "stat_typ_cd='CLOSED'".[/highlight]
At the bottom of the page is the SELECT query that pulls the data that I'm trying to update.
[highlight #FCE94F]I am looking to update the column "stat_typ_cd='OPEN'" to "stat_typ_cd='CLOSED'".[/highlight]
At the bottom of the page is the SELECT query that pulls the data that I'm trying to update.
The UPDATE query below updates ALL rows, not just unique "DISTINCT" rows (which is what I want). This works though.
Code:
update
(select su.sec_usr_id,su.is_enbl_ind,t.asn_usr_id,t.stat_typ_cd
from sec_usr su, tsk t
where su.is_enbl_ind = 0
and su.sec_usr_id = t.asn_usr_id
and t.stat_typ_cd = 'OPEN')u
set u.stat_typ_cd = 'CLOSED';
Code:
[highlight #FCE94F]Results:
*Action:
savepoint a
158 rows updated.[/highlight]
But, if I add “distinct” into it I get an illegal on this view error. Fails.
Code:
update
(select [COLOR=#EF2929]distinct su.sec_usr_id[/color], su.is_enbl_ind, t.asn_usr_id, t.stat_typ_cd
from sec_usr su, tsk t
where su.is_enbl_ind = 0
and su.sec_usr_id = t.asn_usr_id
and t.stat_typ_cd = 'OPEN')u
set u.stat_typ_cd = 'CLOSED';
Code:
[highlight #FCE94F]Results:
SQL Error: ORA-01732: data manipulation operation not legal on this view
01732. 00000 - "data manipulation operation not legal on this view"[/highlight]
SELECT query below pulls the data that the UPDATE needs to update.
Code:
SELECT [COLOR=#EF2929]distinct n.sec_usr_id[/color], n.is_enbl_ind, m.stat_typ_cd, m.asn_usr_id
FROM sec_usr n
LEFT OUTER JOIN tsk m
ON n.sec_usr_id = m.asn_usr_id
where n.is_enbl_ind = 0
and m.stat_typ_cd = 'OPEN';