diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md
index 37502a57652..885c20c5b05 100644
--- a/docs/pages/release_notes.md
+++ b/docs/pages/release_notes.md
@@ -226,6 +226,8 @@ The rules have been moved into categories with PMD 6.
* [#4719](https://github.com/pmd/pmd/pull/4719): \[java] UnnecessaryCaseChange: example doc toUpperCase() should compare to a capitalized string
* javascript
* [#4673](https://github.com/pmd/pmd/pull/4673): \[javascript] CPD: Added support for decorator notation
+* plsql
+ * [#4820](https://github.com/pmd/pmd/issues/4820): \[plsql] WITH clause is ignored for SELECT INTO statements
* swift
* [#4697](https://github.com/pmd/pmd/issues/4697): \[swift] Support Swift 5.9 features (mainly macros expansion expressions)
* xml-bestpractices
@@ -359,6 +361,7 @@ The following previously deprecated classes have been removed:
* [#4750](https://github.com/pmd/pmd/pull/4750): \[core] Fix flaky SummaryHTMLRenderer - [219sansim](https://github.com/219sansim) (@219sansim)
* [#4754](https://github.com/pmd/pmd/pull/4754): \[java] EmptyControlStatementRule: Add allowCommentedBlocks property - [Andreas Bergander](https://github.com/bergander) (@bergander)
* [#4759](https://github.com/pmd/pmd/pull/4759): \[java] fix: remove delimiter attribute from ruleset category/java/errorprone.xml - [Marcin Dฤ browski](https://github.com/marcindabrowski) (@marcindabrowski)
+* [#4825](https://github.com/pmd/pmd/pull/4825): \[plsql] Fix ignored WITH clause for SELECT INTO statements - [Laurent Bovet](https://github.com/lbovet) (@lbovet)
### ๐ Major Features and Enhancements
@@ -1009,6 +1012,8 @@ Language specific fixes:
* kotlin
* [#419](https://github.com/pmd/pmd/issues/419): \[kotlin] Add support for Kotlin
* [#4389](https://github.com/pmd/pmd/pull/4389): \[kotlin] Update grammar to version 1.8
+* plsql
+ * [#4820](https://github.com/pmd/pmd/issues/4820): \[plsql] WITH clause is ignored for SELECT INTO statements
* swift
* [#1877](https://github.com/pmd/pmd/pull/1877): \[swift] Feature/swift rules
* [#1882](https://github.com/pmd/pmd/pull/1882): \[swift] UnavailableFunction Swift rule
@@ -1069,6 +1074,7 @@ Language specific fixes:
* [#4750](https://github.com/pmd/pmd/pull/4750): \[core] Fix flaky SummaryHTMLRenderer - [219sansim](https://github.com/219sansim) (@219sansim)
* [#4754](https://github.com/pmd/pmd/pull/4754): \[java] EmptyControlStatementRule: Add allowCommentedBlocks property - [Andreas Bergander](https://github.com/bergander) (@bergander)
* [#4759](https://github.com/pmd/pmd/pull/4759): \[java] fix: remove delimiter attribute from ruleset category/java/errorprone.xml - [Marcin Dฤ browski](https://github.com/marcindabrowski) (@marcindabrowski)
+* [#4825](https://github.com/pmd/pmd/pull/4825): \[plsql] Fix ignored WITH clause for SELECT INTO statements - [Laurent Bovet](https://github.com/lbovet) (@lbovet)
### ๐ Stats
* 5007 commits
diff --git a/pmd-plsql/etc/grammar/PLSQL.jjt b/pmd-plsql/etc/grammar/PLSQL.jjt
index 51be215856b..f99b2d0e1b7 100644
--- a/pmd-plsql/etc/grammar/PLSQL.jjt
+++ b/pmd-plsql/etc/grammar/PLSQL.jjt
@@ -1273,12 +1273,17 @@ void AbstractSelectStatement(AbstractSelectStatement node) #void :
}
/**
+ * Note: The SELECT INTO statement can be preceded by a WithClause, even though this is not in the
+ * official reference documentation.
+ *
* @see https://docs.oracle.com/en/database/oracle/oracle-database/18/lnpls/SELECT-INTO-statement.html
- * @see https://docs.oracle.com/en/database/oracle/oracle-database/18/lnpls/img_text/select_into_statement.html
+ * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/lnpls/SELECT-INTO-statement.html
+ * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/SELECT.html
*/
ASTSelectIntoStatement SelectIntoStatement() :
{}
{
+ [ WithClause() ] // Although undocumented, WITH works with SELECT INTO !
AbstractSelectStatement(jjtThis)
SelectList()
( IntoClause() | BulkCollectIntoClause() )
@@ -2330,11 +2335,11 @@ ASTUnlabelledStatement UnlabelledStatement() :
{}
{
(
- // small optimization: SelectIntoStatement and SelectStatement both begin with SELECT
+ // small optimization: SelectIntoStatement and SelectStatement both begin with WITH or SELECT
// but to distinguish the two, a complete lookahead of SelectIntoStatement needs to be parsed.
// Using a lookahead of a single token first avoids this the syntatic lookahead for all other choices
// not related to SELECT statements.
- LOOKAHEAD(