update table set col='test' where id in(select id from (select id,rownum num,col1 from table2 order by col1)where mod(num,484,11)=1);
执行此语句之后再执行
update table set col='test2' where id in(select id from (select id,rownum num,col1 from table2 order by col1)where mod(num,484,11)=2);
这样更新的数据就产生了混乱, 第二条sql语句更新的数据有些更新到第一条sql语句当中。希望能给给答复, 到底是数据更新 排序发生了变化而使之rownum也发生了改变。
执行此语句之后再执行
update table set col='test2' where id in(select id from (select id,rownum num,col1 from table2 order by col1)where mod(num,484,11)=2);
这样更新的数据就产生了混乱, 第二条sql语句更新的数据有些更新到第一条sql语句当中。希望能给给答复, 到底是数据更新 排序发生了变化而使之rownum也发生了改变。
解决方案 »
- 行转列,大家帮帮忙。
- 多数据分组后取日期最近的一条记录?跪求高人!!!!
- sql 新需求
- 如图:有限制条件的分类求和语句怎么写?
- 如何在oracle90中查出数据量在1000以上的所有表id
- oracle中如何把一个数据库中的表以及数据用SQL语句复制到另外一个空的数据库中?
- 为什么装了ORACLE9I后,无法再配置IIS服务器,如何解决呢?,,急
- Oracle客户端ODBC Test能连的上服务器,而程序中不行!(急)
- 求在本机连其他主机上的ORACLE数据库的方法(详见内)
- oracle 调用java发出http请求怎么没有请求到服务器
- Linux proc连接oracle数据库
- /usr/lib/hpux64/dld.so: Unable to find library 'libsqlplus.so'.这个错误怎么解决
select mod(484,11) from dual; ---结果是为0
原意这样?
2 (id number(10),
3 name varchar2(100));
Table created
SQL> insert into test select rownum,'test'||rownum from dual connect by rownum<=1000;
1001 rows inserted
SQL> commit;
Commit completeSQL> update test a set a.name='test'
2 where a.id in (select id from (select id ,rownum rn from (select id from test order by id )) where rn<484 and mod(rn,11)=1 );
44 rows updatedSQL> select * from test where name='test' order by id;
ID NAME
----------- --------------------------------------------------------------------------------
1 test
12 test
23 test
34 test
45 test
56 test
67 test
78 test
89 test
100 test
111 test
122 test
133 test
144 test
155 test
166 test
177 test
188 test
199 test
210 test
ID NAME
----------- --------------------------------------------------------------------------------
221 test
232 test
243 test
254 test
265 test
276 test
287 test
298 test
309 test
320 test
331 test
342 test
353 test
364 test
375 test
386 test
397 test
408 test
419 test
430 test
441 test
ID NAME
----------- --------------------------------------------------------------------------------
452 test
463 test
474 test
44 rows selected
SQL>
--rownum 与order by层次问题 需先排序 在加序号 也可以分析函数update table set col='test'
where id in(
select id from
(select id,rownum num from
(select id,col1 from table order by col1)
) where num <=484 and mod(484,11)=1)
-- 或者分析函数
update table set col='test'
where id in(
select id from
(select id,col1,row_number() over(order by col1) rn
from table ) where rn<=484 and mod(rn,11)=1)
就算我把num 放在外层! 还是一样的! 出来的结果还不是我想要的结果!数据串位了!
我现在改成了 row_number() over(order by col1) 同样出现修改的数据串位现象!
这个我测了多次, 前几次都没问题! 多执行几条数据, 而且根据 mod(484,11)=1或者等于2,将每个username值改成不一直。 多试几次就出问题!
update table set col='test'
where id in(
select id from
(select id,rownum num from
(select id,col1 from table order by col1)
) where num <=484 and mod(num,11)=1)