Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 需要帮助使用Vertica中的特定分隔符函数捕获部分字符串值吗_Sql_Vertica - Fatal编程技术网

Sql 需要帮助使用Vertica中的特定分隔符函数捕获部分字符串值吗

Sql 需要帮助使用Vertica中的特定分隔符函数捕获部分字符串值吗,sql,vertica,Sql,Vertica,我有一个CustomerKey表,该表由一列Key组成,其示例值如下: ar.system.company.addr.clearinghouse ar.system.company.addr.dtac.th ar.system.company.info.clearinghouse.th .......... ... ...... ar.system.company.addr.dtac ar.system.company.addr.paysbuy 现在我必须使用一个函数,它将值返

我有一个
CustomerKey
表,该表由一列
Key
组成,其示例值如下:

ar.system.company.addr.clearinghouse
ar.system.company.addr.dtac.th
ar.system.company.info.clearinghouse.th
.......... ...         ......
ar.system.company.addr.dtac
ar.system.company.addr.paysbuy
现在我必须使用一个函数,它将值返回到第四个分隔符

比如:


注意:我发现了一种类似的函数
STRTOK()
,它在Snowflake中使用。但是我在Vertica中没有找到类似的函数。

我想您需要
regexp\u substr()


我想您需要
regexp\u substr()


您还可以获取列的子字符串,从位置1到第四次出现的“.”,从字符串的位置1开始,减去1

像这样:

WITH
input(string) AS (
          SELECT 'ar.system.company.addr.clearinghouse'
UNION ALL SELECT 'ar.system.company.addr.dtac.th'
UNION ALL SELECT 'ar.system.company.info.clearinghouse.th'
UNION ALL SELECT 'ar.system.company.addr.dtac'
UNION ALL SELECT 'ar.system.company.addr.paysbuy'
)
SELECT
  SUBSTR(string,1,INSTR(string,'.',1,4)-1) AS what_i_need
FROM input;
-- out       what_i_need       
-- out ------------------------
-- out  ar.system.company.addr
-- out  ar.system.company.addr
-- out  ar.system.company.info
-- out  ar.system.company.addr
-- out  ar.system.company.addr

您还可以获取列的子字符串,从位置1到第四次出现的“.”,从字符串的位置1开始,减去1

像这样:

WITH
input(string) AS (
          SELECT 'ar.system.company.addr.clearinghouse'
UNION ALL SELECT 'ar.system.company.addr.dtac.th'
UNION ALL SELECT 'ar.system.company.info.clearinghouse.th'
UNION ALL SELECT 'ar.system.company.addr.dtac'
UNION ALL SELECT 'ar.system.company.addr.paysbuy'
)
SELECT
  SUBSTR(string,1,INSTR(string,'.',1,4)-1) AS what_i_need
FROM input;
-- out       what_i_need       
-- out ------------------------
-- out  ar.system.company.addr
-- out  ar.system.company.addr
-- out  ar.system.company.info
-- out  ar.system.company.addr
-- out  ar.system.company.addr

非常感谢。这会带来预期的结果谢谢你。它给出了预期的结果
WITH
input(string) AS (
          SELECT 'ar.system.company.addr.clearinghouse'
UNION ALL SELECT 'ar.system.company.addr.dtac.th'
UNION ALL SELECT 'ar.system.company.info.clearinghouse.th'
UNION ALL SELECT 'ar.system.company.addr.dtac'
UNION ALL SELECT 'ar.system.company.addr.paysbuy'
)
SELECT
  SUBSTR(string,1,INSTR(string,'.',1,4)-1) AS what_i_need
FROM input;
-- out       what_i_need       
-- out ------------------------
-- out  ar.system.company.addr
-- out  ar.system.company.addr
-- out  ar.system.company.info
-- out  ar.system.company.addr
-- out  ar.system.company.addr