0

I am using the following query written by other developers:

SELECT DISTINCT c.id category_id,
  c.parent_id,
  d.name AS category_name,
  level
FROM category c,
  category_language d
WHERE c.id                                 = d.category_id
AND c.is_active                            = 1
AND c.is_deleted                           = 0
AND c.deleted_date                        IS NULL
AND d.is_active                            = 1
AND d.is_deleted                           = 0
AND d.deleted_date                        IS NULL
AND ((to_date(d.expiry_date,'DD-MON-YYYY') > to_date(sysdate,'DD-MON-YYYY'))
OR d.expiry_date                          IS NULL)
AND d.language_id                          = 1
AND c.cat_type_id                          = 1
  START WITH c.parent_id                   =1308206844
  CONNECT BY c.parent_id                   = prior c.id
ORDER SIBLINGS BY d.name 

I had two problems.

First, I don't know how START WITH, CONNECT BY, PRIOR Keywords are working in query.

Second, when I change ORDER SIBLINGS BY d.name to ORDER SIBLINGS BY c.priority desc following error message is thrown:=

ORA-01791: not a SELECTed expression
01791. 00000 -  "not a SELECTed expression"

I had also tried to change the Datatype of priority from number to string but same error is thrown.

I want to run query of order by c.priority desc for producing desired results.

4

1 回答 1

3

关键字START WITH, CONNECT BY, PRIOR用于显示层次结构。在我看来,这个链接是一个非常好的教程:http: //www.adp-gmbh.ch/ora/sql/connect_by.html

至少我通过示例学会了如何使用它。也许这也为您提供了ORDER SIBLINGS BY真正含义的答案,然后您可以回答自己如何避免错误消息。显然 Oracle 希望您将该列包含在选定的列中。ORDER SIBLINGS特定于层次结构,你可以谷歌它。但我认为你首先需要了解START WITH, CONNECT BY, PRIOR

也许你不想做一个ORDER SIBLINGS BYORDER BY只有一个。

于 2012-08-24T07:15:55.490 回答