使用match_recognize时出错ORA-00918

时间:2017-01-14 10:56:33

标签: sql oracle oracle12c

我正在尝试学习Oracle 12c引入的模式匹配。但是,对ORA-00918:列进行了模糊定义   使用以下代码。我不确定我错过了哪里

    SELECT CUSTOMER_ID,ORDER_TOTAL,ORDER_TIMESTAMP FROM DEMO_ORDERS MATCH_RECOGNIZE(
  PARTITION BY CUSTOMER_ID
  ORDER BY CUSTOMER_ID,ORDER_TIMESTAMP

  MEASURES
   A.CUSTOMER_ID AS CUSTOMER,
    A.ORDER_TOTAL AS TOTAL_AMT,
    A.ORDER_TIMESTAMP AS WHEN_HPA
   ALL ROWS PER MATCH
  PATTERN( A B* )
  DEFINE
    B AS (B.ORDER_TOTAL < PREV(B.ORDER_TOTAL))


    )

1 个答案:

答案 0 :(得分:0)

问题是你的order by条款;它似乎同时看到原始表列customer_id和匹配分区值。

但是你按customer_id进行分区,所以按顺序进行排序无论如何都没有任何意义。排序适用于分区(如分析函数)。所以你可以删除它:

SELECT CUSTOMER_ID,ORDER_TOTAL,ORDER_TIMESTAMP FROM DEMO_ORDERS MATCH_RECOGNIZE(
  PARTITION BY CUSTOMER_ID
  ORDER BY ORDER_TIMESTAMP
...