【发布时间】:2015-12-01 16:53:52
【问题描述】:
我正在对 SQL 查询进行一些字符串解析,并且在识别和提取嵌套查询方面遇到了一些十字路口。在这种情况下:
select name, wins
from mlb_team
where wins > (select avg(wins) from mlb_team) and league = 'NL'
order by wins desc
我想提取(select avg(wins) from mlb_team)。在嵌套查询的情况下会出现一个更全局的问题,该查询包含嵌套查询的父查询中的关键字之后的关键字。即
select columns
from table
where column_val > (select avg(column) from table where conditional order by column asc) and league = 'NL'
order by wins desc
嵌套查询与父查询一样包含 order by 子句,因此单独搜索该关键字无法使此代码更通用。我希望能够放入任何查询并让它提取嵌套查询。
提示或建议会有所帮助。我目前正在使用大量正则表达式来提取子句,并且单表查询处理正常(即我自己获取每个单独的子句)但是对于嵌套查询我遇到了困难。
谢谢大家!
【问题讨论】:
-
你现在编码了什么?
标签: java sql regex string-parsing