Ceccina said:
This never ends:
Code:
SELECT SIPI.RETRIEVE_SCUOLA(78052,2009,2)
Ceccina, when you say "This never ends...", I believe, in fact, that "This never starts"...If your code truly is only:
Code:
SELECT SIPI.RETRIEVE_SCUOLA(78052,2009,2)
...then you have never told it to begin...there is no semicolon (";") or slash ("/") to tell SQL*Plus to begin execution. (You are probably seeing only a "2" at the beginning of the line following "SELECT SIPI.RETRIEVE_SCUOLA(78052,2009,2)", which means, "Okay, Ceccina, I'm waiting for you to continue/complete the command by telling me "FROM <some table name>...", followed by either ";" or a "/" on a line of its own.
If you had told SQL*Plus to (attempt to) begin execution with either ";" or "/", then you would receive an error message saying:
Code:
SQL> SELECT SIPI.RETRIEVE_SCUOLA(78052,2009,2)
2 /
SELECT SIPI.RETRIEVE_SCUOLA(78052,2009,2)
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
The proof-of-concept that
your code works successfully is my copy of your code. (I've also included displays of the contents of my contrived copies of your tables.):
Code:
SQL> select * from setup;
ID_INGRESSO ID_SERVIZIO DT_INIZIO
----------- ----------- ---------
45 2 06-APR-09
1 row selected.
SQL> select * from V_ALUNNO_CLASSE;
ID_ALUNNO ID_INGRESSO ID_ISTITUTO DT_DIMISS
---------- ----------- ----------- ---------
78052 45 999
1 row selected.
CREATE OR REPLACE FUNCTION RETRIEVE_INGRESSO(inAnno number,inServizio number) RETURN NUMBER
IS
vIngresso number;
BEGIN
SELECT id_ingresso into vIngresso
FROM SETUP i
WHERE I.ID_SERVIZIO=inServizio
AND to_char(I.DT_INIZIO,'yyyy') = inAnno;
RETURN(vIngresso);
EXCEPTION
WHEN NO_DATA_FOUND THEN
BEGIN
DBMS_OUTPUT.PUT_LINE('Impossibile determinare ingresso');
return (0);
END;
END RETRIEVE_INGRESSO;
/
Function created.
CREATE OR REPLACE FUNCTION RETRIEVE_SCUOLA(inAlunno number,inAnno number, inServizio number)
RETURN number
IS
vScuola number;
BEGIN
SELECT vc.id_istituto into vScuola
FROM V_ALUNNO_CLASSE vc
WHERE vc.id_alunno = inAlunno
AND vc.id_ingresso = RETRIEVE_INGRESSO(inAnno,inServizio)
AND vc.DT_DIMISSIONE is null;
RETURN(vScuola);
EXCEPTION
WHEN NO_DATA_FOUND THEN
BEGIN
DBMS_OUTPUT.PUT_LINE('Impossibile determinare la scuola');
return (0);
END;
END RETRIEVE_SCUOLA;
/
Function created.
SQL> SELECT RETRIEVE_SCUOLA(78052,2009,2) from dual;
RETRIEVE_SCUOLA(78052,2009,2)
-----------------------------
999
1 row selected.
Let us know if this resolves your problem.
![[santa] [santa] [santa]](/data/assets/smilies/santa.gif)
Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services:
www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”