Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

Procedimiento almacenado

Estas en el tema de Procedimiento almacenado en el foro de Mysql en Foros del Web. estimados tengo un problema se supone que este procedimiento al ser llamado y no parasrle valores deberia deviolver todos los registros pero returna 0 rows, ...
  #1 (permalink)  
Antiguo 02/01/2016, 20:58
Avatar de Killerx_8937  
Fecha de Ingreso: noviembre-2006
Mensajes: 99
Antigüedad: 17 años, 5 meses
Puntos: 0
Busqueda Procedimiento almacenado

estimados tengo un problema se supone que este procedimiento al ser llamado y no parasrle valores deberia deviolver todos los registros pero returna 0 rows, alguna idea
Código MySQL:
Ver original
  1. CREATE DEFINER=`salem`@`localhost` PROCEDURE `usuarios_buscarusuario`(
  2. IN `run` VARCHAR(12),
  3. IN `empresa` VARCHAR(12),
  4. IN `area` INT(6),
  5. IN `nombres` VARCHAR(255),
  6. IN `app` VARCHAR(255),
  7. IN `apm` VARCHAR(255),
  8. IN `departamento` INT(6),
  9. IN `gs` VARCHAR(255),
  10. IN `email` VARCHAR(100),
  11. IN `telefono` VARCHAR(50),
  12. IN `cargo` INT(6),
  13. IN `profesion` VARCHAR(255),
  14. IN `cuentabancaria` VARCHAR(255),
  15. IN `tipocuenta` INT(6),
  16. IN `banco` INT(6),
  17. IN `direccion` VARCHAR(255),
  18. IN `region` INT(6),
  19. IN `provincia` INT(6),
  20. IN `comuna` INT(6),
  21. IN `tipohorario` INT(10),
  22. IN `vinculado` INT(2),
  23. IN `usuariocrea` VARCHAR(255),
  24. IN `usuarioact` VARCHAR(255),
  25. IN `fechacrea` DATETIME,
  26. IN `fechaact` DATETIME
  27. )
  28.     declare condicion varchar(100000);
  29.     SET condicion ="";
  30.     if run <> "" then
  31.         if condicion <> "" then
  32.         set condicion = concat(" and usuarios_run='",convert(run using utf8) collate utf8_spanish_ci ,"' ");
  33.         else
  34.         set condicion = concat(" where usuarios_run='",convert(run using utf8) collate utf8_spanish_ci ,"' ");
  35.         end if;
  36.     end if;
  37.     if empresa <> "" then
  38.         if condicion <> "" then
  39.         set condicion = concat(condicion, " and usuarios_empresa='",convert(empresa using utf8) collate utf8_spanish_ci ,"' ");
  40.         else
  41.         set condicion = concat(" where usuarios_empresa='",convert(empresa using utf8) collate utf8_spanish_ci,"' ");
  42.         end if;
  43.     end if;
  44.     if area <> "" then
  45.         if condicion <> "" then
  46.         set condicion = concat(condicion, " and usuarios_area=",area," ");
  47.         else
  48.         set condicion = concat(" where usuarios_area=",area,"  ");
  49.         end if;
  50.     end if;
  51.     if nombres <> "" then
  52.         if condicion <> "" then
  53.         set condicion = concat(condicion, " and usuarios_nombres like '%", convert(nombres using utf8) collate utf8_spanish_ci ,"%' ");
  54.         else
  55.         set condicion = concat(" where usuarios_nombres like '%", convert(nombres using utf8) collate utf8_spanish_ci ,"%' ");
  56.         end if;
  57.     end if;
  58.  if app <> "" then
  59.         if condicion <> "" then
  60.         set condicion = concat(condicion, " and usuarios_apellidop like '%", convert(app using utf8) collate utf8_spanish_ci ,"%' ");
  61.         else
  62.         set condicion = concat(" where usuarios_apellidop like '%", convert(app using utf8) collate utf8_spanish_ci ,"%' ");
  63.         end if;
  64.     end if;
  65.     if apm <> "" then
  66.         if condicion <> "" then
  67.         set condicion = concat(condicion, " and usuarios_apellidom like '%", convert(apm using utf8) collate utf8_spanish_ci ,"%' ");
  68.         else
  69.         set condicion = concat(" where  usuarios_apellidom like '%", convert(apm using utf8) collate utf8_spanish_ci ,"%' ");
  70.         end if;
  71.     end if;
  72.     if departamento <> "" then
  73.           if condicion <> "" then
  74.              set condicion = concat(condicion, " and usuarios_departamento=",departamento," ");
  75.           else
  76.               set condicion = concat(" where usuarios_departamento=",departamento," ");
  77.         end if;
  78.     end if;
  79.     if gs <> "" then
  80.         if condicion <> "" then
  81.         set condicion = concat(condicion, " and usuarios_gruposeguridad='",convert(gs using utf8) collate utf8_spanish_ci ,"' ");
  82.         else
  83.         set condicion = concat(" where usuarios_gruposeguridad='",convert(gs using utf8) collate utf8_spanish_ci,"' ");
  84.         end if;
  85.     end if;
  86.     if email <> "" then
  87.         if condicion <> "" then
  88.         set condicion = concat(condicion, " and usuarios_email like '%", convert(email using utf8) collate utf8_spanish_ci ,"%' ");
  89.         else
  90.         set condicion = concat(" where  usuarios_email like '%", convert(email using utf8) collate utf8_spanish_ci ,"%' ");
  91.         end if;
  92.     end if;
  93.     if telefono <> "" then
  94.         if condicion <> "" then
  95.         set condicion = concat(condicion, " and usuarios_telefono like '%", convert(telefono using utf8) collate utf8_spanish_ci ,"%' ");
  96.         else
  97.         set condicion = concat(" where  usuarios_telefono like '%", convert(telefono using utf8) collate utf8_spanish_ci ,"%' ");
  98.         end if;
  99.     end if;
  100.     if cargo <> "" then
  101.         if condicion <> "" then
  102.         set condicion = concat(condicion, " and usuarios_cargo=",cargo," ");
  103.         else
  104.         set condicion = concat(" where usuarios_cargo=",cargo,"  ");
  105.         end if;
  106.     end if;
  107.     if profesion <> "" then
  108.         if condicion <> "" then
  109.         set condicion = concat(condicion, " and usuarios_profesion like '%", convert(profesion using utf8) collate utf8_spanish_ci ,"%' ");
  110.         else
  111.         set condicion = concat(" where  usuarios_profesion like '%", convert(profesion using utf8) collate utf8_spanish_ci ,"%' ");
  112.         end if;
  113.     end if;
  114.     if cuentabancaria <> "" then
  115.         if condicion <> "" then
  116.         set condicion = concat(condicion, " and usuarios_cuentabancaria like '%", convert(cuentabancaria using utf8) collate utf8_spanish_ci ,"%' ");
  117.         else
  118.         set condicion = concat(" where  usuarios_cuentabancaria like '%", convert(cuentabancaria using utf8) collate utf8_spanish_ci ,"%' ");
  119.         end if;
  120.     end if;
  121.     if tipocuenta <> "" then
  122.           if condicion <> "" then
  123.              set condicion = concat(condicion, " and usuarios_tipocuentabancaria=",tipocuenta," ");
  124.           else
  125.               set condicion = concat(" where usuarios_tipocuentabancaria=",tipocuenta," ");
  126.         end if;
  127.     end if;
  128.     if banco <> "" then
  129.           if condicion <> "" then
  130.              set condicion = concat(condicion, " and usuarios_banco=",banco," ");
  131.           else
  132.               set condicion = concat(" where usuarios_banco=",banco," ");
  133.         end if;
  134.     end if;
  135.     if direccion <> "" then
  136.         if condicion <> "" then
  137.         set condicion = concat(condicion, " and usuarios_direccion like '%", convert(direccion using utf8) collate utf8_spanish_ci ,"%' ");
  138.         else
  139.         set condicion = concat(" where  usuarios_direccion like '%", convert(direccion using utf8) collate utf8_spanish_ci ,"%' ");
  140.         end if;
  141.     end if;
  142.     if region <> "" then
  143.         if condicion <> "" then
  144.         set condicion = concat(condicion, " and usuarios_region=",region," ");
  145.         else
  146.         set condicion = concat(" where usuarios_region=",region," ");
  147.         end if;
  148.     end if;
  149.     if provincia <> "" then
  150.         if condicion <> "" then
  151.         set condicion = concat(condicion, " and usuarios_provincia=",provincia," ");
  152.         else
  153.         set condicion = concat(" where usuarios_provincia=",provincia," ");
  154.         end if;
  155.     end if;
  156.     if comuna <> "" then
  157.         if condicion <> "" then
  158.         set condicion = concat(condicion, " and usuarios_comuna=",comuna," ");
  159.         else
  160.         set condicion = concat(" where usuarios_comuna=",comuna," ");
  161.         end if;
  162.     end if;
  163.     if tipohorario <> "" then
  164.         if condicion <> "" then
  165.         set condicion = concat(condicion, " and usuarios_tipohorario=",tipohorario," ");
  166.         else
  167.         set condicion = concat(" where  usuarios_tipohorario=",tipohorario," ");
  168.         end if;
  169.     end if;
  170.     if vinculado <> "" then
  171.           if condicion <> "" then
  172.              set condicion = concat(condicion, " and usuarios_vinculado=",vinculado," ");
  173.           else
  174.               set condicion = concat(" where usuarios_vinculado=",vinculado," ");
  175.         end if;
  176.     end if;
  177.     if usuariocrea <> "" then
  178.         if condicion <> "" then
  179.         set condicion = concat(condicion, " and usuarios_usuariocrea='", convert(usuariocrea using utf8) collate utf8_spanish_ci ,"' ");
  180.         else
  181.         set condicion = concat(" where  usuarios_usuariocrea='", convert(usuariocrea using utf8) collate utf8_spanish_ci ,"' ");
  182.         end if;
  183.     end if;
  184.     if usuarioact <> "" then
  185.         if condicion <> "" then
  186.         set condicion = concat(condicion, " and usuarios_usuarioact='", convert(usuarioact using utf8) collate utf8_spanish_ci ,"' ");
  187.         else
  188.         set condicion = concat(" where  usuarios_usuarioact='", convert(usuarioact using utf8) collate utf8_spanish_ci ,"' ");
  189.         end if;
  190.     end if;
  191.  
  192.     if fechacrea <> "" then
  193.         if condicion <> "" then
  194.         set condicion = concat(condicion, " and usuarios_fechacrea='", convert(fechacrea using utf8) collate utf8_spanish_ci ,"' ");
  195.         else
  196.         set condicion = concat(" where  usuarios_fechacrea='", convert(fechacrea using utf8) collate utf8_spanish_ci ,"' ");
  197.         end if;
  198.     end if;
  199.     if fechaact <> "" then
  200.         if condicion <> "" then
  201.         set condicion = concat(condicion, " and usuarios_fechaact='", convert(fechaact using utf8) collate utf8_spanish_ci ,"' ");
  202.         else
  203.         set condicion = concat(" where  usuarios_fechaact='", convert(fechaact using utf8) collate utf8_spanish_ci ,"' ");
  204.         end if;
  205.     end if;
  206. set @consulta = concat("SELECT * FROM `usuarios` ", condicion);
  207. prepare stmt from @consulta;
  208. execute stmt;
  #2 (permalink)  
