【发布时间】:2012-08-24 07:04:43
【问题描述】:
我正在使用其他开发人员编写的以下查询:
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
我有两个问题。
首先,我不知道 START WITH、CONNECT BY、PRIOR 关键字在查询中的作用。
其次,当我将 ORDER SIBLINGS BY d.name 更改为 ORDER SIBLINGS BY c.priority desc 时会抛出以下错误消息:=
ORA-01791: not a SELECTed expression
01791. 00000 - "not a SELECTed expression"
我也尝试将优先级的数据类型从数字更改为字符串,但抛出相同的错误。
我想通过 c.priority desc 运行订单查询以产生所需的结果。
【问题讨论】:
-
@hol:你说得对,用这些 oracle 关键字学习。顺便说一句,问题的解决方案是,当我按 c.priority desc 编写 order 时,我忘记在 select 语句上选择 c.priority。现在它工作正常...... :)
-
酷。这是因为结果集是有序的,因此您必须包含它。很高兴我的回答对你有用。