将日期时间戳转换为Presto
有什么方法可以从2022-06-15 10:21:05.698000000转换为2022-06-15 10:21:05格式?
我在Hive中有数据(数据类型为字符串),其中包含此类数据2022-06-15 10:21:05.698000000。我需要将这些数据插入Oracle,在Oracle数据类型中是日期。在选择Hive的数据时,我正在使用以下查询。
select hive_date,cast(coalesce(substr(A.hive_date, 1,19),substr(A.hive_date2,1,19)) as timestamp)
as oracle_date from test A limit 10;
它显示以下输出。
hive_date oracle_date
2022-06-15 10:21:05.698000000 | 2022-06-15 10:21:05.000
我想将其转换为 2022-06-15 10:21:05 ,这样我就可以将其插入Oracle中。有人可以建议我吗?
is there any way to convert from 2022-06-15 10:21:05.698000000 to this 2022-06-15 10:21:05 format?
I have data in hive (Datatype is string) which contains data like this 2022-06-15 10:21:05.698000000. I need to insert this data in oracle, in oracle data type is date. I am using below query while selecting the data from hive.
select hive_date,cast(coalesce(substr(A.hive_date, 1,19),substr(A.hive_date2,1,19)) as timestamp)
as oracle_date from test A limit 10;
It's showing below output.
hive_date oracle_date
2022-06-15 10:21:05.698000000 | 2022-06-15 10:21:05.000
I want to convert this till seconds 2022-06-15 10:21:05 so i can insert into it in oracle. Can someone plz suggest me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 date function 和
date_format
:输出:
我也建议在操作之前使用
cocce
,即原始尝试cocece(substr(a.hive_date,1,19,1,19),substr(a.hive_date2,1,19) )
- >substr(cocce(a.hive_date,a.hive_date2),1,19)
也可能只需在数据上使用
trim
,例如:或:
You can use date functions -
date_parse
anddate_format
:Output:
Also I would suggest using
coalesce
before manipulations i.e. in original attemptcoalesce(substr(A.hive_date, 1,19),substr(A.hive_date2,1,19))
->substr(coalesce(A.hive_date, A.hive_date2), 1, 19)
Also possibly you need to just use
trim
on the data, like:Or:
您可能需要的只是:
但是,如果需要是字符串,则截断:
或此方法回合:
It's possible that all you need is:
But, if it needs to be a string, this truncates:
Or this method rounds: