use of com.alibaba.druid.sql.dialect.oracle.ast.clause.CycleClause in project druid by alibaba.
the class OracleSelectParser method withSubquery.
protected void withSubquery(SQLSelect select) {
if (lexer.token() == Token.WITH) {
lexer.nextToken();
SQLWithSubqueryClause subqueryFactoringClause = new SQLWithSubqueryClause();
for (; ; ) {
OracleWithSubqueryEntry entry = new OracleWithSubqueryEntry();
entry.setName((SQLIdentifierExpr) this.exprParser.name());
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
exprParser.names(entry.getColumns());
accept(Token.RPAREN);
}
accept(Token.AS);
accept(Token.LPAREN);
entry.setSubQuery(select());
accept(Token.RPAREN);
if (identifierEquals("SEARCH")) {
lexer.nextToken();
SearchClause searchClause = new SearchClause();
if (lexer.token() != Token.IDENTIFIER) {
throw new ParserException("syntax erorr : " + lexer.token());
}
searchClause.setType(SearchClause.Type.valueOf(lexer.stringVal()));
lexer.nextToken();
acceptIdentifier("FIRST");
accept(Token.BY);
searchClause.addItem(exprParser.parseSelectOrderByItem());
while (lexer.token() == (Token.COMMA)) {
lexer.nextToken();
searchClause.addItem(exprParser.parseSelectOrderByItem());
}
accept(Token.SET);
searchClause.setOrderingColumn((SQLIdentifierExpr) exprParser.name());
entry.setSearchClause(searchClause);
}
if (identifierEquals("CYCLE")) {
lexer.nextToken();
CycleClause cycleClause = new CycleClause();
exprParser.exprList(cycleClause.getAliases(), cycleClause);
accept(Token.SET);
cycleClause.setMark(exprParser.expr());
accept(Token.TO);
cycleClause.setValue(exprParser.expr());
accept(Token.DEFAULT);
cycleClause.setDefaultValue(exprParser.expr());
entry.setCycleClause(cycleClause);
}
subqueryFactoringClause.addEntry(entry);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
select.setWithSubQuery(subqueryFactoringClause);
}
}
Aggregations