2015-10-26 138 views
1

我在BusinessObjects中進行Oracle查詢,並且無法同時使用這三個關鍵字:DISTINCT,SUBSTR和ORDER BY。同時使用DISTINCT,SUBSTR和ORDER BY

它可以使用DISTINCT ORDER BY DISTINCT SUBSTR,但並非所有這三個在一起。

返回的錯誤是「ORA-01791:不是一個SELECTed表達式」。

這工作:

SELECT 
DISTINCT HPD_HELP_DESK.Product_Name 
FROM 
HPD_HELP_DESK 
WHERE REGEXP_LIKE(HPD_HELP_DESK.Product_Name, '^[A-Z]{2}[A-Z]? -') 
ORDER BY HPD_HELP_DESK.Product_Name 

這工作太:

SELECT 
DISTINCT SUBSTR(HPD_HELP_DESK.Product_Name, 1, 3) 
FROM 
HPD_HELP_DESK 
WHERE REGEXP_LIKE(HPD_HELP_DESK.Product_Name, '^[A-Z]{2}[A-Z]? -') 

能否請你告訴我在寫什麼,使其工作? 謝謝。

回答

2

添加別名SUBSTRORDER BY使用:

SELECT DISTINCT SUBSTR(HPD_HELP_DESK.Product_Name, 1, 3) AS result 
FROM HPD_HELP_DESK 
WHERE REGEXP_LIKE(HPD_HELP_DESK.Product_Name, '^[A-Z]{2}[A-Z]? -') 
ORDER BY result; 

或:

SELECT DISTINCT SUBSTR(HPD_HELP_DESK.Product_Name, 1, 3) 
FROM HPD_HELP_DESK 
WHERE REGEXP_LIKE(HPD_HELP_DESK.Product_Name, '^[A-Z]{2}[A-Z]? -') 
ORDER BY SUBSTR(HPD_HELP_DESK.Product_Name, 1, 3); 
+1

它的工作原理!非常感謝。 – v01dv01d

0

可以使用的列數:

SELECT DISTINCT SUBSTR(HPD_HELP_DESK.Product_Name, 1, 3) 
FROM HPD_HELP_DESK 
WHERE REGEXP_LIKE(HPD_HELP_DESK.Product_Name, '^[A-Z]{2}[A-Z]? -') 
ORDER BY 1