[英]ORACLE SQL Trim ineffective with Regular Expressions
When I simplify the query , ie 当我简化查询时 ,即
SELECT TO_CHAR(MIN(I.INCIDENTID)) AS "Incident ID",
TRIM(TO_CHAR(I.CREATIONDATE,'DD-MON-YYYY')) AS "Creation Date"
FROM INCIDENT I
GROUP BY TRIM(TO_CHAR(I.CREATIONDATE,'DD-MON-YYYY'))
I get 我懂了
But if I incorporate into my actual query for 164,000+ distinct rows, I get 但是,如果我在实际查询中合并了164,000+个不同的行,我将得到
But I expect this (only difference is, Creation Date must have proper Date format, not this complex string) 但我希望这样(唯一的区别是,创建日期必须具有正确的日期格式,而不是此复杂的字符串)
I am reading a date-time from an external Oracle Database, and have trimmed any extra spaces successfully with TRIM(I.CREATIONDATE)
. 我正在从外部Oracle数据库读取日期时间,并且已使用
TRIM(I.CREATIONDATE)
成功地修剪了所有多余的空间。
I have verified this because my SQL query only displays distinct date values 我已经验证了这一点,因为我的SQL查询仅显示了不同的日期值
However, TRIM(I.CREATIONDATE)
turns 2/26/2019 11:05:44 AM
into 26-FEB-19 11.05.43.925000 AM
, but I only want 26-FEB-19
但是,
TRIM(I.CREATIONDATE)
将2/26/2019 11:05:44 AM
变成26-FEB-19 11.05.43.925000 AM
,但我只想要26-FEB-19
When I apply regular expression to only get date, ie REGEXP_SUBSTR(TRIM(I.CREATIONDATE),'[^ ]+')
, it certainly outputs 26-FEB-19
, but somehow extra spaces are added because I get duplicate dates. 当我将正则表达式仅用于获取日期时,即
REGEXP_SUBSTR(TRIM(I.CREATIONDATE),'[^ ]+')
,它当然会输出26-FEB-19
,但是由于我得到重复的日期,所以以某种方式添加了额外的空格。
I have tried applying TRIM
a second time, ie TRIM(REGEXP_SUBSTR(TRIM(I.CREATIONDATE),'[^ ]+'))
, but I still get duplicates 我已经尝试了第二次应用
TRIM
,即TRIM(REGEXP_SUBSTR(TRIM(I.CREATIONDATE),'[^ ]+'))
,但我仍然得到重复
Then I tried running regular expression first, then trim, but this does not work, ie TRIM(REGEXP_SUBSTR(I.CREATIONDATE,'[^ ]+'))
still gives duplicates. 然后我尝试先运行正则表达式,然后修剪,但这不起作用,即
TRIM(REGEXP_SUBSTR(I.CREATIONDATE,'[^ ]+'))
仍然给出重复项。
Please assist 请协助
I think you want trunc()
, not trim()
to remove the time component. 我认为您想要
trunc()
,而不是trim()
来删除时间分量。
So try: 因此,请尝试:
trunc(i.creationdate)
Or if you want the days in a particular string representation: 或者,如果您希望用特定的字符串表示形式的日子:
to_char(i.creationdate, 'YYYY-MM-DD')
尝试to_char:
trim(to_char(column_name,'dd-mon-yy'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.