Oracle sql提取表中“HRS”之前的数字

mbskvtky  于 2023-03-29  发布在  Oracle
关注(0)|答案(1)|浏览(141)

我有一个表,其中列详细信息如下-
我想提取数字与小时提到。所以输出应该是-
更新输出
为此使用哪个函数?
我正在使用下面的查询,但它返回空

regexp_substr (regexp_substr(SCHEDULE_NAME, '([[:alpha:]]+)[[:space:]]hrs', 1), '^[^ ]+', 1)
dz6r00yl

dz6r00yl1#

您可以使用REGEXP_SUBSTR

SELECT id,
       TO_NUMBER(REGEXP_SUBSTR(schedule_name, '(\d+\.?\d*)\s+hrs', 1, 1, 'i', 1)) AS hrs
FROM   table_name

其中,对于示例数据:

CREATE TABLE table_name (id, schedule_name) AS
SELECT 1, 'IPFGH Cycle 2 Work Schedule  7.78 hrs  - 30 min lunch - 07:15:00 AM to 03:32:00 PM Work Time' FROM DUAL UNION ALL
SELECT 2, 'IPFGH Cycle 1 Work Schedule  7.78 hrs  - 60 min lunch - 08:00:00 AM to 04:47:00 PM Work Time' FROM DUAL UNION ALL
SELECT 3, 'IPFGH Cycle 1 Work Schedule  7.78 hrs  - 30 min lunch - 07:47:00 AM to 04:04:00 PM Work Time' FROM DUAL UNION ALL
SELECT 4, 'IPFGH Cycle 2 Work Schedule  7.78 hrs  - 60 min lunch - 06:45:00 AM to 03:32:00 PM Work Time' FROM DUAL UNION ALL
SELECT 5, 'IPFGH Part Time WTF Cycle Work Schedule No EDO 7 hrs  - 60 min lunch - 08:00:00 AM to 04:00:00 PM Work Time' FROM DUAL;

输出:
| ID|HRS|
| --------------|--------------|
| 1|七点七八分|
| 二|七点七八分|
| 三|七点七八分|
| 四|七点七八分|
| 五|七|
fiddle

相关问题