Tema: debuger
Ver Mensaje Individual
  #10 (permalink)  
Antiguo 01/10/2009, 09:29
Avatar de huesos52
huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Respuesta: debuger

Código SQL:
Ver original
  1. DELIMITER $$
  2. DROP FUNCTION IF EXISTS SI.SOLO_CARACTERES $$
  3. CREATE FUNCTION SI.SOLO_CARACTERES (VAR CHAR(100)) RETURNS CHAR(100)
  4. DETERMINISTIC
  5. BEGIN
  6. DECLARE POS INT DEFAULT 1;
  7. DECLARE TOTAL CHAR(100) DEFAULT '';
  8. DECLARE VALOR INT DEFAULT 0;
  9. REPEAT
  10. IF INSTR('ABCDEFGHIJKLMNOPQRSTUVWXYZ', SUBSTRING(VAR, POS, 1))>0 THEN
  11. SET TOTAL = CONCAT(TOTAL,SUBSTRING(VAR, POS, 1));
  12. END IF;
  13. SET POS = POS + 1;
  14. UNTIL POS > LENGTH(VAR) END REPEAT;
  15.  
  16. --IF (TOTAL='INSERTAR') THEN
  17. --INSERT INTO SI.rango_facturas
  18. --SELECT *
  19. --FROM rangos A
  20. --WHERE A.Funcion='F';
  21. --END IF;
  22.  
  23. RETURN POS;
  24.  
  25. END $$
  26. DELIMITER ;

Si ingresas palabra 'prueba' y la variable pos se retorna con un 6, ya sabes que está recorriendo bien el repeat.

En conclusión, de esta función que quieres observar o debbuguear?

Código mysql:
Ver original
  1. mysql> use pruebas
  2. Database changed
  3. mysql> DELIMITER $$
  4. mysql> DROP FUNCTION IF EXISTS SOLO_CARACTERES $$
  5. Query OK, 0 rows affected, 1 warning (0.00 sec)
  6.  
  7. mysql> CREATE FUNCTION SOLO_CARACTERES (VAR CHAR(100)) RETURNS CHAR(100)
  8.     -> DETERMINISTIC
  9.     -> BEGIN
  10.     -> DECLARE POS INT DEFAULT 1;
  11.     -> DECLARE TOTAL CHAR(100) DEFAULT '';
  12.     -> DECLARE VALOR INT DEFAULT 0;
  13.     -> REPEAT
  14.     -> IF INSTR('ABCDEFGHIJKLMNOPQRSTUVWXYZ', SUBSTRING(VAR, POS, 1))>0 THEN
  15.     -> SET TOTAL = CONCAT(TOTAL,SUBSTRING(VAR, POS, 1));
  16.     -> END IF;
  17.     -> SET POS = POS + 1;
  18.     -> UNTIL POS > LENGTH(VAR) END REPEAT;
  19.     ->
  20.     -> --IF (TOTAL='INSERTAR') THEN
  21.     -> --INSERT INTO SI.rango_facturas
  22.     -> --SELECT *
  23.     -> --FROM rangos A
  24.     -> --WHERE A.Funcion='F';
  25.     -> --END IF;
  26.     ->
  27.     -> RETURN TOTAL;
  28.     ->
  29.     -> END $$
  30. Query OK, 0 rows affected (0.02 sec)
  31.  
  32. mysql> DELIMITER ;
  33. mysql> select solo_caracteres('dan12');
  34. +--------------------------+
  35. | solo_caracteres('dan12') |
  36. +--------------------------+
  37. | dan                      |
  38. +--------------------------+
  39. 1 row in set (0.00 sec)
  40.  
  41. mysql> select solo_caracteres('insertar1234');
  42. +---------------------------------+
  43. | solo_caracteres('insertar1234') |
  44. +---------------------------------+
  45. | insertar                        |
  46. +---------------------------------+
  47. 1 row in set (0.00 sec)
  48.  
  49. mysql> select solo_caracteres('ins456ertar1234');
  50. +------------------------------------+
  51. | solo_caracteres('ins456ertar1234') |
  52. +------------------------------------+
  53. | insertar                           |
  54. +------------------------------------+
  55. 1 row in set (0.00 sec)
  56.  
  57. mysql>

Yo la veo trabajando bien
__________________
Without data, You are another person with an opinion.
W. Edwads Deming