Skip to content

[prettier-plugin-sql] PL-SQL code from Oracle Apex causing error #291

@FerreiraM12

Description

@FerreiraM12

I have valid PL-SQL code and I am getting an error when trying to format it.

This is the code I used:

BEGIN
    IF :APEX$ROW_STATUS = 'C' THEN
        -- Call the CreateProfessor procedure to insert the new professor
        CreateProfessor(
            p_first_name       => :FIRST_NAME,
            p_last_name        => :LAST_NAME,
            p_user_name        => :USER_NAME,
            p_email            => :EMAIL,
            p_department_id    => :DEPARTMENT_ID,
            p_salary           => :SALARY,
            p_work_hours       => :WORK_HOURS,
            p_title            => :TITLE
        );
        
    ELSIF :APEX$ROW_STATUS = 'U' THEN
        -- Call the UpdateProfessor procedure to update the professor
        UpdateProfessor(
            p_user_id          => :USER_ID,
            p_first_name       => :FIRST_NAME,
            p_last_name        => :LAST_NAME,
            p_user_name        => :USER_NAME,
            p_email            => :EMAIL,
            p_department_id    => :DEPARTMENT_ID,
            p_salary           => :SALARY,
            p_work_hours       => :WORK_HOURS,
            p_title            => :TITLE
        );

    ELSIF :APEX$ROW_STATUS = 'D' THEN
        -- Call the DeleteProfessor procedure to delete the professor
        DeleteProfessor(p_user_id => :USER_ID);
    END IF;
END;

I am getting the following error:

npx prettier --write teste.sql
teste.sql
[error] teste.sql: Error: Parse error: Unexpected "$ROW_STATU" at line 2 column 13
[error]     at TokenizerEngine.createParseError (file:///Users/marlonferreira/Documentos%20Local/AeC/E-learning/node_modules/sql-formatter/lib/lexer/TokenizerEngine.js:53:12)
[error]     at TokenizerEngine.tokenize (file:///Users/marlonferreira/Documentos%20Local/AeC/E-learning/node_modules/sql-formatter/lib/lexer/TokenizerEngine.js:35:22)
[error]     at Tokenizer.tokenize (file:///Users/marlonferreira/Documentos%20Local/AeC/E-learning/node_modules/sql-formatter/lib/lexer/Tokenizer.js:16:47)
[error]     at LexerAdapter.tokenize (file:///Users/marlonferreira/Documentos%20Local/AeC/E-learning/node_modules/sql-formatter/lib/parser/createParser.js:16:76)
[error]     at LexerAdapter.reset (file:///Users/marlonferreira/Documentos%20Local/AeC/E-learning/node_modules/sql-formatter/lib/parser/LexerAdapter.js:17:24)
[error]     at Parser.feed (/Users/marlonferreira/Documentos Local/AeC/E-learning/node_modules/nearley/lib/nearley.js:281:15)
[error]     at Object.parse (file:///Users/marlonferreira/Documentos%20Local/AeC/E-learning/node_modules/sql-formatter/lib/parser/createParser.js:26:18)
[error]     at Formatter.parse (file:///Users/marlonferreira/Documentos%20Local/AeC/E-learning/node_modules/sql-formatter/lib/formatter/Formatter.js:32:49)
[error]     at Formatter.format (file:///Users/marlonferreira/Documentos%20Local/AeC/E-learning/node_modules/sql-formatter/lib/formatter/Formatter.js:25:22)
[error]     at formatDialect (file:///Users/marlonferreira/Documentos%20Local/AeC/E-learning/node_modules/sql-formatter/lib/sqlFormatter.js:77:57)

If I replace all occurrences of APEX$ROW_STATUS with some other word the formatting works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions