首页 > 解决方案 > 通过 CRATE 在 MYSQL 中拆分字符串

问题描述

我想在 CRATE 中拆分一个字符串。我尝试使用 substr,但它只需要 substr(string,long,long)。我想要一个可以接受分隔符字符串的函数。

例子 :

值=1234-5656

从 XYZ 中选择 SUBSTR(value, '-',1) 作为第一个;

I want to split the value into 1234 and 5656 in a SQL query. But CRATE does not support SUBSTR(value, '-',1). So I am looking for an option to split the value in the CRATE query.

Any help?

标签: mysqlcratecratedb

解决方案


SUBSTRING_INDEX在这里派上用场:

SELECT
    SUBSTRING_INDEX('1234-5656', '-', 1)  AS first,
    SUBSTRING_INDEX('1234-5656', '-', -1) AS second
FROM yourTable;

在此处输入图像描述


推荐阅读