简体   繁体   English

在Oracle SQL中将ID号转换为日期格式

[英]Convert ID number into date format in oracle sql

I have ID's stored into the ID column in table TEMP_SDR_RECEIVED which has value for example: 201505264865645884 . 我将ID存储到表TEMP_SDR_RECEIVED的ID列中,该列的值例如: 201505264865645884 The year,month and date is stored in this ID format in the first 8 numbers. 年,月和日以该ID格式存储在前8个数字中。 I want to extract the year,month,date from this ID and want to set the minute,hour,seconds to 00:00:00 and others values to null in the column ID_DATE which is date data type. 我想从此ID中提取年,月,日,并要将分钟,小时,秒设置为00:00:00并将其他值设置为ID_DATEID_DATE其为日期数据类型)中的null。 So the conversion of ID into date format should look like this : 26.05.15 00:00:00 I am trying following query but getting an error as the hour must be between 1 to 23. Here is my query: 因此,将ID转换为日期格式应如下所示: 26.05.15 00:00:00我正在尝试执行以下查询,但由于小时数必须在1到23之间,因此出现了错误。这是我的查询:

Insert into TEMP_SDR_RECEIVED(ID_DATE)
    Select to_date(substr(ID, 1, 14), 'YYYYMMDDHH24MISS') FROM TEMP_SDR_RECEIVED

You only need the 8 first characters then : 您只需要前8个字符:

Insert into TEMP_SDR_RECEIVED(ID_DATE)
Select to_date(substr(ID, 1, 8), 'YYYYMMDD') FROM TEMP_SDR_RECEIVED

See SQLFiddle . 参见SQLFiddle

By default, the hours / min / seconds will be set to 0 默认情况下,小时/分钟/秒将设置为0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM