Skip to content

Commit

Permalink
[Plsql] pivot_clause and unpivot_clause can have own alias (#4363)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiefei30 authored Dec 22, 2024
1 parent f54fe1c commit 7f917ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sql/plsql/PlSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -5986,7 +5986,7 @@ flashback_query_clause
;

pivot_clause
: PIVOT XML? '(' pivot_element (',' pivot_element)* pivot_for_clause pivot_in_clause ')'
: PIVOT XML? '(' pivot_element (',' pivot_element)* pivot_for_clause pivot_in_clause ')' table_alias?
;

pivot_element
Expand All @@ -6011,7 +6011,7 @@ pivot_in_clause_elements
;

unpivot_clause
: UNPIVOT ((INCLUDE | EXCLUDE) NULLS)? '(' (column_name | paren_column_list) pivot_for_clause unpivot_in_clause ')'
: UNPIVOT ((INCLUDE | EXCLUDE) NULLS)? '(' (column_name | paren_column_list) pivot_for_clause unpivot_in_clause ')' table_alias?
;

unpivot_in_clause
Expand Down
9 changes: 9 additions & 0 deletions sql/plsql/examples/pivot14.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT s2.id, name, subject, score
FROM scores2 s1
UNPIVOT (
score FOR subject IN (
chinese_score AS 'Chinese',
math_score AS 'Math',
english_score AS 'English'
)
) s2;
6 changes: 6 additions & 0 deletions sql/plsql/examples/pivot15.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT *
FROM (SELECT id, name, subject, score FROM scores) s1
PIVOT (
MAX(score)
FOR subject IN ('Chinese', 'Math', 'English')
) s2;

0 comments on commit 7f917ad

Please sign in to comment.