执行oracle查询时出错ORA-00907:缺少右括号

时间:2017-01-03 07:21:46

标签: sql oracle oracle12c

我在执行以下查询时遇到异常。

    SELECT CONSUMER_KEY, AUTHZ_USER,
  ACCESS_TOKEN_TABLE.TENANT_ID, USER_DOMAIN,
  TOKEN_SCOPE, TIME_CREATED,
  REFRESH_TOKEN_TIME_CREATED, VALIDITY_PERIOD,
  REFRESH_TOKEN_VALIDITY_PERIOD, USER_TYPE,
  REFRESH_TOKEN, ACCESS_TOKEN_TABLE.TOKEN_ID,
  GRANT_TYPE, SUBJECT_IDENTIFIER
FROM
  (SELECT TOKEN_ID, CONSUMER_KEY,
    AUTHZ_USER,IDN_OAUTH2_ACCESS_TOKEN.TENANT_ID   AS TENANT_ID,
    IDN_OAUTH2_ACCESS_TOKEN.USER_DOMAIN AS USER_DOMAIN,
    TIME_CREATED, REFRESH_TOKEN_TIME_CREATED,
    VALIDITY_PERIOD, REFRESH_TOKEN_VALIDITY_PERIOD,
    USER_TYPE,REFRESH_TOKEN,
    IDN_OAUTH2_ACCESS_TOKEN.GRANT_TYPE AS GRANT_TYPE,
    SUBJECT_IDENTIFIER
  FROM
    (SELECT *
    FROM IDN_OAUTH2_ACCESS_TOKEN
    WHERE ACCESS_TOKEN='xyz'
    AND TOKEN_STATE   ='ACTIVE'
    ) AS IDN_OAUTH2_ACCESS_TOKEN
  JOIN IDN_OAUTH_CONSUMER_APPS
  ON CONSUMER_KEY_ID = ID
  ) AS ACCESS_TOKEN_TABLE
LEFT JOIN IDN_OAUTH2_ACCESS_TOKEN_SCOPE
ON ACCESS_TOKEN_TABLE.TOKEN_ID = IDN_OAUTH2_ACCESS_TOKEN_SCOPE.TOKEN_ID;

感谢您的帮助以找出此查询的错误。

例外: ORA-00907:缺少右括号

3 个答案:

答案 0 :(得分:4)

您正在使用AS关键字对选择结果进行别名,这会产生此错误。只需删除以下两行中的AS,您的查询就可以正常使用。

 - AS IDN_OAUTH2_ACCESS_TOKEN
 - AS ACCESS_TOKEN_TABLE

答案 1 :(得分:0)

    SELECT CONSUMER_KEY, AUTHZ_USER, ACCESS_TOKEN_TABLE.TENANT_ID, USER_DOMAIN, TOKEN_SCOPE, TIME_CREATED, REFRESH_TOKEN_TIME_CREATED, VALIDITY_PERIOD, REFRESH_TOKEN_VALIDITY_PERIOD, USER_TYPE, REFRESH_TOKEN, ACCESS_TOKEN_TABLE.TOKEN_ID, GRANT_TYPE, SUBJECT_IDENTIFIER FROM (SELECT TOKEN_ID, CONSUMER_KEY, AUTHZ_USER, IDN_OAUTH2_ACCESS_TOKEN.TENANT_ID AS TENANT_ID, IDN_OAUTH2_ACCESS_TOKEN.USER_DOMAIN AS USER_DOMAIN,TIME_CREATED,REFRESH_TOKEN_TIME_CREATED, VALIDITY_PERIOD, REFRESH_TOKEN_VALIDITY_PERIOD, USER_TYPE, REFRESH_TOKEN, IDN_OAUTH2_ACCESS_TOKEN.GRANT_TYPE AS GRANT_TYPE,SUBJECT_IDENTIFIER FROM (SELECT * FROM IDN_OAUTH2_ACCESS_TOKEN WHERE ACCESS_TOKEN='xyz' AND TOKEN_STATE='ACTIVE') AS IDN_OAUTH2_ACCESS_TOKEN JOIN IDN_OAUTH_CONSUMER_APPS as c ON IDN_OAUTH2_ACCESS_TOKEN.CONSUMER_KEY_ID = c.ID) AS ACCESS_TOKEN_TABLE LEFT JOIN IDN_OAUTH2_ACCESS_TOKEN_SCOPE ON ACCESS_TOKEN_TABLE.TOKEN_ID = IDN_OAUTH2_ACCESS_TOKEN_SCOPE.TOKEN_ID;

您已为表提供了别名,但未在join的on子句中使用。

答案 2 :(得分:0)

您已在外部选择查询中显示了14列:

SELECT CONSUMER_KEY,
       AUTHZ_USER,
       ACCESS_TOKEN_TABLE.TENANT_ID,
       USER_DOMAIN,
       TOKEN_SCOPE,
       TIME_CREATED,
       REFRESH_TOKEN_TIME_CREATED,
       VALIDITY_PERIOD,
       REFRESH_TOKEN_VALIDITY_PERIOD,
       USER_TYPE,
       REFRESH_TOKEN,
       ACCESS_TOKEN_TABLE.TOKEN_ID,
       GRANT_TYPE,
       SUBJECT_IDENTIFIER

并仅从13列中检索数据:

FROM (SELECT TOKEN_ID,
             CONSUMER_KEY,
             AUTHZ_USER,
             IDN_OAUTH2_ACCESS_TOKEN.TENANT_ID AS TENANT_ID,
             IDN_OAUTH2_ACCESS_TOKEN.USER_DOMAIN AS USER_DOMAIN,
             TIME_CREATED,
             REFRESH_TOKEN_TIME_CREATED,
             VALIDITY_PERIOD,
             REFRESH_TOKEN_VALIDITY_PERIOD,
             USER_TYPE,
             REFRESH_TOKEN,
             IDN_OAUTH2_ACCESS_TOKEN.GRANT_TYPE AS GRANT_TYPE,
             SUBJECT_IDENTIFIER

和检索数据(来自)的别名,你已经给出了这个!

AS    IDN_OAUTH2_ACCESS_TOKEN
AS ACCESS_TOKEN_TABLE

这些都是你准备好的改变!