powered by simpleCommunicator - 2.0.18     © 2024 Programmizd 02
Map
Форумы / Informix [игнор отключен] [закрыт для гостей] / Ищу токенайзер на SPL
6 сообщений из 6, страница 1 из 1
Ищу токенайзер на SPL
    #39859560
cpr
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
cpr
Гость
Кому нибудь попадались толковые реализации?
...
Рейтинг: 0 / 0
Ищу токенайзер на SPL
    #39860909
cpr
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
cpr
Гость
Попробовал сам, собственно вот что получилось

create function ssplit3 (
plist char(30267),
pd SET (char(1) not null)
)
returning LIST (lvarchar(30267) not null);
define i,first,last int;
define ret_list LIST (lvarchar(30267) not null);
define ret_str lvarchar(30267);
let plist = nvl(plist,'');
let first,last=1,1;
for i=1 to length(trim(plist))
if(substr(plist,i,1) in pd) then
let ret_str=trim(substr(plist,first,i-first));
insert into table (ret_list) values (ret_str);
let first=i+1;
end if
end for
let ret_str=trim(substr(plist,first,i-first));
insert into table (ret_list) values (ret_str);
return ret_list;
end function;
...
Рейтинг: 0 / 0
Ищу токенайзер на SPL
    #39863643
Выбегалло
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
cpr,

смотри в сторону JSON/BSON .

Имеется запись JSON
{ "person" : {
"givenname" : "Jim",
"surname" : "Flynn",
"age" : 29,
"cars" : [ "dodge", "olds" ] }}



drop table if exists tt1;
create table tt1 (col1 int,
col2 bson);


insert into tt1 values (1, '{ "person" : { "givenname" : "Jim", "surname" : "Flynn", "age" : 29, "cars" : [ "dodge", "olds" ] }}'::JSON)

select col1, BSON_VALUE_LVARCHAR(col3, "person.givenname") from tt1 where col1 = 1
...
Рейтинг: 0 / 0
Ищу токенайзер на SPL
    #39899372
victor16
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
cpr,

Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
create function my_strtok (str lvarchar(2048), delim char(1), token_num smallint)
returning lvarchar(2048) as token;

        define str_len integer;
        define start_pos integer;
        define stop_pos integer;
        define cur_token_num integer;


        -- initialize start position and current token number to 1
        let start_pos = 1;
        let cur_token_num = 1;

        -- remove any leading delimiters from the input string
        let str = ltrim(str, delim);

        -- save the input string length so we don't have to recalculate it later
        let str_len = length(str);


        -- find the start of the token we want to return

        -- while there is still more string available to process
        while (start_pos <= str_len)
                -- if the current token number is the token we want, stop looking
                -- for a start position
                if (cur_token_num = token_num) then
                        exit;
                end if;

                -- increment the start position to the next character
                let start_pos = start_pos + 1;

                -- check to see if the current character in the string is a delimiter
                if (substr(str, start_pos, 1) = delim) then
                        -- we have found the next token
                        let cur_token_num = cur_token_num + 1;

                        -- advance the token start position past any repeating delimiters
                        while (start_pos <= str_len)
                                let start_pos = start_pos + 1;

                                if (substr(str, start_pos, 1) != delim) then
                                        -- there are no more repeating delimiters
                                        -- stop looking for repeating delimiters
                                        exit;
                                end if;
                        end while;
                end if;
        end while;


        -- we now either have the start position of the token we are looking for
        -- or we did not find the token we were looking for
        -- if we did not find the token, return NULL
        -- if we did find the token we were looking for, find the end of the token

        if (cur_token_num = token_num) then
                -- we found the token
                let stop_pos = start_pos;

                -- while there is still string to process try to find the end of our token
                -- if we run out of string before we find the next delimiter then
                -- our token ends where the string ends
                while (stop_pos <= str_len)
                        let stop_pos = stop_pos + 1;

                        if (substr(str, stop_pos, 1) = delim) then
                                -- we found the end
                                let stop_pos = stop_pos - 1;
                                exit;
                        end if;
                end while;

                -- return the found token
                return substr(str, start_pos, stop_pos - start_pos + 1);
        else
                -- the token was not found
                return NULL;
        end if;
end function;
...
Рейтинг: 0 / 0
Ищу токенайзер на SPL
    #39899373
victor16
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Пример использования:

Код: plsql
1.
2.
3.
4.
execute function my_strtok ("ABC CDE EFG", " ", 1);
execute function my_strtok ("ABC CDE EFG", " ", 2);
execute function my_strtok ("ABC CDE EFG", " ", 3);
execute function my_strtok ("ABC CDE EFG", " ", 4);
...
Рейтинг: 0 / 0
Ищу токенайзер на SPL
    #39936272
cpr
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
cpr
Гость
Выбегалло,

Кстати забавная ошибка в документации.

SELECT bson_col.person.cars.1::JSON FROM bson_table;

выдает ошибку 201

правильный вызов , который работает у меня

SELECT bson_col.person.cars.'1'::JSON FROM bson_table;

IDS 12.10FC10
...
Рейтинг: 0 / 0
6 сообщений из 6, страница 1 из 1
Форумы / Informix [игнор отключен] [закрыт для гостей] / Ищу токенайзер на SPL
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали тему (1): Анонимы (1)
Читали форум (1): Анонимы (1)
Пользователи онлайн (8): Анонимы (6), Bing Bot, Yandex Bot 1 мин.
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]