开发者

Need help with error in Oracle SQL query

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.


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
  ^^
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