我的网址列中有一些网址。
www.quick.com/tea
www.quick.com/tea/green
www.quick.com/tea/green/strong
www.quick.com/tea/black/
www.quick.com/tea/black/light/
我需要在每个不以“ /”结尾的网址的末尾添加“ /”,并需要在所述列中获取所有网址。但这不会返回所有数据。有人可以帮助我获取正确的数据吗。
select concat(url,'/') as url
from table1
RIGHT(url, 1) != '/'
答案 0 :(得分:2)
使用case
逻辑:
select (case when url like '%/' then url else url || '/' end) as new_url
答案 1 :(得分:0)
您可以同时使用decode
和nvl2
函数
with t(url) as
(
select 'www.quick.com/tea' from dual union all
select 'www.quick.com/tea/black/light/' from dual union all
select null from dual
)
select nvl2(substr(url,-1),decode(substr(url,-1),'/',url,url||'/'),url) as new_url
from t;
NEW_URL
------------------------------
www.quick.com/tea/
www.quick.com/tea/black/light/
/
nvl2
适用于空URL的存在。否则,使用decode(substr(url,-1),'/',url,url||'/')
就足以派生new_url
列。