使用查询拆分字符串

时间:2013-11-22 05:49:50

标签: sql oracle oracle10g

我写了一个查询,它分割一个字符串,并使用SUBSTR

显示我想要的值
    SELECT SUBSTR ('imagelocation/r1.jpg', 15)   AS image_location  FROM dual

我得到输出为r1.jpg但我只希望值为r1。请帮忙

3 个答案:

答案 0 :(得分:1)

select SUBSTR (
         'imagelocation/r1.jpg', 
         INSTR('imagelocation/r1.jpg', '/')+1,
         LENGTH('imagelocation/r1.jpg') - INSTR('imagelocation/r1.jpg', '.') - 1
       ) AS image_location  
FROM dual

<强> SUBSTR Function in Oracle

<强> SQL Fiddle

答案 1 :(得分:1)

如果你想要更通用的东西,可以使用regexp_replace。

SELECT 
regexp_replace('imagelocation/r1.jpg','^[^/]*/([^.]+).*$','\1') AS image_location 
FROM dual;

答案 2 :(得分:0)

试试这个:

SELECT SUBSTR('imagelocation/r1.jpg',15,2) AS image_location FROM dual