Search code examples
oraclesql-maven-plugin

PL/SQL script in sql-maven-plugin throws invalid SQL statement


I am trying to update my materialized view using sql-maven-plugin but its says

Caused by: java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement
ORA-06512: at line 2

Query :

begin
    EXECUTE IMMEDIATE 'DBMS_MVIEW.REFRESH(''M_CUSTOMER'')';
end;

Even after spending hours and hours on this, i am not able to figure out the issue. Thanks in advance.

The queries I want to execute are not simple DDL queries but DBMS_MVIEW package or other packages. Other answers have the solution for DDL but not for package.

Project structure

enter image description here


Solution

  • You have not enough or too many levels of indirection here :-)

    You either want:

    begin
        DBMS_MVIEW.REFRESH('M_CUSTOMER');
    end;
    

    or

    begin
        EXECUTE IMMEDIATE 'begin DBMS_MVIEW.REFRESH(''M_CUSTOMER''); end;';
    end;
    

    with the former being the most likely.