选择语句将引发“ ORA-00907:缺少右括号”

时间:2018-08-06 08:17:08

标签: sql database oracle oracle12c confluence

我对Oracle有点陌生,似乎无法在下面运行此查询。

SELECT user_key AS oldKey,
       (SELECT 
            user_key
        FROM
            user_mapping AS u
        WHERE lower(u.username) = u.lower_username
          AND lower(u.username) = lower(um.username)
        ) AS newKey,
       um.username,
       um.lower_username
  FROM user_mapping AS um
  WHERE user_key IN (SELECT user_key
                      FROM user_mapping
                      WHERE (lower(username) != lower_username))
                         OR (lower_username is null)

它引发“ ORA-00907:缺少右括号”错误,但是我没有看到任何语法错误,并且在针对MySQL数据库运行查询时,查询工作正常。

检查与缺少括号有关的其他一些问题,但这主要是关于不显式说明主键,或将某些内容指定为非null的问题,但我认为这似乎也不是问题。

请让我知道我在上述任何方面是否缺失或错误。

谢谢。

1 个答案:

答案 0 :(得分:1)

第14行中有一个额外的),并且在结尾处(即第15行之后)缺少了一个)

我已经解决了两个问题。尝试以下

SELECT user_key AS oldKey,
       (SELECT 
            user_key
        FROM
            user_mapping AS u
        WHERE lower(u.username) = u.lower_username
          AND lower(u.username) = lower(um.username)
        ) AS newKey,
       um.username,
       um.lower_username
  FROM user_mapping AS um
  WHERE user_key IN ( SELECT user_key
                      FROM user_mapping
                      WHERE (lower(username) != lower_username)
                         OR (lower_username is null)
                    )