0
我有一個名爲'ADDRESSES'的表。Oracle sql order by not expected as working as expected?
我的查詢:
select MODIFIED_DATE, CITY from ADDRESSES order by MODIFIED_DATE desc, CITY asc;
通過運行上面的查詢,我得到:
MODIFIED_DATE CITY
============= ==============
13-JAN-16 CHICAGO
13-JAN-16 CHICAGO
13-JAN-16 CHICAGO
13-JAN-16 KANSAS CITY
13-JAN-16 KANSAS CITY
13-JAN-16 KANSAS CITY
13-JAN-16 KANSAS CITY
13-JAN-16 KANSAS CITY
13-JAN-16 CHICAGO
13-JAN-16 CHICAGO
13-JAN-16 DENVER
13-JAN-16 DENVER
但我相信:
MODIFIED_DATE CITY
============= ==============
13-JAN-16 CHICAGO
13-JAN-16 CHICAGO
13-JAN-16 CHICAGO
13-JAN-16 CHICAGO
13-JAN-16 CHICAGO
13-JAN-16 DENVER
13-JAN-16 DENVER
13-JAN-16 KANSAS CITY
13-JAN-16 KANSAS CITY
13-JAN-16 KANSAS CITY
13-JAN-16 KANSAS CITY
13-JAN-16 KANSAS CITY
MODIFIED_DATE的數據類型是日期和數據CITY的類型是VARCHAR2。
這究竟是爲什麼?
我懷疑是有時間組件添加到您'DATE'值,即使不是被顯示的話。 –
首先運行:'alter session set nls_date_format ='dd-mon-yyyy hh24:mi:ss';'然後重新運行您的查詢;) – Ditto