Antiguo 02/01/2016, 20:59
Avatar de Killerx_8937  
Fecha de Ingreso: noviembre-2006
Mensajes: 99
Antigüedad: 17 años, 5 meses
Puntos: 0
Busqueda Respuesta: Procedimiento almacenado

la tabla tiene la siguiente estructura
Código MySQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `usuarios` (
  2.   `usuarios_run` varchar(12) COLLATE utf8_spanish_ci NOT NULL,
  3.   `usuarios_empresa` varchar(12) COLLATE utf8_spanish_ci NOT NULL,
  4.   `usuarios_area` int(6) NOT NULL,
  5.   `usuarios_nombres` varchar(255) COLLATE utf8_spanish_ci NOT NULL,
  6.   `usuarios_apellidop` varchar(255) COLLATE utf8_spanish_ci NOT NULL,
  7.   `usuarios_apellidom` varchar(255) COLLATE utf8_spanish_ci NOT NULL,
  8.   `usuarios_departamento` int(6) NOT NULL,
  9.   `usuarios_gruposeguridad` varchar(255) COLLATE utf8_spanish_ci NOT NULL,
  10.   `usuarios_email` varchar(100) COLLATE utf8_spanish_ci NOT NULL,
  11.   `usuarios_telefono` varchar(50) COLLATE utf8_spanish_ci NOT NULL,
  12.   `usuarios_cargo` int(6) NOT NULL,
  13.   `usuarios_profesion` varchar(255) COLLATE utf8_spanish_ci NOT NULL,
  14.   `usuarios_cuentabancaria` varchar(255) COLLATE utf8_spanish_ci NOT NULL,
  15.   `usuarios_tipocuentabancaria` int(6) NOT NULL,
  16.   `usuarios_banco` int(6) NOT NULL,
  17.   `usuarios_direccion` varchar(255) COLLATE utf8_spanish_ci NOT NULL,
  18.   `usuarios_region` int(6) NOT NULL,
  19.   `usuarios_provincia` int(6) NOT NULL,
  20.   `usuarios_comuna` int(6) NOT NULL,
  21.   `usuarios_tipohorario` int(6) NOT NULL,
  22.   `usuarios_vinculado` int(2) NOT NULL,
  23.   `usuarios_usuariocrea` varchar(12) COLLATE utf8_spanish_ci NOT NULL,
  24.   `usuarios_usuarioact` varchar(12) COLLATE utf8_spanish_ci NOT NULL,
  25.   `usuarios_fechacrea` datetime NOT NULL,
  26.   `usuarios_fechaact` datetime NOT NULL,
  27.   PRIMARY KEY (`usuarios_run`),
  28.   KEY `usuarios_empresa` (`usuarios_empresa`),
  29.   KEY `usuarios_area` (`usuarios_area`),
  30.   KEY `usuarios_departamento` (`usuarios_departamento`),
  31.   KEY `usuarios_gruposeguridad` (`usuarios_gruposeguridad`),
  32.   KEY `usuarios_cargo` (`usuarios_cargo`),
  33.   KEY `usuarios_tipocuentabancaria` (`usuarios_tipocuentabancaria`),
  34.   KEY `usuarios_banco` (`usuarios_banco`),
  35.   KEY `usuarios_region` (`usuarios_region`),
  36.   KEY `usuarios_provincia` (`usuarios_provincia`),
  37.   KEY `usuarios_comuna` (`usuarios_comuna`),
  38.   KEY `usuarios_tipohorario` (`usuarios_tipohorario`)
  39. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
  #3 (permalink)  
Antiguo 02/01/2016, 22:26
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 5 meses
Puntos: 2658
Respuesta: Procedimiento almacenado

Un SP que tiene definidos parámetros de entrada y/o salida no puede no recibir parámetros. En todo caso puede recibir parámetros vacíos, nulos, o ceros.
Si no le mandas los parámetros disparará un error de ejecución.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)

Etiquetas: almacenado, fecha, procedimiento, registros, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:41.