0
votes

I have this error for my code :

insert into Giocatore(ID_giocatore,username) Values('4','pluto')
Report error -
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "MONOPOLY3.INSERISCI_LOG", line 6
ORA-06512: at "MONOPOLY3.T2", line 2
ORA-04088: error during execution of trigger 'MONOPOLY3.T2'

we want to save the value inserted on tab Giocatore( ID_giocatore) into the variable "a" for see that value in the tab log_giocatore in the column id_giocatore of log_giocatore. This is procedure :

create or replace PROCEDURE  inserisci_log
AS
a integer ;
BEGIN
SELECT ID_giocatore 
INTO a
FROM (select ID_giocatore from Giocatore order by ID_GIOCATORE desc)
where rownum <2;
INSERT INTO Log_giocatore ( ID_mossa , ID_partita , ID_giocatore , ID_patrimonio ,ID_proprietà , ID_turno)
VALUES ('1' , '1' , a , '1' ,'1','1');
END inserisci_log;

And this is the trigger that call the procedure:

create or replace TRIGGER  t2
AFTER INSERT OR UPDATE ON Giocatore
begin
inserisci_log;
end;
1
please remove sql server from related tags, since it seems you are in oracle - apomene
ORA-01422: select ID_giocatore from Giocatore order by ID_GIOCATORE desc returns more then one row - Indrakumara
I know but I cant resolve it Can you help me? In the tab giocatore we have this columns( ID_giocatore, Username) that have more instance . Username is foregn key of the table utente(username,password). @Indrakumara - Alfredo Ferrigno
with the where rownum <2 it won't be a more then one row error. just check with data type and the length of Log_giocatore table. - Indrakumara

1 Answers

1
votes

I suggest you might want to rewrite your procedure to accept the ID_GIOCATORE value as a parameter, as in:

create or replace PROCEDURE inserisci_log(pin_ID_GIOCATORE IN INTEGER)
  AS
  BEGIN
    INSERT INTO Log_giocatore
      ( ID_mossa , ID_partita , ID_giocatore , ID_patrimonio ,ID_proprietà , ID_turno)
    VALUES
      ('1' , '1' , pin_ID_GIOCATORE , '1' ,'1','1');
  END inserisci_log;

Then you can change your trigger to pass the ID_GIOCATORE value from the new row:

create or replace TRIGGER  t2
  AFTER INSERT OR UPDATE ON Giocatore
  FOR EACH ROW
begin
  inserisci_log(:NEW.ID_GIOCATORE);
end t2;

Best of luck.