-2

我想在 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?

4

3 回答 3

0

SUBSTRING_INDEX在这里派上用场:

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

在此处输入图像描述

于 2018-11-15T05:57:22.060 回答
0

请尝试使用此查询:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(name, '_', 1), '_', -1) as beforesplit, SUBSTRING_INDEX(SUBSTRING_INDEX(name, '_', 2), '_', -1) as aftersplit FROM testenter
于 2018-11-15T06:11:26.233 回答
0

对于 CrateDB,您可能想在 Create 的文档站点上使用 regex_matches 函数的更多信息

但是,以下内容应为您提供所需的内容

select regexp_matches(yourColumnName, '([0-9])\w+')[1] from yourTable 
于 2018-12-29T00:55:40.450 回答