PROCEDURE sp_inicia_fluxo(p_flu_via_codigo number)
AS
v_km_inicial number(10);
BEGIN
SELECT b.vei_km INTO v_km_inicial
FROM viagem a,
veiculo b
WHERE a.via_vei_codigo = b.vei_codigo
AND a.via_codigo = p_flu_via_codigo;
INSERT INTO fluxo
VALUES (seq_fluxo.nextval,p_flu_via_codigo,sysdate,null,v_km_inicial,null,'A');
END;
I can not play v_km_inicial as INSERT in the table?
Thanks
ORA-02291: restrição de integridade (CAIOAMANTE.SYS_C004108) violada - chave mãe não localizada
ORA-06512: em "CAIOAMANTE.SP_INICIA_FLUXO", line 12
ORA-06512: em line 2
Your flow table references another table through a Foreign Key, and the record you pointed out there on the other table does not exist. Or create the record there in the other or change the data for a record that exists there.
Wheel the select below to see FK that is giving you error (Caioamante.sys_c004108) and which table and columns.
select c2.owner, c2.constraint_name, c2.table_name, cc.*
from all_constraints c
join all_constraints c2 on c.r_owner = c2.owner and c.r_constraint_name = c2.constraint_name
join all_cons_columns cc on cc.owner = c2.owner and cc.constraint_name = c2.constraint_name
where c.constraint_type = 'R' and c.table_name = 'FLUXO'
Just to clarify, the error is in the insert command, and you will have to correct the values ??that are being inserted or include new lines in the table that the flows reference.