【发布时间】:2015-01-22 16:25:06
【问题描述】:
我正在研究一些 Oracle SQL,但我是新手。我的表“web_access_log”中有数据,列名是“活动”。我需要获取保存在第 4 个和第 5 个“/”之间的 col 中的数据,或者如果我可以从右边开始让并从第 1 个到第 2 个“/”中获取数据,那将是正确的剩下!下面是一个有效的 SQL 语句,但从左到右。我真的需要从右到左,也许在 REGEX 中更容易?
Table: web_access_log
col name: activity
Sample value: Download file:/webdocs/data/groupXXX/case/03_28_54_9_0000011856.pdf
这就是我现在拥有的
SQL:
select SUBSTR(activity, INSTR(activity, '/', 1, 4) + 1, INSTR(activity, '/', 1, 5) - INSTR(activity, '/', 1, 4) -1) AS FILENAME,
COUNT (SUBSTR(activity, INSTR(activity, '/', 1, 4) + 1, INSTR(activity, '/', 1, 5) - INSTR(activity, '/', 1, 4)-1)) AS DOWNLOADS
FROM sa.web_access_log where application_id = 5339 and to_char(time_stamp, 'mm/yyyy') = '04/2011'
GROUP BY SUBSTR(activity, INSTR(activity, '/', 1, 4) + 1, INSTR(activity, '/', 1, 5) - INSTR(activity, '/', 1, 4) -1)
ORDER BY DOWNLOADS DESC;
【问题讨论】:
-
您的previous question 有正则表达式和普通方法的答案!
-
这在您的代码中失败
to_char(time_stamp, 'mm/yyyy') = '04/2011' -
该代码在这里可以工作,但它是从左到右的。我需要从右到左
标签: sql regex oracle substring