2

this is the query:

SELECT DISTINCT pprom.pk
FROM
(
    SELECT
      item_t0.SourcePK as pk
    FROM
      links item_t0
    WHERE (? =  item_t0.TargetPK   AND  item_t0.SourcePK  in (?,?))
    AND (item_t0.TypePkString=? )
    UNION
    SELECT
      item_t1.TargetPK as pk
    FROM
      cat2prodrel item_t1
    WHERE ( item_t1.SourcePK  in (? )  AND  item_t1.TargetPK  in (?,?))
    AND (item_t1.TypePkString=? )
) AS pprom

And this is the error:

ORA-00933: SQL command not properly ended

Any ideas what could be wrong?

Edit:

The question marks are replaced by PKs of the respective items:

values = [PropertyValue:8802745684882, PropertyValue:8796177006593, PropertyValue:8796201713665, 8796110520402, PropertyValue:8796125954190, PropertyValue:8796177006593, PropertyValue:8796201713665, 8796101705810]

Edit 2:

The query is executed deep inside some proprietary software system so I don't know exactly the code that runs it.

Edit 3:

I found one more query that's a little shorter but results in the same error message:

SELECT DISTINCT pprom.pk 
FROM 
( 
    SELECT  
        item_t0.SourcePK  as pk 
    FROM 
        links item_t0 
    WHERE (? =  item_t0.TargetPK  AND  item_t0.SourcePK  in (?)) 
        AND (item_t0.TypePkString=? )  
) AS pprom

Using the following values:

values = [PropertyValue:8799960601490, PropertyValue:8796177006593, 8796110520402]

Edit 4

I found the SQL code that is sent to the db after replacing the values:

SELECT DISTINCT pprom.pk 
FROM 
( 
    SELECT  
        item_t0.SourcePK  as pk 
    FROM 
        links item_t0 
    WHERE (8801631769490 =  item_t0.TargetPK   AND  item_t0.SourcePK  in (8796177006593)) 
        AND (item_t0.TypePkString=8796110520402 )  
) AS pprom

I also tried executing the inner SELECT statement and that alone runs ok and returns a single PK as a result.

6
  • 1
    making your query readable would be a step in the right direction =D Commented Jul 20, 2011 at 8:50
  • What are those question marks? especially this part: (?,?)? Commented Jul 20, 2011 at 8:52
  • How do you execute this command? Commented Jul 20, 2011 at 8:54
  • if you run each bit individually? Commented Jul 20, 2011 at 8:58
  • Maybe no value for TypePkString is specified? Your values only show numbers... Commented Jul 20, 2011 at 8:59

1 Answer 1

3

I could not find any obvious syntax error in your query so I'd presume the issue is the client library you are using to convert the ? place holders into actual values. Your question edit displays a sort of dump where there are 8 integers but only 6 PropertyValue items. Make sure that's not the issue: IN (?, ?) requires 2 parameters.

Edit

Try removing the AS keyword when you assign an alias to the subquery:

SELECT DISTINCT pprom.pk 
FROM 
( 
    SELECT  
        item_t0.SourcePK  as pk 
    FROM 
        links item_t0 
    WHERE (8801631769490 =  item_t0.TargetPK   AND  item_t0.SourcePK  in (8796177006593)) 
        AND (item_t0.TypePkString=8796110520402 )  
) AS pprom
  ^^
Sign up to request clarification or add additional context in comments.

4 Comments

If there was a parameter missing would this result in the ORA-00933 error? I thought it might have something to do with the general syntax of the query (but as you might have guessed I'm not an Oracle expert).
Certainly, if it was missing. Your app might be filling it with a bogus value. (We know nothing about your code.)
Álvaro is right, the AS in ) AS pprom is causing the issue.
Thanks! You saved my project today!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.