Oracle: Using CTE with update clause

后端 未结 3 1397
梦谈多话
梦谈多话 2021-01-22 00:21

Can I make an update using common table expression in oracle database?

I am getting error ORA-00928: missing SELECT keyword when I am trying this:

3条回答
  •  耶瑟儿~
    2021-01-22 00:56

    Since average salary just a scalar value you can do

    update instructor
       set salary = case
           when salary <= (select avg(t.salary) from instructor t) then salary * 1.05 
           else salary * 1.03                                     
       end
    

    In that case Oracle first compute the average (say 1234.4567) and then perform the update.

提交回复
热议问题