简体   繁体   中英

ORA-00905: missing keyword error on query that runs fine in SQL Developer

I'm trying to access information from a few different tables in a schema, using the JOIN function. The code was working fine until I added the FULL OUTER JOIN on TABLE3. I'm fairly new to oracle so although I've been reading up on it, I haven't been able to pinpoint my mistake as of yet.

The interesting point to note here is that this same query is running perfectly on Oracle SQL Developer, but throwing the missing keyword error when I run it with the rest of my code in Java (Netbeans IDE). Is there any chance there are different syntax requirements for the two?

Here is my code:

SELECT 
t2.A1 as temp1, 
t2.A2 as temp2, 
t2.A3 as temp3, 
t2.A4 as temp4, 
t2.A5 as temp5, 
t2.A6 as temp6, 
t2.A7 as temp7, 
t2.A8 as temp8, 
t3.A9 as temp9,  
t2.A10 as temp10, 
t2.A11 as temp11, 
t2.A12 as temp12, 
t2.A13 as temp13, 
t2.A14 as temp14, 
t2.A15 as temp15,
t2.A16 as temp16, 
t2.A17 as temp17, 
t2.A18 as temp18, 
t2.A19 as temp19, 
t2.A20 as temp20, 
t2.A9 as temp21, 
t2.A21 as temp22, 
t2.A22 as temp23,
t1.deets as deets 
FROM SCHEMA1.TABLE2 t2 
FULL OUTER JOIN 
    SCHEMA1.TABLE3 t3
    ON t2.A1 = t3.A23
LEFT OUTER JOIN 
    (select A24, LISTAGG(A25, ',') WITHIN GROUP (ORDER BY A26) as deets 
        FROM SCHEMA1.NA av 
        WHERE (A26 = 'TYPE1' OR A26 = 'TYPE2') 
        Group by A24) t1 
    ON t1.A24 =  t2.A1 
WHERE 
    (t2.A2 between (TO_CHAR (SYSDATE, 'YYYYMMDD') || '000000') 
        AND (TO_CHAR (SYSDATE+15, 'YYYYMMDD') || '000000') 
    OR t2.A11 between (TO_CHAR (SYSDATE, 'YYYYMMDD') || '000000') 
        AND (TO_CHAR (SYSDATE+15, 'YYYYMMDD') || '000000')) 
    AND TRIM(t2.A27) IS NOT NULL 
    AND t2.A28 = 'SOMESPEC' 
    AND t2.A3 = 'SOMEOTHERSPEC'
order by temp2 desc;

And here is the error I'm getting:

[DEBUG: 2018-11-20 08:58:24.426] [query]
java.sql.SQLException: ORA-00905: missing keyword

Any advice would be appreciated

EDIT: Here is the query in Java as well:

String query = "SELECT "
+ "t2.A1 as temp1, "
+ "t2.A2 as temp2, "
+ "t2.A3 as temp3, "
+ "t2.A4 as temp4, "
+ "t2.A5 as temp5, "
+ "t2.A6 as temp6, "
+ "t2.A7 as temp7, "
+ "t2.A8 as temp8, "
+ "t3.A9 as temp9, " 
+ "t2.A10 as temp10, "
+ "t2.A11 as temp11, "
+ "t2.A12 as temp12, "
+ "t2.A13 as temp13, "
+ "t2.A14 as temp14, "
+ "t2.A15 as temp15, "
+ "t2.A16 as temp16, "
+ "t2.A17 as temp17, "
+ "t2.A18 as temp18, "
+ "t2.A19 as temp19, "
+ "t2.A20 as temp20, "
+ "t2.A9 as temp21, "
+ "t2.A21 as temp22, "
+ "t2.A22 as temp23, "                                                
+ "t1.deets as deets  "
+ "FROM SCHEMA1.TABLE2 t2 "
+ "FULL OUTER JOIN "
    + "SCHEMA1.TABLE3 t3"
    + "ON t2.A1 = t3.A23"
+ "LEFT OUTER JOIN "
        + "(select A24, LISTAGG(A25, ',') WITHIN GROUP (ORDER BY A26) as deets  "
            + "FROM SCHEMA1.NA av  "
            + "WHERE (A26 = 'TYPE1' OR A26 = 'TYPE2')  "
            + "Group by A24) t1  "
        +"ON t1.A24 =  t2.A1 "
+ "WHERE "
+ "(t2.A2 between (TO_CHAR (SYSDATE, 'YYYYMMDD') || '000000')  "
        + "AND (TO_CHAR (SYSDATE+15, 'YYYYMMDD') || '000000') "
    + "OR t2.A11 between (TO_CHAR (SYSDATE, 'YYYYMMDD') || '000000') "
        + "AND (TO_CHAR (SYSDATE+15, 'YYYYMMDD') || '000000')) "
     +"AND "
        + "TRIM(t2.A27) IS NOT NULL  "
     + "AND t2.A28 = 'SOMESPEC' "
     + "AND t2.A3 = 'SOMEOTHERSPEC'"
+ "order by temp2 desc";

Add trailing blank to the lines

+ "SCHEMA1.TABLE3 t3"
+ "ON t2.A1 = t3.A23"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM