private static SqlQueryExpression Form(PlSqlParser.QueryBlockContext context, out IntoClause into) { var fromClause = FromClauseBuilder.Build(context.fromClause()); SelectColumn[] columns; if (context.all != null) { columns = new[] {new SelectColumn(SqlExpression.Reference(new ObjectName("*")))}; } else { columns = context.selectedElement().Select(SelectElement.BuildColumn).ToArray(); } var query = new SqlQueryExpression(columns); into = null; if (context.DISTINCT() != null || context.UNIQUE() != null) query.Distinct = true; var intoClause = context.into_clause(); if (intoClause != null) { into = new IntoClause(); if (intoClause.objectName() != null) { into.TableName = Name.Object(intoClause.objectName()); } else if (intoClause.variable_name() != null) { into.Variables = intoClause.variable_name().Select(Name.Variable).ToArray(); } } if (fromClause != null) query.FromClause = fromClause; var groupBy = context.groupByClause(); if (groupBy != null && !groupBy.IsEmpty) { query.GroupBy = groupBy.groupByElements().expression().Select(x => new SqlExpressionVisitor().Visit(x)); var having = groupBy.havingClause(); if (having != null) query.HavingExpression = new SqlExpressionVisitor().Visit(having.condition()); } var groupMax = context.groupMaxClause(); if (groupMax != null && !groupMax.IsEmpty) { var maxColumn = Name.Object(groupMax.objectName()); query.GroupMax = maxColumn; } var whereClause = context.whereClause(); if (whereClause != null && !whereClause.IsEmpty) { var currentOf = whereClause.current_of_clause(); if (currentOf != null && !currentOf.IsEmpty) { var cursorName = Name.Simple(currentOf.cursor_name()); throw new NotImplementedException(); } else { query.WhereExpression = new SqlExpressionVisitor().Visit(whereClause.conditionWrapper()); } } return query; }