IMAGE_PATH(其列名)
sph/images///////30_Fairhall_Court.jpeg
sph/images///8_Furnival_Court.jpeg
sph/images/9_Pennethorne_House.jpeg
rbkc/images/TAVISTOCK_CRESCENT.jpeg
haringey///images/399932thumb.jpg
urbanchoice/images//18190862.jpg
westminster/images//7_Glarus_Court.jpeg
我想从IMAGE_PATH列中获取子串作为
30_Fairhall_Court
8_Furnival_Court
9_Pennethorne_House
TAVISTOCK_CRESCENT
399932thumb
18190862
7_Glarus_Court
意味着我需要在最后一个' /'之间使用子字符串。之前'。' 请给我解决方案如何修复
答案 0 :(得分:4)
尝试这种简单的方法(将SUBSTR
与INSTR
一起使用):
SELECT SUBSTR( image_path, INSTR(image_path, '/', -1)+1) "Image name"
FROM IMAGES;
编辑:如果您不想使用extension
使用.
个文件:
SELECT SUBSTR( image_path, INSTR(image_path, '/', -1)+1,
(INSTR(image_path, '.', -1))-INSTR(image_path, '/', -1)-1) "Image name"
FROM IMAGES;
<强>输出:强>
30_Fairhall_Court
8_Furnival_Court
9_Pennethorne_House
TAVISTOCK_CRESCENT
399932thumb
18190862
7_Glarus_Court
答案 1 :(得分:2)
您可以尝试以下内容:
WITH d1 AS (
SELECT 'sph/images///////30_Fairhall_Court.jpeg' AS image_path FROM dual
UNION ALL
SELECT 'sph/images///8_Furnival_Court.jpeg' AS image_path FROM dual
UNION ALL
SELECT 'sph/images/9_Pennethorne_House.jpeg' AS image_path FROM dual
UNION ALL
SELECT 'rbkc/images/TAVISTOCK_CRESCENT.jpeg' AS image_path FROM dual
UNION ALL
SELECT 'haringey///images/399932thumb.jpg' AS image_path FROM dual
UNION ALL
SELECT 'urbanchoice/images//18190862.jpg' AS image_path FROM dual
UNION ALL
SELECT 'westminster/images//7_Glarus_Court.jpeg' AS image_path FROM dual
)
SELECT TRIM(TRAILING '.' FROM REGEXP_SUBSTR(image_path, '[^/]+\.'))
FROM d1;
以上假设最终.
之前没有/
个字符。更好的解决方案可能是:
WITH d1 AS (
SELECT 'sph/images///////30_Fairhall_Court.jpeg' AS image_path FROM dual
UNION ALL
SELECT 'sph/images///8_Furnival_Court.jpeg' AS image_path FROM dual
UNION ALL
SELECT 'sph/images/9_Pennethorne_House.jpeg' AS image_path FROM dual
UNION ALL
SELECT 'rbkc/images/TAVISTOCK_CRESCENT.jpeg' AS image_path FROM dual
UNION ALL
SELECT 'haringey///images/399932thumb.jpg' AS image_path FROM dual
UNION ALL
SELECT 'urbanchoice/images//18190862.jpg' AS image_path FROM dual
UNION ALL
SELECT 'westminster/images//7_Glarus_Court.jpeg' AS image_path FROM dual
)
SELECT REGEXP_SUBSTR(image_path, '[^.]+', INSTR(image_path, '/', -1) + 1)
FROM d1;
也就是说,在最终.
之后找到所有非.
(请注意,在字符类中转义/
}字符不是必需的。)
输出:
30_Fairhall_Court
8_Furnival_Court
9_Pennethorne_House
TAVISTOCK_CRESCENT
399932thumb
18190862
7_Glarus_Court