In my table, I have some records that are repeated, and I want to take the record that have the newest date. This is because I´m using a cursor, that cursor is returning me the repeated records and that information I have to insert into a table, but I can´t do it because of the repeated records. It maybe be a function error, because I´m using 4 of them, idk. I don´t know what can I do to solve it. Sorry about my english.
This is the procedure that I was trying to use:
CREATE OR REPLACE PROCEDURE PR_INSERT_DATOS IS
CURSOR CUR_DATOS IS
SELECT DISTINCT NUMRUN AS NUMRUN, PNOMBRE||' '||SNOMBRE||' '||APATERNO||' '||AMATERNO AS NOMBRE
FROM ANTECEDENTES_PERSONALES
ORDER BY NUMRUN;
V_PTJE_ANNOS_EXP NUMBER(8);
V_PTJE_HORAS_TRAB NUMBER(8);
V_PTJE_ZONA NUMBER(8);
V_PTJE_RANKING NUMBER(8);
BEGIN
EXECUTE IMMEDIATE('TRUNCATE TABLE DETALLE_PUNTAJE_POSTULACION');
FOR REG_DATOS IN CUR_DATOS LOOP
V_PTJE_ANNOS_EXP:=FN_PTJ_ANNOS_EXP(REG_DATOS.NUMRUN);
V_PTJE_HORAS_TRAB:=FN_PTJE_HORAS(REG_DATOS.NUMRUN);
V_PTJE_ZONA:=FN_PTJE_ZONA(REG_DATOS.NUMRUN);
V_PTJE_RANKING:=FN_PTJE_RANKING(REG_DATOS.NUMRUN);
INSERT INTO DETALLE_PUNTAJE_POSTULACION VALUES (REG_DATOS.NUMRUN, REG_DATOS.NOMBRE, V_PTJE_ANNOS_EXP,
V_PTJE_HORAS_TRAB, V_PTJE_ZONA, V_PTJE_RANKING, 0, 0);
END LOOP;
END;
And that's the error that I have:
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requested