Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORA-00920: invalid relational operator 2

Status
Not open for further replies.

missmis44

MIS
Sep 11, 2002
22
US
More details in thread1177-1136650
I am getting the following error: ORA-00920: invalid relational operator with this script:


Code:
SELECT J.BOOK_ID, A.FEL_MIS_WT, J.BOOKDATE, A.ARRE_ID 
FROM JMMAIN J, ARMAIN A        
WHERE  (J.BOOK_ID,DECODE(A.FEL_MIS_WT, 'F',1,'W',2,'M',3)||J.BOOKDATE,A.ARRE_ID) IN
(SELECT J.BOOK_ID, MIN(DECODE(A.FEL_MIS_WT, 'F',1,'W',2,'M',3)||J.BOOKDDATE,A.ARRE_ID)) 
AND J.BOOK_ID = A.BOOK_ID AND TO_CHAR(J.BOOKDATE,'YYYYMMDD') BETWEEN '20040101' AND '20041231'
ORDER BY J.BOOK_ID
 
Helps a bit when spaced out:
Code:
select J.BOOK_ID, A.FEL_MIS_WT, J.BOOKDATE, A.ARRE_ID
from   JMMAIN J, ARMAIN A
where  (J.BOOK_ID, DECODE(A.FEL_MIS_WT,'F',1,'W',2,'M',3)
         || J.BOOKDATE, A.ARRE_ID) 
        in
       (select J.BOOK_ID, 
           min(DECODE(A.FEL_MIS_WT,'F',1,'W',2,'M',3)
                      || J.BOOKDDATE,A.ARRE_ID)
         [COLOR=RED]-- from? need different aliases[/COLOR]
         [COLOR=RED]-- group by?[/COLOR]
       )
and    J.BOOK_ID = A.BOOK_ID
and    TO_CHAR(J.BOOKDATE,'YYYYMMDD')
         between '20040101' and '20041231'
order  by J.BOOK_ID

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
Author and Sole Proprietor of: Emu Products Plus
 
I am now getting the following error:
MIN(DECODE(R.FEL_MIS_WT,'F',1,'W',2,'M',3)
*
ERROR at line 7:
ORA-00920: invalid relational operator
Code:
SELECT J.BOOK_ID, A.FEL_MIS_WT, J.BOOKDATE, A.ARRE_ID
FROM   JMMAIN J, ARMAIN A
WHERE  (J.BOOK_ID, DECODE(A.FEL_MIS_WT,'F',1,'W',2,'M',3)
         || J.BOOKDATE, A.ARRE_ID) 
        IN
       (SELECT M.BOOK_ID, 
           MIN(DECODE(R.FEL_MIS_WT,'F',1,'W',2,'M',3)
                      || M.BOOKDDATE,R.ARRE_ID)
         FROM JMMAIN M, ARMAIN R
       )
AND   J.BOOK_ID = A.BOOK_ID
AND    TO_CHAR(J.BOOKDATE,'YYYYMMDD')
         BETWEEN '20040101' AND '20041231'
ORDER BY J.BOOK_ID
 
MissMis,

Your attempt to incorporate "R.ARRE_ID" in the subquery produced a syntax error because your closing paren on the DECODE is misplaced. Also, as a second issue, if you need to incorporate the "ARMAIN" table in the subquery, you should also have a WHERE clause that defines how you wish to join the tables, else you receive a "Cartesian Product" of the two tables: every row in "JMMAIN" matched with every row in "ARMAIN"...definitely not what you want.

Relocating the misplaced closing paren and inclusion of a joining WHERE clause causes your subquery to read something like:
Code:
...    (SELECT M.BOOK_ID, 
           MIN(DECODE(R.FEL_MIS_WT,'F',1,'W',2,'M',3)
                      || M.BOOKDDATE[b])[/b],R.ARRE_ID
         FROM JMMAIN M, ARMAIN R
         [b]WHERE <some condition>[/b]
       )
Let us know if this improves your results.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
Do not forget that it also needs a group by clause.

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
Author and Sole Proprietor of: Emu Products Plus
 
Thanks Mufasa and Barb!!! You two are awesome. Here is my final solution.
Code:
SELECT J.BOOK_ID, A.FEL_MIS_WT, J.BOOKDATE
     FROM JMMAIN J, ARMAIN A  
     WHERE (A.BOOK_ID,DECODE(A.FEL_MIS_WT, 'F',1,'W',2,'M',3)||A.ARRE_ID) IN
     (SELECT A.BOOK_ID, MIN(DECODE(A.FEL_MIS_WT, 'F',1,'W',2,'M',3)||A.ARRE_ID)
     FROM ARMAIN A 
     GROUP BY A.BOOK_ID) AND J.BOOK_ID = A.BOOK_ID AND 
     TO_CHAR(J.BOOKDATE,'YYYYMMDD') BETWEEN '20040101' AND '20041231'
ORDER BY J.BOOK_ID;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top