Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Parse Oracle open cursor statement SQL error when parameters contain method expr #6183

Open
yisiliang opened this issue Oct 18, 2024 · 0 comments

Comments

@yisiliang
Copy link
Contributor

Database Type

Oracle

Database Version

Oracle 12c

Druid Version

1.2.23

JDK Version

OpenJDK 8

Error SQL

create or replace procedure proc_test1 (myArray in self_define_array) is 

CURSOR c_test (p1 varchar2) is
select
     *
from
     test1
where
     id = p1;

BEGIN OPEN c_test (myArray (1));

END proc_test1;

Testcase Code

    @Test
    public void test_open_cursor_with_method() {
        String sql = "create or replace procedure proc_test1 (myArray in self_define_array) is \n" +
                "\n" +
                "CURSOR c_test (p1 varchar2) is\n" +
                "select\n" +
                "     *\n" +
                "from\n" +
                "     test1\n" +
                "where\n" +
                "     id = p1;\n" +
                "\n" +
                "BEGIN OPEN c_test (myArray (1));\n" +
                "\n" +
                "END proc_test1;";
        List<SQLStatement> sqlStatements = SQLUtils.parseStatements(sql, DbType.oracle);
        System.out.println(sqlStatements);
    }

Stacktrace Info

com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'est (myArray (1));
END proc_test1;', expect ), actual (, pos 185, line 11, column 28, token (
	at com.alibaba.druid.sql.parser.SQLParser.printError(SQLParser.java:862)
	at com.alibaba.druid.sql.parser.SQLParser.accept(SQLParser.java:870)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseOpen(SQLStatementParser.java:5240)
	at com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser.parseStatementList(OracleStatementParser.java:661)
	at com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser.parseBlock(OracleStatementParser.java:1948)
	at com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser.parseCreateProcedure(OracleStatementParser.java:2870)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseCreate(SQLStatementParser.java:3663)
	at com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser.parseStatementList(OracleStatementParser.java:110)
	at com.alibaba.druid.sql.SQLUtils.parseStatements(SQLUtils.java:600)
	at com.alibaba.druid.sql.SQLUtils.parseStatements(SQLUtils.java:621)
	at ParseTest.test_open_cursor_with_method(ParseTest.java:24)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

Error Info

No response

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

No branches or pull requests

1 participant