Search code examples
oracle-databaseplsqloracle11goracle11gr2generic-collections

Oracle - TYPE TABLE - Collection Method EXISTS in IF Statement - ORA-06502: PL/SQL: erro: character to number conversion error


I need to make a collection in a Package, but I don't know where was the mistake...

This is my declaration and initialization:

avversao varchar2(30);
TYPE tListaVersaoHomologada IS TABLE OF NVARCHAR2(30);
vVersaoHomologada tListaVersaoHomologada := tListaVersaoHomologada('0.06', '0.07');

And this is where raise the exception

if NOT(vVersaoHomologada.EXISTS(avversao)) then
        ...
end if;

The variable

avversao

Have one of the values:

  • 0.06
  • 0.07

Reference:

Using PL/SQL Collections and Records

Collection Methods


Solution

  • member of - checking if value exists in collection.
    EXISTS - Is for check if collection has value in index.

    declare 
    avversao varchar2(30) := '0.06';
    TYPE tListaVersaoHomologada IS TABLE OF VARCHAR2(30);
    vVersaoHomologada tListaVersaoHomologada := tListaVersaoHomologada('0.06', '0.07');
    begin
    
     if avversao member of vVersaoHomologada then 
      dbms_output.put_line('!!!!Exist!!!!!');
     end if; 
    
    end;