Oracle SQL Update语句

时间:2014-02-25 18:41:52

标签: sql oracle

有人可以帮我修改这个SQL语句,以便它可以在Oracle环境中工作吗?

update tbraccd 
join ttbtaxn on tbraccd.pidm = ttbtaxn.pidm
set tbraccd_effective_date = '01-JAN-2014', tbraccd_entry_date = '01-JAN-2014'
where tbraccd_detail_code = 'VPMT' 
and tbraccd_effective_date = '31-DEC-2013' 
and (tbraccd_entry_date > '31-DEC-2013' and tbraccd_entry_date < '01-JAN-2014')
and tbraccd_term_code = '201410'
and ttbtaxn_stud_notif_status = 'E'
and ttbtaxn_tax_year = '2013'

2 个答案:

答案 0 :(得分:0)

假设连接导致密钥保留视图,您可以这样做:

update
(
select
        tbraccd_effective_date,
        tbraccd_entry_date
from
        tbraccd
        join ttbtaxn
        on tbraccd.pidm = ttbtaxn.pidm
where
        tbraccd_detail_code = 'VPMT'
        and tbraccd_effective_date = '31-DEC-2013'
        and (tbraccd_entry_date > '31-DEC-2013' and tbraccd_entry_date <'01-JAN-2014')
        and tbraccd_term_code = '201410'
        and ttbtaxn_stud_notif_status = 'E'
        and ttbtaxn_tax_year = '2013'
)
set
        tbraccd_effective_date = '01-JAN-2014',
        tbraccd_entry_date ='01-JAN-2014'

答案 1 :(得分:0)

update tbraccd 
    set tbraccd_effective_date = '01-JAN-2014', 
        tbraccd_entry_date = '01-JAN-2014'
where tbraccd_detail_code = 'VPMT' 
and tbraccd_effective_date = '31-DEC-2013' 
and (tbraccd_entry_date > '31-DEC-2013' 
and tbraccd_entry_date < '01-JAN-2014')
and tbraccd_term_code = '201410'
and exists
    (select 'X' from ttbtaxn  
       where tbraccd.pidm = ttbtaxn.pidm
        and  ttbtaxn_stud_notif_status = 'E'
        and  ttbtaxn_tax_year = '2013')