varchar2输出转换成11g数据库中的数字

问题描述 投票:0回答:1

我的查询 从 TBL_WOJOBS 中选择 SUBSTR(JOBCOMPL_TIME,1,5) 结果 = 10:45 现在我想要输出为 10.45 在 11G 数据库中

当我写下这个问题来寻找答案时 选择 TO_NUMBER(SUBSTR(JOBCOMPL_TIME,1,5)) 来自 TBL_WOJOBS 我出现这个错误 我在无效月份遇到错误

sql database oracle oracle11gr2
1个回答
0
投票

无效月份?! 从哪里来?


您应该发布表格描述和示例数据。因为,按照您的说法,当您从中提取前 5 个字符时,列的数据类型似乎是 VARCHAR2 (或类似的)。那“看起来”就像时间 (10:45)。如果您想使用点而不是冒号字符,请替换它。 SQL> with tbl_wojobs (jobcompl_time) as 2 (select '10:45 whatever' from dual) 3 select 4 substr(jobcompl_time, 1, 5) as current_result, 5 replace(substr(jobcompl_time, 1, 5), ':', '.') as new_result 6 from tbl_wojobs; CURRENT_RESULT NEW_RESULT -------------------- -------------------- 10:45 10.45 SQL>

© www.soinside.com 2019 - 2024. All rights reserved.