如何仅将列值插入前几千行

我有一个名为GSH的表,其中的值已经存在。

已经在表'GSH'中添加了一个名为'GS'的新列。我只需要为从GSH表中选择的前一千行添加值即可。

如何编写SQL查询?

wx8823 回答:如何仅将列值插入前几千行

如果我正确地遵循了您的说明,则希望在该列中添加随机1000行的数据。 (更新新列的值)

Update GSH
SET GS = 1 -- replace 1 with value that you want to fill it with
WHERE ROWNUM <= 1000;

干杯!

,

您可以在下面使用(假设您要选择任意100行)

update GSH 
set GS = 'your values logic'
where rowid in (
select rowid 
from GSH
where rownum < 101); 

这是我用来重新创建场景的脚本

drop table temp;

create table temp (temp1 varchar2(100));

begin 
for rec in 1..500
loop
insert into temp values('s');
end loop;
commit;

end;
/


alter table temp add  temp2 varchar2(200);

update temp 
set temp2 = 'your values logic'
where rowid in (
select rowid 
from temp
where rownum < 101);
本文链接:https://www.f2er.com/3124541.html

大家都在问