简体   繁体   中英

Function in invalid State : Oracle with Jdbc

I have a query in java string. What i need to do is fire that query by jdbc. Query is:

String strQuery= " CREATE OR REPLACE FUNCTION GET_CLOSE_DATE ( PARAM_DOCUMENT_ID IN NUMBER ) 
     RETURN DATE AS
      V_CLOSE_DATE DATE;
     BEGIN
       SELECT MAX(TOP_LEVEL_ELEMENT.CLOSE_DATE_TIME) INTO V_CLOSE_DATE  
       FROM TOP_LEVEL_ELEMENT  WHERE TOP_LEVEL_ELEMENT.DOCUMENT_ID = PARAM_DOCUMENT_ID; 
       RETURN V_CLOSE_DATE; 
     END GET_CLOSE_DATE;";

I am using JDBC

Statement stmt = con.createStatement();
stmt.executeUpdate(strQuery);

The query gets executed successfully but when I try to use this function it throws an an exception saying the GET_CLOSE_DATE function is in invalid state. I have also tried firing

alter function GET_CLOSE_DATE compile;

immediately after firing the create function query. Both are executed successfully but still the the function remains in invalid state. Please suggest some solutions.

Try this command to see what, if any errors are associated with this function:

SELECT * 
  FROM user_errors 
 WHERE name = 'GET_CLOSE_DATE';

EDIT:

It might be the embedded CR/LF's in your string. Try concatenating your SQL string, as in:

String strQuery= " CREATE OR REPLACE FUNCTION GET_CLOSE_DATE ( PARAM_DOCUMENT_ID IN" +
                 " NUMBER) RETURN DATE AS " +
                 " V_CLOSE_DATE   DATE " +
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM