plsql查询根据标题no更新行号

时间:2018-05-31 09:06:00

标签: sql oracle

任何人都可以帮我解决这个问题。

我有一个如下所示的示例表,有3个标题记录:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div class="sidebar_lang">
    <span>Language:</span>
    <div class="lang_option">
        <a href="javascript:void(0)" id='ger_btn' class="lang_txt" target="_blank">DE</a>
    <a href="javascript:void(0)" id="eng_btn" class="lang_txt" target="_blank">EN</a>
    </div>
</div>

<script>
$(document).ready(function(){
$("#eng_btn").click(function()
{
     var bn_pathname = window.location.href;
     var en_pathname = bn_pathname.replace("/de_DE/","/en_Us/"); 
    window.location.href = en_pathname;

});

$("#ger_btn").click(function()
{
     var bn_pathname = window.location.href;
     var en_pathname = bn_pathname.replace("/en_Us/","/de_DE/"); 
     window.location.href = en_pathname;

});
});
</script>

我需要将LINE_NUM更新为此特定标头记录,如下表所示。

PO_HEADER ||    ITEM   || LINE_NUM

   1              X 
   1              Y 
   2              Z 
   2              A 
   3              B 

2 个答案:

答案 0 :(得分:1)

您应该使用row_number函数来完成此任务:

create table tx (po_header number(1), item varchar2(1), line_num number(1));

insert into tx values (1,'X', null);
insert into tx values (1,'Y', null);
insert into tx values (2,'Z', null);
insert into tx values (2,'A', null);
insert into tx values (3,'B', null);
insert into tx values (4,'C', null);

update tx a
set a.line_num = (select y.line_num
                  from (select x.po_header, x.item, row_number () over (partition by x.po_header order by x.item) line_num
                        from tx x) y
                  where y.po_header = a.po_header
                    and y.item = a.item);

答案 1 :(得分:0)

一种方法是使用row_number()函数:

select *, row_number() over (partition by po_header order by ?) as LineNum
from table t;

?表示您的订购列,用于指定您的表数据排序。