[英]DATE FORMAT in Oracle SQL
Below is my sample tables and the expected output and the corresponding query that I have return. 以下是我的示例表以及预期的输出和返回的相应查询。 I am running into DATE FORMAT ISSUES, When I try to get the Earliest date record from PROV table. 当我尝试从PROV表获取最早的日期记录时,我遇到了“日期格式问题”。 Please Let me know if this is not clear 请让我知道是否不清楚
select *
from beau_prov beau
join provi prov
on trim(beau.no) = trim(prov.prov_no)
where prov.ins_dt =
( select min(ins_dt)
from provi prov
where trim(beau.no) = trim(prov.no)
and beau.year = to_char(to_date(ins_dt, 'MM/DD/YYYY HH:MI:SS PM', 'YYYY'), 'YYYY') )
BEAU U
----------------------
NAME | NO | YEAR |
----------------------
CAR | 1234 | 2013 |
AUTO | 4356 | 2013 |
PROV PROV
-----------------------------------------------
NO |NUMBER | NAME | INS_DT |
-----------------------------------------------
1234 | 987 | ZZ | 7/13/2013 11:36:05 PM |
1234 | 456 | ZZ | 12/31/2013 10:34:45 PM |
RESULT 结果
---------------------------------------
NAME | NO | YEAR | NUMBER | NAME |
---------------------------------------
CAR | 1234 | 2013 | 987 | ZZ |
If INS_DT
is an Oracle date
, then you can just insert it into another date
column as it is. 如果INS_DT
是Oracle date
,则可以直接将其插入到另一个date
列中。
The formatting you are seeing is applied by the client application and is not part of the date
value itself. 您看到的格式是由客户端应用程序应用的,而不是date
值本身的一部分。
If it's supplied to your procedure as a string, then you would need to convert it to a date
using to_date(ins_dt,'DD/MM/YYYY HH:MI:SS PM')
. 如果将它作为字符串提供给您的过程,则需要使用to_date(ins_dt,'DD/MM/YYYY HH:MI:SS PM')
将其转换为date
。
If INS_DT
is an Oracle date
and BEAU_PROV.YEAR
is a string containing a 4-digit year, then you can join them using: 如果INS_DT
是Oracle date
而BEAU_PROV.YEAR
是包含4位数字的年份的字符串,则可以使用以下命令加入它们:
and beau.year = to_char(ins_dt,'YYYY')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.