Skip to content

Oracle query parse error when using "WITH FUNCTION" #7663

@graymcd

Description

@graymcd

sqlglot 30.8.0
Oracle dialect
"WITH FUNCTION" in a query causes parsing error Expecting (. Line 1, Col: 20.

Query:

WITH FUNCTION f_demo(v_in_ch IN CHAR) RETURN CHAR
IS
BEGIN
    RETURN v_in_ch;
END;

SELECT
    'C' || f_demo('d')
FROM dual;

Repo code:

import sqlglot

query = """WITH FUNCTION f_demo(v_in_ch IN CHAR) RETURN CHAR
IS
BEGIN
    RETURN v_in_ch;
END;

SELECT
    'C' || f_demo('d')
FROM dual;"""

try:
    ast = sqlglot.parse_one(query,read="oracle")
except sqlglot.ParseError as p:
    print('Parsing error!')
    print(p)
except Exception as e:
    print(type(e))
    print(e)

Results:

py .\withfunctionerror.py
Parsing error!
Expecting (. Line 1, Col: 20.
  WITH FUNCTION f_demo(v_in_ch IN CHAR) RETURN CHAR
IS
BEGIN
    RETURN v_in_ch;
END;

SELECT
    'C' || f_demo('d')
FROM 

Query runs fine producing output 'Cd' under Oracle 19c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions