Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/01/2008, 17:52
Avatar de matanga
matanga
 
Fecha de Ingreso: octubre-2007
Ubicación: España
Mensajes: 1.091
Antigüedad: 16 años, 6 meses
Puntos: 85
Re: Eliminar registros no numericos

Hola,

Este problema ha sido motivo de varios post en varios foros, y todos han llegado mas o menos a la misma conclusion, hay que wrapear la funcion TO_NUMBER dentro de una funcion desarrollada por nosotros, el problema es siempre el mismo, la funcion TO_NUMBER no maneja excepciones.

Código:
CREATE OR REPLACE FUNCTION my_to_number( arg IN VARCHAR2 )
  RETURN INTEGER
IS
  var NUMBER;
  not_a_number EXCEPTION;
  PRAGMA EXCEPTION_INIT( not_a_number, -6502 );
BEGIN
  var := to_number( arg );
  RETURN var;
EXCEPTION
  WHEN not_a_number THEN
    RETURN null;
END;
De esta manera podremos hacer consultas como la siguiente en forma segura.

Código:
SELECT *
  FROM testtable
 WHERE code = 'H'
   AND my_to_numeric( value ) > 1000
Fuente: http://www.ddbcinc.com/askDDBC/topic.asp?TOPIC_ID=722

Saludos