How To Get Select Clause's Body With Jsqlparser
I'm using JsqlParser 0.8.0. I have the following string: String sql = 'SELECT table alias FROM table;'; CCJSqlParserManager pm = new CCJSqlParserManager(); Select s = (Select) pm
Solution 1:
SelectBody is of type PlainSelect. This is not equivalent to the SelectItems which you want to get. This is an example for getting these items:
String sqlStr = "SELECT mytable alias FROM mytable";
Select select = (Select)CCJSqlParserUtil.parse(sqlStr);
System.out.println(select.getSelectBody());
PlainSelect pl = (PlainSelect)select.getSelectBody();
for (SelectItem item : pl.getSelectItems()) {
System.out.println(item.toString());
}
By the way this example is using JSqlParser V0.9.3 but the relevant parts of getting the SelectItems are identical in V0.8.0.
You should not using keywords as column or tablenames. This could confuse in many ways the parsing process. However, more and more keywords are allowed in recent versions of JSqlParser.
Post a Comment for "How To Get Select Clause's Body With Jsqlparser"