小编use*_*778的帖子

在特定字符SQL-Standard处拆分字符串

在我的SQL语句中,我必须从字符'_'处的字符串中提取子字符串.字符串可以是例如'A_XXX''AB_XXX''ABC_XXXX',因此提取的子字符串应该像'A''AB''ABC'.

在Oracle中,使用substr()和instr()函数很容易:

select substr('AB_XXX', 1, instr('AB_XXX', '_')-1) as substring
from dual;
Run Code Online (Sandbox Code Playgroud)

结果将是:

SUBSTRING
------------------------
AB
Run Code Online (Sandbox Code Playgroud)

我需要此查询来检查特定子字符串是否在字符串数组中.

整个查询看起来像:

select 'AB_XXX' from dual
where (instr('ABC_AB_A', substr('AB_XXX', 1, instr('AB_XXX', '_')-1))>0);
Run Code Online (Sandbox Code Playgroud)

有没有办法在SQL-Standard中编写它?

在此先感谢您的帮助.

编辑:

如果PostgreSQL提供了另一种功能,它也会有所帮助.其余的可以用例如IN来解决.真正重要的部分是获得子串.

string postgresql string-split sql-standards

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

postgresql ×1

sql-standards ×1

string ×1

string-split ×1