Procedure with error

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
caioamante
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 18
Joined: Fri, 25 Sep 2009 8:34 am
Location: Caçapava - Sp
Caiovisk

Friends I'm doing a procedure that is giving a problem saying that it is not finding the mother key.

Select all

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
SergioLBJr
Rank: Oracle Guru
Rank: Oracle Guru
Posts: 448
Joined: Tue, 16 Jun 2009 3:07 pm
Location: Parobé - RS
Sérgio Luiz Bonemberger Junior
Programador Junior
Parobé RS

[]s

Post the forum error
caioamante
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 18
Joined: Fri, 25 Sep 2009 8:34 am
Location: Caçapava - Sp
Caiovisk

Follows the error

Select all

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
caioamante
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 18
Joined: Fri, 25 Sep 2009 8:34 am
Location: Caçapava - Sp
Caiovisk

and the procedure I am trying to run is

Select all

begin 
sp_inicia_fluxo(21); 
end;
This travel code 21 search km and already quantity 0 of km in variavavel ... Feed the flow table as the initial km 0
User avatar
fsitja
Rank: OraSauro
Rank: OraSauro
Posts: 611
Joined: Mon, 19 Jan 2009 4:29 pm
Location: Gaúcho no Rio de Janeiro - RJ
"The scars exist to remind us that the past was real"
Campanha: Como fazer uma pergunta e obter uma resposta.
http://tkyte.blogspot.com/2005/06/how-t ... tions.html

OCA & OCP Developer — OCE SQL Expert — OCS Data Warehousing Specialist

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 all

 
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' 
User avatar
fsitja
Rank: OraSauro
Rank: OraSauro
Posts: 611
Joined: Mon, 19 Jan 2009 4:29 pm
Location: Gaúcho no Rio de Janeiro - RJ
"The scars exist to remind us that the past was real"
Campanha: Como fazer uma pergunta e obter uma resposta.
http://tkyte.blogspot.com/2005/06/how-t ... tions.html

OCA & OCP Developer — OCE SQL Expert — OCS Data Warehousing Specialist

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.
caioamante
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 18
Joined: Fri, 25 Sep 2009 8:34 am
Location: Caçapava - Sp
Caiovisk

The flow table appeared in the 2 table names .. How strange ..
caioamante
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 18
Joined: Fri, 25 Sep 2009 8:34 am
Location: Caçapava - Sp
Caiovisk

Select all

CREATE TABLE FLUXO (  
  FLU_CODIGO      NUMBER (10)   NOT NULL,  
  FLU_VIA_CODIGO  NUMBER (10),  
  FLU_HR_INICIO   DATE          NOT NULL,  
  FLU_HR_FIM      DATE,  
  FLU_KM_INICIO   NUMBER (10)   NOT NULL,  
  FLU_KM_FIM      NUMBER (10),  
  FLU_STATUS      CHAR (1),  
   CONSTRAINT CK_FLU_STATUS 
          CHECK (flu_status  in ('A','I')),  
  PRIMARY KEY ( FLU_CODIGO ) ) ;  
 
ALTER TABLE FLUXO ADD  
 FOREIGN KEY (FLU_VIA_CODIGO)  
  REFERENCES CAIOAMANTE.FLUXO (FLU_CODIGO) ;

I believe the problem is here ...
caioamante
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 18
Joined: Fri, 25 Sep 2009 8:34 am
Location: Caçapava - Sp
Caiovisk

Friend fic very grateful for the help ... I managed to solve ... really is what you gave me .. how can you see I was referencing the own table.

Thank you very much.
caioamante
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 18
Joined: Fri, 25 Sep 2009 8:34 am
Location: Caçapava - Sp
Caiovisk

[SORTED OUT]
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest