建议,用于匹配SQL查询中的括号的工具

时间:2022-06-14 20:50:13

Can someone can tell me a nice approach to checking how, and where, parenthesis may be missing (or be in excess) in a query such as the following?

有人可以告诉我一个很好的方法来检查在如下查询中如何以及在何处,括号可能会丢失(或过多)?

For example, this query returns error that it is missing right parenthesis. But where??? !

例如,此查询返回错误,即它缺少右括号。但是哪里??? !

SELECT * FROM ( SELECT X.*, ROWNUM AS RN FROM (SELECT ORG_UNIT, QUEUE_NAME, CASE_STATUS, AGENT_ROLE, COUNT(*) AS CASE_COUNT 
   FROM 
   (    
     SELECT ORG_UNIT, QUEUE_NAME, CREATION_TIMESTAMP, CASE_STATUS, AGENT_ROLE
     FROM 
     (   SELECT OU.NAME AS ORG_UNIT,            D.NAME AS QUEUE_NAME, 
                WS.NAME AS CASE_STATUS,  C.ASSIGNED_TO AS AGENT_ID,  C.CREATION_TIMESTAMP AS CREATION_TIMESTAMP,
                CASE NVL(C.ASSIGNED_TO, -1) WHEN -1 THEN 'Unassigned' ELSE RU.ROLE_NAME END AS AGENT_ROLE 
           FROM CASES C 
           JOIN ORGANIZATION_UNITS OU ON OU.ID = C.ORGUNIT_ID       
           JOIN WORKFLOW_STATUSES WS ON WS.ID = C.STATUS_ID 
           JOIN DOMAINS D ON D.ID = C.DOMAIN_ID 
           JOIN DOMAINS DP ON DP.ID = D.PARENT_ID
LEFT OUTER JOIN (SELECT DISTINCT C.ASSIGNED_TO AS AGENT_ID, RL.NAME AS ROLE_NAME 
                                  FROM CASES C 
                                    JOIN DOMAINS D ON D.ID = C.DOMAIN_ID 
                                    JOIN DOMAINS DP ON DP.ID = D.PARENT_ID 
                                    JOIN USER_GROUP_RELATIONS UGR ON UGR.USER_ID = C.ASSIGNED_TO 
                                    JOIN GRP_ORG_DOM_ROLE_RELATIONS GODRR ON (GODRR.GROUP_ID = (SELECT MAX(UGR.GROUP_ID) 
                                                                                                                                                                   FROM USER_GROUP_RELATIONS UGR 
                                                                                                                                                                 WHERE   UGR.USER_ID = C.ASSIGNED_TO) 
                                                                                                                   AND GODRR.DOMAIN_ID =C.DOMAIN_ID
                                                                                                                   AND GODRR.ORGANIZATION_ID = C.ORGUNIT_ID) 
  JOIN ROLES RL ON RL.ID = (SELECT MAX(GODRR.ROLE_ID) 
                                                  FROM GRP_ORG_DOM_ROLE_RELATIONS GODRR 
                                                WHERE GODRR.GROUP_ID = UGR.GROUP_ID 
                                                     AND GODRR.ORGANIZATION_ID = C.ORGUNIT_ID AND GODRR.DOMAIN_ID = C.DOMAIN_ID)            
                                WHERE DP.NAME='DD') RU ON RU.AGENT_ID = C.ASSIGNED_TO 
       WHERE DP.NAME='DD' 
     )  WHERE 1=1
   ) 
   GROUP BY ORG_UNIT, QUEUE_NAME, CASE_STATUS, AGENT_ROLE  
   ORDER BY ORG_UNIT, QUEUE_NAME, CASE_STATUS, AGENT_ROLE order by ORG_UNIT asc ) X ) WHERE RN > 0 AND RN <= 10

1 个解决方案

#1


2  

Crimson Edit and many other text editors and IDEs have brace matching.

Crimson Edit和许多其他文本编辑器和IDE都有大括号匹配。

http://en.wikipedia.org/wiki/Crimson_Editor

If brace match, but are nested wrong, you may need to change your indentation strategy.

如果大括号匹配,但嵌套错误,则可能需要更改缩进策略。

Also, code formatting tools sometimes can make it clear where you missed a paren or nested wrong.

此外,代码格式化工具有时可以清楚地表明您错过了paren或嵌套错误。

Here is one online place where you can paste in your code to see it reformatted.

这是一个在线地方,您可以粘贴代码以查看其重新格式化。

http://www.dpriver.com/pp/sqlformat.htm

#1


2  

Crimson Edit and many other text editors and IDEs have brace matching.

Crimson Edit和许多其他文本编辑器和IDE都有大括号匹配。

http://en.wikipedia.org/wiki/Crimson_Editor

If brace match, but are nested wrong, you may need to change your indentation strategy.

如果大括号匹配,但嵌套错误,则可能需要更改缩进策略。

Also, code formatting tools sometimes can make it clear where you missed a paren or nested wrong.

此外,代码格式化工具有时可以清楚地表明您错过了paren或嵌套错误。

Here is one online place where you can paste in your code to see it reformatted.

这是一个在线地方,您可以粘贴代码以查看其重新格式化。

http://www.dpriver.com/pp/sqlformat.htm