What is the correct way to use nested functions in PLSQL?
-
27-06-2021 - |
Frage
I want to know the correct way to use nested functions in PLSQL. In the following snippet the function 'to_number' works fine, but my two nested functions can't be used in the same manner.
Declare
Tettt Number;
Function lolazo(pigt Number, p_Fecha_Fact Date)
Return Number Is
resultado number;
Begin
Select Vp.Valor
into resultado
from valor_precio vp
Where Vp.Id_Tipo_Cargo = 103
And Vp.Id_Grupo_Precio = pigt
and vp.f_inicio_precio =
(select max(vp2.f_inicio_precio)
From Valor_Precio Vp2
Where Vp2.Id_Grupo_Precio = pigt
And Vp2.F_Inicio_Precio < p_fecha_fact
And Vp2.Id_Tipo_Cargo = 103 );
Return Resultado;
End Lolazo;
Function Multi(Uno Number, Dos Number) Return Number Is
Begin
return uno*dos;
End Multi;
Begin
Select to_number('123')
Into Tettt
From Dual;
-- Doesn't work!
-- Select lolazo(1544, to_date('01/01/2011','dd/mm/yyyy'))
-- Into Tettt
-- From Dual;
-- Doesn't work!
-- select Multi(2,3) into Tettt from dual;
Dbms_Output.Put_Line(lolazo(1544, to_date('01/01/2011','dd/mm/yyyy')));
Dbms_Output.Put_Line(Multi(2,3));
dbms_output.put_line(Tettt);
end;
Lösung
Your functions can't be used in SQL, so DO NOT: select into some_variable from dual
.
Try using an assignment:
Tettt := Multi(2,3);
Also, post your errors from your script (instead of saying doesn't work). Much easier for us to see the actual issue.
If you really wanted to use these functions from SQL, you'd have to expose them to the SQL engine (outside of the PL/SQL world in which your anonymous block resides). This would typically involve creating separate stored procedures or defining them in some package specification.
Hope that helps.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow