FUNCION NO DEVUELVE EL VALOR
Publicado por fause (1 intervención) el 31/07/2018 18:37:45
He construido una función para obtener un valor y no me está devolviendo información. He probado el código ejecutándolo como un PL/SQL y mostrando el resultado con DBMS_OUTPUT.PUT_LINE y si me muestra el valor correcto. Qué tengo mal al armar la función? (P.D. tuve que usar IF porque el CASE no me estaba operando ).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
CREATE OR REPLACE FUNCTION OPEN.EMD_GETVERTIMSUBSM3AL
(EMD_FACTURA IN FACTURA.FACTCODI%TYPE)
RETURN NUMBER
IS
nuValor number;
nuUnid number;
nuAno number;
nuMes number;
nuInd number;
BEGIN
nuInd:=0;
select SUM(CARGUNID) INTO nuUnid
from cargos
where 1=1
and cargcuco = (select cucocodi from cuencobr where cucofact=EMD_FACTURA)
and cargconc =4;
select pefaano, pefames INTO nuAno,nuMes
from perifact
where pefacodi = (select factpefa from factura where factcodi=EMD_FACTURA);
IF (nuAno < 2016) THEN nuInd:=1; END IF;
IF (nuAno = 2016 and nuMes < 6) THEN nuInd:=2; END IF;
IF (nuAno = 2016 and nuMes >=6) THEN nuInd:=3; END IF;
IF (nuAno = 2017 and nuMes <2) THEN nuInd:=4; END IF;
IF (nuAno = 2017 and (nuMes >=2 and nuMes <8)) THEN nuInd:=5; END IF;
IF (nuAno = 2017 and nuMes>=8) THEN nuInd:=6; END IF;
IF (nuAno = 2018 and nuMes=1) THEN nuInd:=7; END IF;
IF (nuAno = 2018 and nuMes>1) THEN nuInd:=8; END IF;
IF (nuInd = 1)
then
IF (nuUnid >= 20)
THEN nuValor:=20;
ELSE nuValor:=nuUnid;
END IF;
END IF;
IF (nuInd = 2)
then
IF (nuUnid >= 20)
THEN nuValor:=20;
ELSE nuValor:=nuUnid;
end if;
end if;
IF (nuInd = 3)
then
IF (nuUnid >= 19)
THEN nuValor:=19;
ELSE nuValor:=nuUnid;
end if;
end if;
IF (nuInd = 4)
then
IF (nuUnid >= 19)
THEN nuValor:=19;
ELSE nuValor:=nuUnid;
end if;
end if;
IF (nuInd = 5)
then
IF (nuUnid >= 18)
THEN nuValor:=18;
ELSE nuValor:=nuUnid;
end if;
end if;
IF (nuInd = 6)
then
IF (nuUnid >= 17)
THEN nuValor:=17;
ELSE nuValor:=nuUnid;
end if;
end if;
IF (nuInd = 7)
then
IF (nuUnid >= 17)
THEN nuValor:=17;
ELSE nuValor:=nuUnid;
end if;
end if;
IF (nuInd = 8)
then
IF (nuUnid >= 16)
THEN nuValor:=16;
ELSE nuValor:=nuUnid;
end if;
end if;
Return nuValor;
END EMD_GETVERTIMSUBSM3AL;
/
Valora esta pregunta


0