Skip to content

fix: Oracle PL/SQL TYPE ... IS RECORD parsing in package body#6629

Open
daguimu wants to merge 1 commit intoalibaba:masterfrom
daguimu:fix/oracle-type-table-of-6589
Open

fix: Oracle PL/SQL TYPE ... IS RECORD parsing in package body#6629
daguimu wants to merge 1 commit intoalibaba:masterfrom
daguimu:fix/oracle-type-table-of-6589

Conversation

@daguimu
Copy link
Copy Markdown

@daguimu daguimu commented Mar 25, 2026

Problem

Oracle PL/SQL parser throws ParserException: TODO when encountering TYPE ... IS RECORD(...) declarations inside package bodies, procedures, or DECLARE blocks.

-- This fails with: TODO : ... token IDENTIFIER record
CREATE OR REPLACE PACKAGE BODY pkg_test IS
    PROCEDURE test_proc AS
        TYPE T_Rec IS RECORD(
            id NUMBER,
            name VARCHAR2(100));
    BEGIN
        NULL;
    END test_proc;
END pkg_test;

Root cause: In OracleStatementParser (line ~2129), the TYPE ... IS handler only supported REF CURSOR, TABLE OF, and VARRAYRECORD was missing, falling through to a throw new ParserException("TODO").

Fix

Add RECORD type parsing to the PL/SQL declaration section, following the same implementation pattern already used at line ~2940 in the same file. The fix parses RECORD(field1 type1, field2 type2, ...) using SQLRecordDataType and parseColumn() which already exist in the codebase.

Tests Added

6 test cases in Issue6589.java:

  • test_type_is_record_in_package_body_procedure — RECORD type inside a procedure in a package body
  • test_type_is_record_in_declare_block — RECORD type in a standalone DECLARE block
  • test_type_is_record_multiple_fields — RECORD with 4 fields of different types
  • test_ref_cursor_still_works — regression: REF CURSOR still works
  • test_table_of_still_works — regression: TABLE OF still works
  • test_package_spec_and_body_with_record — package spec + body with / separator

All 15 existing Oracle issue tests pass.

Note

The original issue's full SQL file also uses BULK COLLECT INTO and other advanced PL/SQL features that remain unsupported. This PR addresses the TYPE IS RECORD parsing specifically.

Fixes #6589

Add RECORD type support to the PL/SQL declaration parser that previously
only handled REF CURSOR, TABLE OF, and VARRAY after TYPE ... IS. The
parser now correctly parses TYPE ... IS RECORD(field1 type1, field2 type2)
declarations inside package bodies, procedures, and DECLARE blocks.

The implementation follows the same pattern as the existing RECORD
parsing at line ~2940 in OracleStatementParser.

Fixes alibaba#6589

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Oracle脚本语句解析报错

1 participant