I’m working on a school work and I have an error in my code.
I have created a PLSQL package:
create or replace
PACKAGE GestionProjets AS
TYPE Signaletique IS TABLE OF EMPLOYES%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE TableNomDep IS TABLE OF VARCHAR2(40);
PROCEDURE AjouterProjets(ProjetRecord IN PROJETS%ROWTYPE);
PROCEDURE SupprimerProjet(DelNumPro IN PROJETS.numpro%TYPE);
--PROCEDURE ModifierProjet(newRecord IN PROJETS%ROWTYPE, oldRecord IN PROJETS%ROWTYPE);
FUNCTION ListerEmployes(dep1 IN DEPARTEMENTS.Nomdep%TYPE, dep2 IN DEPARTEMENTS.Nomdep%TYPE) RETURN Signaletique;
END GestionProjets;
That’s the body of the function where I have an error:
FUNCTION ListerEmployes(dep1 IN DEPARTEMENTS.Nomdep%TYPE, dep2 IN DEPARTEMENTS.Nomdep%TYPE) RETURN Signaletique AS
nomDeps TableNomDep;
SigTable Signaletique;
EXWrongDep1 EXCEPTION;
EXWrongDep2 EXCEPTION;
BEGIN
SELECT Nomdep
BULK COLLECT INTO nomDeps
FROM DEPARTEMENTS;
-- test if dep 1 est un parametre valide
IF NOT nomDeps.exists(dep1) THEN
RAISE EXWrongDep1;
END IF;
-- test if dep 2 est un parametre valide
IF NOT nomDeps.exists(dep2) THEN
RAISE EXWrongDep2;
END IF;
EXCEPTION
WHEN EXWrongDep1 THEN
RAISE_APPLICATION_ERROR(-20008, 'MAUVAIS PARAMETRE: ' || dep1 || ' N EXISTE PAS!');
WHEN EXWrongDep2 THEN
RAISE_APPLICATION_ERROR(-20008, 'MAUVAIS PARAMETRE: ' || dep2 || ' N EXISTE PAS!');
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR (-20007, 'ERREUR INCONNU: ' || SQLCODE || ' - ' || SQLERRM);
END ListerEmployes;
When I try to execute the function, i get this error message:
DECLARE
tabel gestionprojets.Signaletique;
BEGIN
tabel := gestionprojets.listeremployes('sdsd','sdsd');
END;
ORA-20007: ERREUR INCONNU: -6502 - ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "EDGE.GESTIONPROJETS", line 108
ORA-06512: at line 4
I don’t understand why I get this error message. The type of the Nomdep column is VARCHAR2(40).
I suspect the problem is that the table type is indexed by BINARY_INTEGER. When the
.EXISTScalls are executed they’re passed eitherdep1ordep2as the index for the table, and thus PL/SQL tries to convert the VARCHAR2(40) parameter to a BINARY_INTEGER. Since these input parameters are both non-numeric character strings (‘sdsd’) the conversion fails.This code might run faster if, instead of reading the entire
DEPARTEMENTStable into memory each timeListerEmployesis called, it was rewritten asShare and enjoy.