簡體   English   中英

oracle如何更新大查詢結果?

[英]how update result of big query in oracle?

我可以輕松更新查詢結果嗎?

假設我有一個返回薪水列的大查詢,並且我需要根據此查詢結果更新薪水。

ID-是我的表格的主鍵

現在,我正在這樣做:

第1步

select id from mytable ...... where something

第2步

update mytable  set salary=1000 where id  in (select id from mytable ...... where something)

是否有其他方法可以輕松做到這一點?

是的,您可以直接輕松地更新結果。

這是示例

update 
  (
     select salary from mytable ...... where something
  ) set salary=1000

嘗試for updatecurrent of 您說您正在尋找諸如“更新網格上的數據”之類的東西

create table my_table( id number, a varchar2(10), b varchar2(10));

insert into my_table select level, 'a', 'b' from dual connect by level <=10;

select * from my_table;

declare  
  rec my_table%rowtype;
  cursor c_cursor is select * from my_table for update;
begin 
  open c_cursor;
  loop
    fetch c_cursor into rec;
      exit when c_cursor%notfound;
     if rec.id in (1,3,5) then 
      rec.a := rec.a||'x';
      rec.b := rec.b||'+';

      update my_table set row = rec where current of c_cursor;
     else 
       delete from my_table where current of c_cursor;
     end if;
  end loop;
 commit;
end; 


select * from my_table;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM