0

我在我的 Oracle DB 中使用了以下查询:

UPDATE test5_rdf_memoization 
SET object ='galib' 
WHERE ( predicate='platform' AND 
    object IS NULL AND 
    subject IN ( SELECT subject 
                FROM test5_rdf_memoization t1, 
                    test_parameters_new_5 t2, 
                    test_parameter_detail t3 
                WHERE (t1.object = t2.id AND 
                    t2.id = t3.parameter AND 
                    t1.predicate = 'parameter' AND 
                    t3.host_tool_detail = 1 AND 
                    (t1.subject >= 624))  
                order by t1.subject) );

但它给了我以下错误

 Error starting at line 1 in command: 
    UPDATE test5_rdf_memoization SET
     object ='galib' WHERE ( predicate='platform' AND object IS NULL AND
     subject IN ( SELECT subject FROM test5_rdf_memoization t1,
     test_parameters_new_5 t2, test_parameter_detail t3 WHERE (t1.object =
     t2.id AND t2.id = t3.parameter AND t1.predicate = 'parameter' AND
     t3.host_tool_detail = 1 AND (t1.subject >= 624))  order by t1.subject)
     ) 
 Error at Command Line:2 Column:10 Error report: SQL Error:
 ORA-00907: missing right parenthesis
 00907. 00000 -  "missing right parenthesis"
 *Cause:    
 *Action:

我尝试过使用不同的括号组合,但它不起作用。有人可以帮我解决这个问题吗?

4

2 回答 2

1

试试这个——我只看到你的IN陈述需要一组括号。我还删除了ORDER BY声明:

UPDATE test5_rdf_memoization 
SET object ='galib' 
WHERE predicate='platform' 
   AND object IS NULL 
   AND subject IN ( 
       SELECT subject 
       FROM test5_rdf_memoization t1, 
            test_parameters_new_5 t2, 
            test_parameter_detail t3 
       WHERE t1.object = t2.id 
            AND t2.id = t3.parameter 
            AND t1.predicate = 'parameter' 
            AND t3.host_tool_detail = 1 
            AND t1.subject >= 624)

我更喜欢使用INNER JOINs

UPDATE test5_rdf_memoization 
SET object ='galib' 
WHERE predicate='platform' 
   AND object IS NULL 
   AND subject IN ( 
       SELECT subject 
       FROM test5_rdf_memoization t1 
           INNER JOIN test_parameters_new_5 t2 
               ON t1.object = t2.id 
           INNER JOIN test_parameter_detail t3 
               ON t2.id = t3.parameter 
       WHERE t1.predicate = 'parameter' 
            AND t3.host_tool_detail = 1 
            AND t1.subject >= 624)
于 2013-03-29T01:59:41.950 回答
1

Oracle 经常抛出ORA-00907: missing right parenthesis来指示语法错误,通常是因为它在找到匹配的括号之前发现了非法子句。

在这种情况下,它反对该ORDER BY条款。我们不能订购这样的子查询。实际上排序并不重要,因为该语句只是测试记录的存在,所以谁在乎我们是先随机找到记录还是排序为字母数字第三?好吧,显然排序会消耗 CPU 周期,因此从性能角度来看,不必要的排序是不好的,但它不会改变结果。

“我需要按主题分类的数据。”

不,你没有。您正在将 test5_rdf_memoization与一组特定条件匹配的所有记录更新为相同的值。同样,它们更新的顺序并不重要,因为结果是相同的。


如果您对此解释不满意,请编辑您的问题以解释您的业务需求,以便我们提供可行的解决方案。

于 2013-03-29T09:55:16.113 回答