3

I have a Java webapp with an Oracle DB, and I try to execute this statement at the end of a data migration script:

EXEC DBMS_STATS.GATHER_TABLE_STATS (ownname => 'MY_SCHEMA', tabname => 'MY_TABLE', estimate_percent => dbms_stats.auto_sample_size);

It works in sql*plus, but not via JDBC:

"Error: ORA-00900: invalid SQL statement"

What am I doing wrong?

1
  • EXEC (EXECUTE) is a SQL*Plus native command (just like SHUTDOWN, HELP, SET, etc.), and not a part of SQL itself.
    – kubanczyk
    Commented Sep 29, 2013 at 21:43

2 Answers 2

5

Instead of EXEC, you should put it between begin ... end, or use the { call } syntax. Here is an example, in the documentation:

http://docs.oracle.com/cd/E11882_01/java.112/e16548/getsta.htm#i1014127

0
0
CallableStatement cs = connection.prepareCall("{call MYPROCEDURE }");
cs.execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.