Función en estado no válido: Oracle con 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.

preguntado el 08 de noviembre de 11 a las 15:11

1 Respuestas

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 " +
...

respondido 08 nov., 11:20

It is giving the error message as :PLS-00103: Encountered the symbol "" when expecting one of the following: begin function package pragma procedure subtype type use <an identifier> <a double-quoted delimited-identifier> form current cursor external language - Akshay

do u have any clue regarding this ? - Akshay

What line number did it report? - DCookie

You suspected it right, I had CR/LF at the end of my sting. I removed them and it compiled successfully. Thanks a lot. - Akshay

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.