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

como agregar NULL como valor default en campo de tipo FLOAT...????

Estas en el tema de como agregar NULL como valor default en campo de tipo FLOAT...???? en el foro de Mysql en Foros del Web. Hola Mundo.... Tengo esta descripición en mi tabla y quiero definir un valor NULL como valor DEFAULT y NO que sea un cero (0) como ...
  #1 (permalink)  
Antiguo 07/06/2010, 12:16
 
Fecha de Ingreso: junio-2008
Mensajes: 101
Antigüedad: 15 años, 10 meses
Puntos: 0
como agregar NULL como valor default en campo de tipo FLOAT...????

Hola Mundo....

Tengo esta descripición en mi tabla y quiero definir un valor NULL como valor DEFAULT y NO que sea un cero (0) como es el valor DEFAULT en un campo de tipo Float, dentro de una columna de tipo FLOAT llamado valor.

Sorry, valga la redundancia pero creo que la duda se da a entender con la redundancia... jejejeje

Cómo puedo hacerlo...????

Código MySQL:
Ver original
  1. mysql> describe valores;
  2. +-----------+-------------+------+-----+---------+-------+
  3. | Field     | Type        | Null | Key | Default | Extra |
  4. +-----------+-------------+------+-----+---------+-------+
  5. | id_org    | varchar(10) | YES  |     | NULL    |       |
  6. | id_sub    | varchar(10) | YES  |     | NULL    |       |
  7. | id_cen    | varchar(12) | YES  |     | NULL    |       |
  8. | id_pla    | varchar(14) | YES  | MUL | NULL    |       |
  9. | id_gpo    | int(11)     | YES  |     | NULL    |       |
  10. | id_ind    | int(11)     | YES  |     | NULL    |       |
  11. | id_subind | int(11)     | YES  |     | NULL    |       |
  12. | ano       | int(11)     | YES  |     | NULL    |       |
  13. | mes       | varchar(5)  | YES  |     | NULL    |       |
  14. | valor     | float       | YES  |     | -0.001  |       |
  15. +-----------+-------------+------+-----+---------+-------+
  16. 10 rows in set (0.02 sec)

Saludos y de antemano mil gracias por la atenta ayuda que recibiré de mis compañeros foreros.... jejejeje

Chao, chao.....
  #2 (permalink)  
Antiguo 07/06/2010, 12:50
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: como agregar NULL como valor default en campo de tipo FLOAT...????

No se comprende bien tu problema. Un campo FLOAT, DECIMAL o DOUBLE no tienen un valor por default determinado. Si en la definición de la tabla le pones que puede valer NULL, el valor por default será NULLL:

