指定件数の更新削除

 

(8.0.26)
https://qiita.com/sskre/items/8d44520a3addaabeecdf

drop table tab1;
create table tab1(col1 int);
insert into tab1 select row_number() over(order by table_catalog) from information_schema.columns limit 10;

select * from tab1;

update tab1 set col1 = 0 limit 3;

delete from tab1 limit 3;

 

(19c)

drop table tab1 purge;
create table tab1(col1 int);
insert into tab1 select row_number() over(order by owner) from dba_tab_columns fetch first 10 rows only;
commit;
select * from tab1;

update tab1 set col1 = 0 where rownum <= 3;


delete from tab1 where rownum <= 3;

 

(14)
https://qiita.com/sskre/items/8d44520a3addaabeecdf

drop table tab1;
create table tab1(col1 int);
insert into tab1 select row_number() over(order by table_catalog) from information_schema.columns limit 10;


select * from tab1;


update tab1 set col1 = 0 where ctid in ( select ctid from tab1 limit 3);

delete from tab1 where ctid in ( select ctid from tab1 limit 3);

 

※limit句はエラーとなる
update tab1 set col1 = 0 limit 3;

delete from tab1 limit 3;

(2019)
drop table tab1;
create table tab1(col1 int);
insert into tab1 select top 10 row_number() over(order by object_id) from sys.columns;


select * from tab1;


update top(3) tab1 set col1 = 0;
delete top(3) from tab1;

※select文と異なり、topのかっこは省略できない。下記はエラーとなる。
update top 3 tab1 set col1 = 0;
delete top 3 from tab1;