Stored procedures en Oracle
Publicado por Mario Valarezo (1 intervención) el 20/02/2006 23:22:56
Cómo les va, tengo el siguiente procedure:
create procedure nuevoplan (ciclo IN CHAR, anio IN number, mes IN number, met IN number, ap IN number, fuente IN number, valor IN float, indicador IN varchar2, prog IN number, subprog IN number, proc IN number, rubro IN number) is
begin
declare
cuanto1 number(6);
cod number(6);
cuanto2 number(6);
maxcod number(6);
sumvalor float;
maxcodpres number(6);
begin
select COUNT(*) into cuanto1 from CabValPresupuesto
where CICLO = 'ciclo'
and ANIO = anio
and MES = mes
and METPRESUP_CODIGO = met
and AREAPROTEGIDA_CODIGO = ap
and FUENTE_CODIGO = fuente;
IF cuanto1 != 0 THEN
begin
select codigo into cod
from CabValPresupuesto
where CICLO = 'ciclo'
and ANIO = anio
and MES = mes
and METPRESUP_CODIGO = met
and AREAPROTEGIDA_CODIGO = ap
and FUENTE_CODIGO = fuente;
select COUNT(*) into cuanto2 from ValorPresupuesto
where CABVALPRESUPUESTO_COD = cod
and PROGRAMA_CODIGO = prog
and SUBPROGRAMA_CODIGO = subprog
and PROCESO_CODIGO = proc
and RUBRO_CODIGO = rubro;
IF cuanto2 != 0 THEN
begin
update ValorPresupuesto
set valor = valor,
indicador = 'indicador'
where CABVALPRESUPUESTO_COD = cod
and PROGRAMA_CODIGO = prog
and SUBPROGRAMA_CODIGO = subprog
and PROCESO_CODIGO = proc
and RUBRO_CODIGO = rubro;
end;
else
begin
select nvl(max(codigo + 1), 0) into maxcod
from ValorPresupuesto;
insert into ValorPresupuesto
(codigo, CABVALPRESUPUESTO_COD, PROGRAMA_CODIGO,
SUBPROGRAMA_CODIGO, PROCESO_CODIGO, RUBRO_CODIGO,
indicador, valor)
values (maxcod, cod, prog, subprog, proc, rubro,
'indicador', valor);
end;
end if;
select nvl(sum(valor), 0) into sumvalor
from ValorPresupuesto
where CABVALPRESUPUESTO_COD = cod
and PROGRAMA_CODIGO = prog
and SUBPROGRAMA_CODIGO = subprog
and PROCESO_CODIGO = proc;
update CabValPresupuesto
set valortotal = sumvalor,
FECHACREA = SYSDATE,
estado = 'REA'
where CICLO = 'ciclo'
and ANIO = anio
and MES = mes
and METPRESUP_CODIGO = met
and AREAPROTEGIDA_CODIGO = ap
and FUENTE_CODIGO = fuente;
end;
else
begin
select nvl(max(codigo + 1), 0) into maxcod
from CabValPresupuesto;
select nvl(sum(valor), 0) into sumvalor
from ValorPresupuesto
where CABVALPRESUPUESTO_COD = cod
and PROGRAMA_CODIGO = prog
and SUBPROGRAMA_CODIGO = subprog
and PROCESO_CODIGO = proc;
sumvalor := sumvalor + valor;
insert into CabValPresupuesto
(codigo, AREAPROTEGIDA_CODIGO, CICLO, METPRESUP_CODIGO,
FUENTE_CODIGO, ANIO, MES, ESTADO, FECHACREA, valortotal)
values (maxcod, ap, 'ciclo', met, fuente, anio, mes, 'REA',
SYSDATE, sumvalor);
select nvl(max(codigo + 1), 0) into maxcodpres
from ValorPresupuesto;
insert into ValorPresupuesto
(codigo, CABVALPRESUPUESTO_COD, PROGRAMA_CODIGO,
SUBPROGRAMA_CODIGO, PROCESO_CODIGO, RUBRO_CODIGO,
indicador, valor)
values (maxcodpres, maxcod, prog, subprog, proc, rubro,
'indicador', valor);
end;
end if;
end;
end;
.
/
Este compila muy bien, pero cuando lo ejecuto con el comando: execute nuevoplan ('PLA', 2003, 1, 1, 1, 1, 2000, 'HOLA', 1, 1, 1, 1);, me dan los siguientes errores:
SQL> execute nuevoplan ('PLA', 2003, 1, 1, 1, 1, 2000, 'HOLA', 1, 1, 1, 1);
BEGIN nuevoplan ('PLA', 2003, 1, 1, 1, 1, 2000, 'HOLA', 1, 1, 1, 1); END;
*
ERROR en línea 1:
ORA-01401: valor introducido demasiado largo para columna
ORA-06512: en "GENSANP.NUEVOPLAN", línea 95
ORA-06512: en línea 1
Cómo puedo resolver el problema?, y otra pregunta, cómo lo puedo ejecutar desde una página php?
create procedure nuevoplan (ciclo IN CHAR, anio IN number, mes IN number, met IN number, ap IN number, fuente IN number, valor IN float, indicador IN varchar2, prog IN number, subprog IN number, proc IN number, rubro IN number) is
begin
declare
cuanto1 number(6);
cod number(6);
cuanto2 number(6);
maxcod number(6);
sumvalor float;
maxcodpres number(6);
begin
select COUNT(*) into cuanto1 from CabValPresupuesto
where CICLO = 'ciclo'
and ANIO = anio
and MES = mes
and METPRESUP_CODIGO = met
and AREAPROTEGIDA_CODIGO = ap
and FUENTE_CODIGO = fuente;
IF cuanto1 != 0 THEN
begin
select codigo into cod
from CabValPresupuesto
where CICLO = 'ciclo'
and ANIO = anio
and MES = mes
and METPRESUP_CODIGO = met
and AREAPROTEGIDA_CODIGO = ap
and FUENTE_CODIGO = fuente;
select COUNT(*) into cuanto2 from ValorPresupuesto
where CABVALPRESUPUESTO_COD = cod
and PROGRAMA_CODIGO = prog
and SUBPROGRAMA_CODIGO = subprog
and PROCESO_CODIGO = proc
and RUBRO_CODIGO = rubro;
IF cuanto2 != 0 THEN
begin
update ValorPresupuesto
set valor = valor,
indicador = 'indicador'
where CABVALPRESUPUESTO_COD = cod
and PROGRAMA_CODIGO = prog
and SUBPROGRAMA_CODIGO = subprog
and PROCESO_CODIGO = proc
and RUBRO_CODIGO = rubro;
end;
else
begin
select nvl(max(codigo + 1), 0) into maxcod
from ValorPresupuesto;
insert into ValorPresupuesto
(codigo, CABVALPRESUPUESTO_COD, PROGRAMA_CODIGO,
SUBPROGRAMA_CODIGO, PROCESO_CODIGO, RUBRO_CODIGO,
indicador, valor)
values (maxcod, cod, prog, subprog, proc, rubro,
'indicador', valor);
end;
end if;
select nvl(sum(valor), 0) into sumvalor
from ValorPresupuesto
where CABVALPRESUPUESTO_COD = cod
and PROGRAMA_CODIGO = prog
and SUBPROGRAMA_CODIGO = subprog
and PROCESO_CODIGO = proc;
update CabValPresupuesto
set valortotal = sumvalor,
FECHACREA = SYSDATE,
estado = 'REA'
where CICLO = 'ciclo'
and ANIO = anio
and MES = mes
and METPRESUP_CODIGO = met
and AREAPROTEGIDA_CODIGO = ap
and FUENTE_CODIGO = fuente;
end;
else
begin
select nvl(max(codigo + 1), 0) into maxcod
from CabValPresupuesto;
select nvl(sum(valor), 0) into sumvalor
from ValorPresupuesto
where CABVALPRESUPUESTO_COD = cod
and PROGRAMA_CODIGO = prog
and SUBPROGRAMA_CODIGO = subprog
and PROCESO_CODIGO = proc;
sumvalor := sumvalor + valor;
insert into CabValPresupuesto
(codigo, AREAPROTEGIDA_CODIGO, CICLO, METPRESUP_CODIGO,
FUENTE_CODIGO, ANIO, MES, ESTADO, FECHACREA, valortotal)
values (maxcod, ap, 'ciclo', met, fuente, anio, mes, 'REA',
SYSDATE, sumvalor);
select nvl(max(codigo + 1), 0) into maxcodpres
from ValorPresupuesto;
insert into ValorPresupuesto
(codigo, CABVALPRESUPUESTO_COD, PROGRAMA_CODIGO,
SUBPROGRAMA_CODIGO, PROCESO_CODIGO, RUBRO_CODIGO,
indicador, valor)
values (maxcodpres, maxcod, prog, subprog, proc, rubro,
'indicador', valor);
end;
end if;
end;
end;
.
/
Este compila muy bien, pero cuando lo ejecuto con el comando: execute nuevoplan ('PLA', 2003, 1, 1, 1, 1, 2000, 'HOLA', 1, 1, 1, 1);, me dan los siguientes errores:
SQL> execute nuevoplan ('PLA', 2003, 1, 1, 1, 1, 2000, 'HOLA', 1, 1, 1, 1);
BEGIN nuevoplan ('PLA', 2003, 1, 1, 1, 1, 2000, 'HOLA', 1, 1, 1, 1); END;
*
ERROR en línea 1:
ORA-01401: valor introducido demasiado largo para columna
ORA-06512: en "GENSANP.NUEVOPLAN", línea 95
ORA-06512: en línea 1
Cómo puedo resolver el problema?, y otra pregunta, cómo lo puedo ejecutar desde una página php?
Valora esta pregunta


0