我正在尝试学习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))
)
答案 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
...