【问题标题】:MemSQL - populate a table using comma separate string valueMemSQL - 使用逗号分隔的字符串值填充表
【发布时间】:2023-03-17 03:43:02
【问题描述】:

我需要将值列表传递给 MemSQL 过程。 有没有办法将输入字符串中逗号分隔的整数值转换为表格。

【问题讨论】:

    标签: singlestore


    【解决方案1】:

    MemSQL 还没有类似 python 字符串 split 函数的东西,它将分隔字符串转换为字符串数组。在 MemSQL 6.5 中,最好的方法是使用 locate 内置函数来执行类似的操作。

    delimiter //
    create or replace procedure insert_split_string(input text, d text) as
    declare
        position int = 1;
        newPosition int = -1; 
    begin
        while newPosition != 0 loop
            newPosition = locate(d, input, position);
            if newPosition != 0 then
                insert into t values(substring(input, position, newPosition - position));
                position = newPosition + 1;
            end if; 
        end loop;
    
        -- Add the last delimited element
        insert into t values(substring_index(input, d, -1));
    end //
    delimiter ;
    
    create table t(i int);
    call insert_split_string("1,2,3,4,5", ",");
    select * from t;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多