JDBC: PL/SQL object (procedure) is invalid.
String sql = "create procedure foo(name varchar2) as " +
"begin " +
...
"end";
Statement stmt = connection.createStatement();
stmt.execute(sql);
stmt.close();
String sql1 = "begin foo('world'); end;";
CallableStatement s = connection.prepareCall(sql1);
s.execute();
s.close();
ERROR when executing the second SQL:
java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00905: object MY_DB.FOO is invalid
ORA-06550: line 1, column 7:
MY_DB is current connection user.
After the 1st statement, the procedure is not found by desc Foo
from sqlplus.
NO error if running these two statements in sqlplus.
/
character.;
character.In SQL/Plus (and SQL Developer) the terminating characters are used to signify ends of executable pieces of code (and depending on the user interface's settings a blank line can do this too) and the start of the next.
In JDBC, when you invoke a piece of code you do not need the terminating character as each call only contains a single statement (for SQL) or (outer) block (for PL/SQL) and the terminator would be redundant. So for a PL/SQL statement being called via JDBC, you do not need the /
to terminate the code but you do require the ;
to terminate the statements, declaraions & block(s) that the code is comprised of (including the outer-most BEGIN
/END
block).
So your code should be:
String sql = "create procedure foo(name varchar2) as " +
"begin " +
...
"end;";