2016-11-15 378 views
-1

我编译这个功能,但得到错误:在窗口规范PL/SQL:ORA-30485:在窗口规范缺失的ORDER BY表达

CREATE OR REPLACE FUNCTION WFir_get_act_section_cd(firnum IN NUMBER,langcd IN NUMBER) RETURN VARCHAR2 
       as 
      ACTSEC VARCHAR2(1500); 
       BEGIN 
        begin 
    --- ERROR START      
select ltrim(max(sys_connect_by_path(NVL(act_long,' ') || '/' || NVL(section,' '),',')),',') as FIR_ACT_SEC into ACTSEC from(select NVL(act_long,' ') || '/' || NVL(section,' '), row_number() over() rn from rep_fir_sections sec 
         INNER JOIN m_act a on sec.act_cd = a.act_cd 
         INNER JOIN m_section c on sec.section_cd = c.section_code 
         and FIR_REG_NUM = FIRNum 
         and a.lang_cd = langcd) WHERE ROWNUM <=1 start with rn = 1 
         connect by prior rn = rn -1; 
         EXCEPTION 
         WHEN NO_DATA_FOUND THEN 
         NULL; 
        end; 
        return ACTSEC; 
       END; 

缺少ORDER BY表达当我们正在编译上述功能后迁移该函数形式MYSQL到Oracle我收到错误

“窗口规范缺失的ORDER BY表达”我不知道为什么我收到此错误,请帮我解决这个错误

+1

'row_number()over()'不正确。要分配一个row_number,你必须指定'按某个列排序'。如果您没有指定系统将它们放入的订单,系统不知道要分配给#1的行。即使'null by order'或'order by 1'也应该有效;但你可能会想要一个特定的字段或字段来排序。换句话说,在Row_number窗口函数中'order by'不是可选的。 [Doc Link](http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions137.htm) – xQbert

回答

1

Row_number() over()不正确。

order by是要求row_number工作。

Row_number() over (order by Null /*or you decide what field list*/)

要分配row_number,您必须指定order by some column。如果您没有指定系统将它们放入的订单,系统不知道要分配给#1的行。即使order by nullorder by 1应该工作;但你可能会想要一个特定的字段或字段来排序。

换句话说,在Row_number窗口函数中,order by不是可选的。

Doc Link ” ...... ROW_NUMBER是一个解析函数,它分配给其施加一个唯一的编号,以每行(或者在分区中的每个行或由查询返回的每一行),在有序order_by_条款中指定的行的序列,从1开始。...“

这意味着如果没有订单,则不能分配行号。