Código MySQL:
Ver original
  1. CREATE TABLE  `tablaprueba` (
  2.   `campo_1` decimal(20,2) default NULL,
  3.   `campo_2` float default NULL,
  4.   `campo_3` double default NULL,
  5.   PRIMARY KEY  USING BTREE (`id`)
  6.  
  7. mysql> describe tablaprueba;
  8. +---------+------------------+------+-----+---------+----------------+
  9. | Field   | Type             | Null | Key | Default | Extra          |
  10. +---------+------------------+------+-----+---------+----------------+
  11. | id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
  12. | campo_1 | decimal(20,2)    | YES  |     | NULL    |                |
  13. | campo_2 | float            | YES  |     | NULL    |                |
  14. | campo_3 | double           | YES  |     | NULL    |                |
  15. +---------+------------------+------+-----+---------+----------------+
  16. 4 rows in set (0.00 sec)
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #3 (permalink)  
Antiguo 07/06/2010, 15:35
 
Fecha de Ingreso: junio-2008
Mensajes: 101
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: como agregar NULL como valor default en campo de tipo FLOAT...????


RESPUESTA:



Código MySQL:
Ver original
  1. mysql> alter table valores modify valor float default NULL;
  2. Query OK, 0 rows affected (0.41 sec)
  3. Records: 0  Duplicates: 0  Warnings: 0
  4.  
  5. mysql> describe valores;
  6. +-----------+-------------+------+-----+---------+-------+
  7. | Field     | Type        | Null | Key | Default | Extra |
  8. +-----------+-------------+------+-----+---------+-------+
  9. | id_org    | varchar(10) | YES  |     | NULL    |       |
  10. | id_sub    | varchar(10) | YES  |     | NULL    |       |
  11. | id_cen    | varchar(12) | YES  |     | NULL    |       |
  12. | id_pla    | varchar(14) | YES  | MUL | NULL    |       |
  13. | id_gpo    | int(11)     | YES  |     | NULL    |       |
  14. | id_ind    | int(11)     | YES  |     | NULL    |       |
  15. | id_subind | int(11)     | YES  |     | NULL    |       |
  16. | ano       | int(11)     | YES  |     | NULL    |       |
  17. | mes       | varchar(5)  | YES  |     | NULL    |       |
  18. | valor     | float       | YES  |     | NULL    |       |
  19. +-----------+-------------+------+-----+---------+-------+
  20. 10 rows in set (0.00 sec)
  21.  
  22. mysql>


  #4 (permalink)  
Antiguo 08/06/2010, 12:26
 
Fecha de Ingreso: junio-2008
Mensajes: 101
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: como agregar NULL como valor default en campo de tipo FLOAT...????

De casualidad alguien puede decirme por qué no me está reemplazando el valor default NULL en esta sentencia de PHP....

str_replace(NULL,"Sin valor",$row['valor'])

Código PHP:
Ver original
  1. if (!mysql_connect($db_host, $db_user, $db_pwd))
  2.     die("Can't connect to database");
  3.  
  4. if (!mysql_select_db($database))
  5.     die("Can't select database");
  6.  
  7. // sending query
  8. $result = mysql_query("select {$table}.nomb_gpo,{$table}.nomb_ind,valor from {$table} join indicador on {$table}.nomb_ind=indicador.nomb_ind
  9. where nomb_pla='$_REQUEST[plan_inst]' and nomb_cen='$_REQUEST[cen_trabajo]'  and mes='{$mth}' and ano='{$yr}' order by id_ind asc limit 0,3;"
  10. ,$conexion) or die("Problemas en el select result: ".mysql_error());
  11.  
  12. echo "<table id=\"demo4_table\" cellpadding=\"2\" cellspacing=\"1\" border=\"2\"  width=\"453\" align=left >";
  13.  
  14. // printing table rows
  15. echo "<tr><td  rowspan='1' colspan='3' align='center' bgcolor='58ACFA'><b>Instalaciones y Equipos</b></td></tr>\n";
  16.  
  17. while ($row = mysql_fetch_array($result))
  18. {
  19. echo "<TR>";
  20.         echo "<TD>".$row['nomb_ind']."</TD>";
  21.         echo "<TD width=\"83\" align=center>".str_replace(NULL,"Sin valor",$row['valor'])."</TD>";
  22.     echo "</tr>\n";
  23. }

El pequeño gran detalle es que NO me está reemplazando el Valor NULL por "Sin Valor"....

Para verificar que la parte de MySQL sí está trabajando bien pongo lo siguiente:

Código MySQL:
Ver original
  1. mysql> select valor from clau where mes='Nov' and ano=2009 and nomb_pla='Planta 1';
  2. +-------+
  3. | valor |
  4. +-------+
  5. |  NULL |
  6. |  NULL |
  7. |  NULL |
  8. |  NULL |
  9. |  NULL |
  10. |  NULL |
  11. |  NULL |
  12. |  NULL |
  13. |  NULL |
  14. |  NULL |
  15. |  NULL |
  16. |  NULL |
  17. |  NULL |
  18. +-------+
  19. 13 rows in set (0.01 sec)



  #5 (permalink)  
Antiguo 21/06/2010, 16:02
 
Fecha de Ingreso: junio-2008
Mensajes: 101
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: como agregar NULL como valor default en campo de tipo FLOAT...????


Aquí ya está resuelto el problemita
...... jejejeje

Saludos...

http://www.forosdelweb.com/f18/reemp...5/#post3452734

Etiquetas: default, float, null, tipo, campos
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 10:19.