我正在尝试在大查询中编写SQL以用字符串
的中间部分替换下面的字符串 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="button" id="btn_click" value="Click" />
sports.xxxx.com/en-gb/betting/football/vasdas
sports.xxxx.com/en-gb/betting/basketball/blablabla
sports.xxxx.com/en-gb/betting/football/
结果将是
sports.xxxx.com/en-gb/betting/golf
football
basketball
football
我试过用
golf
但是我收到错误SELECT
REGEXP_REPLACE('sports.xxxx.com/en-gb/betting/football', '.*', '(?<=\b\/betting\/)(\w+)')
我有什么想法可以做到吗?
答案 0 :(得分:1)
正则表达式非常强大而且价格昂贵 如果你有选择避免使用它来支持使用更便宜的功能 - 你至少应该尝试
SELECT
SUBSTR(url, 1 + LENGTH('sports.xxxx.com/en-gb/betting/'),
INSTR(REPLACE(url + '/', 'sports.xxxx.com/en-gb/betting/', ''), '/') - 1
) as sport
FROM
(SELECT 'sports.xxxx.com/en-gb/betting/football/vasdas' AS url),
(SELECT 'sports.xxxx.com/en-gb/betting/basketball/blablabla' AS url),
(SELECT 'sports.xxxx.com/en-gb/betting/football/' AS url),
(SELECT 'sports.xxxx.com/en-gb/betting/golf' AS url)
当处理大量行时,上述方法可以避免资源超出或超时等错误(当然取决于您上面的实际查询是其中的一部分)。此外,您应该始终关注Billing Tier - 对于使用regexp的昂贵查询,可能会更高