FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
||||
|
||||
Mysql, años bisiestos y divisiones por cero
Al parecer, mySQL tiene problemas con los años bisiestos. Si usas controles Data-Aware o sentencias parametrizadas desde delphi, ¡suerte que delphi te ayuda!, pero si estas construyendo sentencias SQL de puro texto (probablemente para importar datos desde otras fuentes, ¡mucho cuidado!
Este es el resultado de un experimento realizado sobre oracle, PostgreSQL, DB2, firebird y mysql: Años bisiestos Oracle: Código:
SQL> CREATE TABLE leaptest (thedate date); Table created. SQL> INSERT INTO leaptest VALUES ('28-feb-2008'); 1 row created. SQL> INSERT INTO leaptest VALUES ('29-feb-2008'); 1 row created. SQL> INSERT INTO leaptest VALUES ('30-feb-2008'); INSERT INTO leaptest VALUES ('30-feb-2008') * ERROR at line 1: ORA-01830: date format picture ends before converting entire input string SQL> INSERT INTO leaptest VALUES ('29-feb-2007'); INSERT INTO leaptest VALUES ('29-feb-2007') * ERROR at line 1: ORA-01830: date format picture ends before converting entire input string SQL> SELECT * from leaptest; THEDATE --------- 28-FEB-08 29-FEB-08 PostgreSQL: Código:
goods=> CREATE TABLE leaptest (thedate date); CREATE TABLE goods=> INSERT INTO leaptest VALUES ('28-feb-2008'); INSERT 0 1 goods=> INSERT INTO leaptest VALUES ('29-feb-2008'); INSERT 0 1 goods=> INSERT INTO leaptest VALUES ('30-feb-2008'); ERROR: date/time field value out of range: "30-feb-2008" goods=> INSERT INTO leaptest VALUES ('29-feb-2007'); ERROR: date/time field value out of range: "29-feb-2007" goods=> SELECT * FROM leaptest; thedate ------------ 2008-02-28 2008-02-29 (2 rows) DB2 Código:
db2 => CREATE TABLE leaptest (thedate date) DB20000I The SQL command completed successfully. db2 => INSERT INTO cmihai.leaptest VALUES ('2008-02-28') DB20000I The SQL command completed successfully. db2 => INSERT INTO cmihai.leaptest VALUES ('2008-02-29') DB20000I The SQL command completed successfully. db2 => INSERT INTO cmihai.leaptest VALUES ('2008-02-30') DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0181N The string representation of a datetime value is out of range. SQLSTATE=22007 db2 => INSERT INTO cmihai.leaptest VALUES ('2007-02-29') DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0181N The string representation of a datetime value is out of range. SQLSTATE=22007 db2 => SELECT * FROM cmihai.leaptest THEDATE ---------- 02/28/2008 02/29/2008 2 record(s) selected. Firebird: Código:
SQL> CREATE TABLE leaptest (thedate date); SQL> INSERT INTO leaptest VALUES ('28-feb-2008'); SQL> INSERT INTO leaptest VALUES ('29-feb-2008'); SQL> INSERT INTO leaptest VALUES ('30-feb-2008'); Statement failed, SQLCODE = -413 conversion error from string "30-feb-2008" SQL> INSERT INTO leaptest VALUES ('29-feb-2007'); Statement failed, SQLCODE = -413 conversion error from string "29-feb-2007" SQL> SELECT * FROM leaptest; THEDATE =========== 2008-02-28 2008-02-29 MySQL: Código:
mysql> CREATE TABLE leaptest (thedate date); Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO leaptest VALUES ('28-feb-2008'); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> INSERT INTO leaptest VALUES ('29-feb-2008'); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> INSERT INTO leaptest VALUES ('30-feb-2008'); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> INSERT INTO leaptest VALUES ('29-feb-2007'); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> SELECT * FROM leaptest; +------------+ | thedate | +------------+ | 0000-00-00 | | 0000-00-00 | | 0000-00-00 | | 0000-00-00 | +------------+ 4 rows in set (0.00 sec) Alguién ha indicado que si se usa fechas en formato ISO trabajaría: Código:
INSERT INTO leaptest VALUES ('2008-02-28'); Resultado de la prueba: NO satisfactorio. División por cero Oracle Código:
SQL> SELECT 0/0 FROM dual; SELECT 0/0 FROM dual * ERROR at line 1: ORA-01476: divisor is equal to zero PostgreSQL Código:
goods=> SELECT 0/0; ERROR: division by zero DB2: Código:
db2 => SELECT 0/0 FROM cmihai.leaptest SQL0801N Division by zero was attempted. SQLSTATE=22012 Firebird: Código:
SQL> SELECT 0/0 FROM rdb$database; ===================== Statement failed, SQLCODE = -802 arithmetic exception, numeric overflow, or string truncation MySQL Código:
mysql> SELECT 0/0; +------+ | 0/0 | +------+ | NULL | +------+ 1 row in set (0.00 sec) Las versiones utilizadas para el experimento son: DB2 9.5, Oracle 10g and 11g, PosgreSQL 8.2, 8.3 Firebird 2 MySQL 5.0.45. enlace
__________________
Juan Antonio Castillo Hernández (jachguate) Guía de Estilo | Etiqueta CODE | Búsca antes de preguntar | blog de jachguate |
|
|
Temas Similares | ||||
Tema | Autor | Foro | Respuestas | Último mensaje |
El Juego de la X y el 0(Cero). | redimido | Varios | 28 | 11-08-2007 00:13:19 |
problemas con divisiones en java | lazar | JAVA | 2 | 10-04-2007 14:02:49 |
Cuando cero - cero es 5.755533321E-13 | IVAND | Firebird e Interbase | 4 | 12-04-2006 16:06:26 |
division por cero | kalimero | Varios | 7 | 21-12-2004 16:24:28 |
Crystal Reports desde cero, cero, cero. | Repelus | Impresión | 1 | 08-03-2004 21:23:14 |
|