错误:ORA-00907:缺少右括号

时间:2017-07-22 17:49:37

标签: sql oracle

我目前正在处理一个小型SQL查询,但我收到了以下错误:

  

ORA-00907:缺少右括号。

以下是代码:

SELECT actor.first_name Vorname,
       actor.last_name  Nachname,
       film.length      Filmlaenge
FROM   actor
       INNER JOIN (film_actor
                   INNER JOIN film
                     ON film.film_id = film_actor.film_id)
         ON actor.actor_id = film_actor.actor_id
ORDER  BY film.length DESC
LIMIT 10

1 个答案:

答案 0 :(得分:0)

不要像这样嵌套连接。将ON放在JOIN之后。以下适用于最新版本的Oracle:

SELECT a.first_name Vorname, a.last_name Nachname, f.length as Filmlaenge
FROM actor a INNER JOIN
     film_actor a
     ON a.actor_id = fa.actor_id INNER JOIN 
     film f
     ON f.film_id = fa.film_id
ORDER BY f.length DESC
FETCH FIRST 10 ROWS ONLY;

在早期版本中,您可以这样做:

SELECT fa.*
FROM (SELECT a.first_name Vorname, a.last_name Nachname, f.length as Filmlaenge
      FROM actor a INNER JOIN
           film_actor a
           ON a.actor_id = fa.actor_id INNER JOIN 
           film f
           ON f.film_id = fa.film_id
      ORDER BY f.length DESC
     ) fa
WHERE rownum <= 10;