我在Oracle SQL Developer中尝试使用自引用子查询更新表时遇到问题。我相信我已经正确设置了查询,但是每当我尝试运行它时,尽管所有的括号都正确匹配,但我都得到了一个通用的“缺少右括号”错误。
简而言之,我正在尝试更新一个基于ROW_NUMBER()函数的事务序列列,该函数对我要更新的表内的值进行分区。我设置了一个查询来子查询分区窗口,并根据rownum更新表。
有没有办法重写这篇文章,让它正常工作?我不确定是什么抛出了括号错误。
update tbl a
set transseq = (select sqtransseq from (select row_number() OVER(Partition by location order by rownum) as sqtransseq, rownum
from tbl ) as b
where a.rownum = b.rownum)```发布于 2021-06-19 00:03:56
rownum不会像你想的那样做。我觉得你把它和rowid搞混了
update tbl a
set transseq = (select sqtransseq
from (select t.*,
row_number() OVER(Partition by location order by location) as sqtransseq
from tbl t
) b
where a.rowid = b.rowid
);但是,这不起作用,因为窗口函数不允许使用rowid。您可以使用将rowid转换为字符串的技巧来实现这一点:
update tbl a
set transseq = (select sqtransseq
from (select t.*, rowidtochar(rowid) as rowid_str,
row_number() over (Partition by location order by location) as sqtransseq
from tbl t
) b
where rowidtochar(a.rowid) = b.rowid_str
);或者用不同的方式表达逻辑:
update tbl a
set transseq = (select count(*)
from tbl b
where b.location = a.location and b.rowid <= a.rowid
);https://stackoverflow.com/questions/68038273
复制相似问题