无法在Oracle中使用ROWNUM更新列

时间:2016-06-14 16:50:35

标签: sql oracle tsql oracle10g

我有一个类似于下面的Oracle结果集

enter image description here

我需要用RNUM替换OLD_ID。我正在使用以下查询

$(document).on('click', '.data-info', function(){
    alert($(this).closest('.popover').prev().data('info'));
});

这给了我oracle错误

  

"无法在源表中获得稳定的行集"
  *原因:由于dml较大,无法获得稳定的行集              活动或非确定性的where子句   *操作:删除任何非确定性where子句并重新发出dml。

有什么想法吗?

3 个答案:

答案 0 :(得分:0)

您可能在S

上有重复项

答案 1 :(得分:0)

没有你的桌子所以我无法测试但是怎么样

UPDATE (SELECT rnum, old_id
          FROM (SELECT OLD_ID,
                       FBU_FFF_FFY,
                       FBU_FFY_MONTH,
                       ROW_NUMBER ()
                       OVER (PARTITION BY fbu_ffy_month, fbu_fff_ffy
                             ORDER BY fbu_ffy_month, fbu_fff_ffy)
                          rnum
                  FROM x) s,
               x u
         WHERE     u.FBU_FFF_FFY = s.FBU_FFF_FFY
               AND u.FBU_FFY_MONTH = s.FBU_FFY_MONTH)
   SET old_id = rnum

答案 2 :(得分:0)

你可以尝试使用rowid加入自己。类似的东西:

SQL> create table x
(
old_id number,
val varchar2(10),
yr varchar2(4),
mth varchar2(2)
)
Table created.
SQL> insert into x values (1, 'X', '2016','01')
1 row created.
SQL> insert into x values (2, 'Y', '2016','01')
1 row created.
SQL> insert into x values (3, 'X', '2016','02')
1 row created.
SQL> insert into x values (4, 'Y', '2016','02')
1 row created.
SQL> insert into x values (5, 'X', '2016','03')
1 row created.
SQL> insert into x values (6, 'Y', '2016','03')
1 row created.
SQL> commit
Commit complete.
SQL> select * from x

    OLD_ID VAL        YR   MTH
---------- ---------- ---- ---
         1 X          2016 01 
         2 Y          2016 01 
         3 X          2016 02 
         4 Y          2016 02 
         5 X          2016 03 
         6 Y          2016 03 

6 rows selected.
SQL> -- this will update ALL rows of table x
SQL> update x
set old_id = (
    select y.rnum
    from x x2
    JOIN (
    select rowid as row_id, yr, mth, row_number() over (partition by yr, mth order by yr, mth) rnum
    from x ) y
    ON (x2.rowid = y.row_id)
    where x.rowid = x2.rowid
)
6 rows updated.
SQL> commit
Commit complete.
SQL> select * from x

    OLD_ID VAL        YR   MTH
---------- ---------- ---- ---
         1 X          2016 01 
         2 Y          2016 01 
         1 X          2016 02 
         2 Y          2016 02 
         1 X          2016 03 
         2 Y          2016 03 

6 rows selected.