Oracle date seems equals

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 03:43:57

问题


there is a table INCASSO in my database:

CREATE TABLE "GEC_AP"."INCASSO" 
("ID_INCASSO" VARCHAR2(50 BYTE) NOT NULL ENABLE,
 "ID_FATTURA" VARCHAR2(50 BYTE) NOT NULL ENABLE, 
 "ID_PIANO_RATE" VARCHAR2(22 BYTE) DEFAULT -1 NOT NULL ENABLE,
 "DATA_ESECUZIONE" DATE DEFAULT SYSDATE NOT NULL ENABLE,
 ...)

The primary key includes four fields:

CONSTRAINT "PK_INCASSO" PRIMARY KEY ("ID_INCASSO", "ID_FATTURA", "ID_PIANO_RATE", "DATA_ESECUZIONE")

It seems there is a duplicated record when I run the following query:

select id_incasso, id_fattura, id_piano_rate, data_esecuzione
from incasso
where id_incasso = 'TO_20110521258225'

But with another query, 0 records are extracted:

select id_incasso, id_fattura, id_piano_rate, data_esecuzione, count(*)
from incasso where id_incasso = 'TO_20110521258225'
group by id_incasso, id_fattura, id_piano_rate, data_esecuzione
having count(*) > 1

The database is on Oracle 11.2.0.1.0 and I'm using SQL Developer 4.1.1.19.

In SQL Developer, the date format is:

I would to know if the records are different or there is a format date problem in the editor. If the records are different based on the date, in which part of the date they are different? If it's a format date problem in the editor, how can I fix it?


回答1:


Change the date format to DD-MON-YYYY HH24:MI:SS and you are likely to see the difference in that the dates have different centuries.

Using RR to format the year can hide that one date is 1911 and the other is 2011

Try:

SELECT TO_CHAR( DATE '2011-01-01', 'RR-MM-DD' ),
       TO_CHAR( DATE '1911-01-01', 'RR-MM-DD' )
FROM   DUAL

Both will output the same although they are different dates and will not be grouped together.

If the dates are still the same then look for additional spaces or other hidden characters in the strings; you can use LENGTH() to check the size of the strings or DUMP() to get the byte values of the contents:

select id_incasso,
       id_fattura,
       LENGTH( id_fattura ) AS f_length,
       id_piano_rate,
       LENGTH( id_piano_rate ) AS pr_length,
       TO_CHAR( data_esecuzione, 'YYYY-MM-DD HH24:MI:SS' ) AS data_esecuzione
from   incasso
where  id_incasso = 'TO_20110521258225'



回答2:


I've changed the date format used in SQL Developer to DD-MON-YYYY HH24:MI:SS and the following query:

select id_incasso, id_fattura, id_piano_rate, data_esecuzione from incasso where id_incasso = 'TO_20110521258225'

show that the difference is in the year:

Thanks everyone.



来源:https://stackoverflow.com/questions/41568532/oracle-date-seems-equals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!