Добро пожаловать, Гость
Логин: Пароль: Запомнить меня
SQL, PL/SQL, T-SQL: запросы, DML DDL операторы, пакеты, процедуры, функции, триггеры и последовательности.
  • Страница:
  • 1
  • 2
  • 3

ТЕМА:

Re: Строка 12 года 4 мес. назад #3908

with sample_table as (select '02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21' str from dual)
select str,
regexp_replace(str,'(^|,)[^,-]+-','\1') new_str
from sample_table
/

STR NEW_STR

02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21 16.15,16.01,16.21

SQL>

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Re: Строка 12 года 4 мес. назад #3909

Ужас
select wm_concat(substr('02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21',
              (round(l.d *
                     length('02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21') /
                     nvl((length('02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21') -
                         length(replace('02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21',
                                         '-',
                                         ''))) / length('-'),
                         0) + 0.6) - 5),
              5))

  from dual, (select level as d from dual connect by level <= 3) l

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Re: Строка 12 года 4 мес. назад #3910

Or 3 characters shorter :lol:
with sample_table as (select '02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21' str from dual)
select  str,
        regexp_replace(str,'(^|,).+?-','\1') new_str
  from  sample_table
/

STR                                                                           NEW_STR
----------------------------------------------------------------------------- ------------------
02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21 16.15,16.01,16.21

SQL>

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Re: Строка 12 года 4 мес. назад #3911

Duh пишет: Or 3 characters shorter :lol:

with sample_table as (select '02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21' str from dual)
select  str,
        regexp_replace(str,'(^|,).+?-','\1') new_str
  from  sample_table
/

STR                                                                           NEW_STR
----------------------------------------------------------------------------- ------------------
02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21 16.15,16.01,16.21

SQL>

regexp_replace(str,'\d\d:.+?-')

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Re: Строка 12 года 4 мес. назад #3912

Есть еще такое решение
with t as (select '02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21' as str from dual)
select level,
instr(t.str, '-', 1, level) as posd,
instr(t.str, ',', 1, level) as poss,
substr(t.str,
instr(t.str, '-', 1, level) + 1,
case
when instr(t.str, ',', 1, level) - instr(t.str, '-', 1, level) - 1 > 0 then instr(t.str, ',', 1, level) - instr(t.str, '-', 1, level) - 1
else length(t.str) - instr(t.str, '-', 1, level) + 1
end)
from t
connect by level <= length(t.str) - length(replace(t.str, '-', ''))

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Последнее редактирование: от Super.

Re: Строка 12 года 4 мес. назад #3913

Super пишет:

Duh пишет: Or 3 characters shorter :lol:

with sample_table as (select '02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21' str from dual)
select  str,
        regexp_replace(str,'(^|,).+?-','\1') new_str
  from  sample_table
/

STR                                                                           NEW_STR
----------------------------------------------------------------------------- ------------------
02:12:2011 09:22:24-16.15,01:12:2011 17:30:49-16.01,04:12:2011 14:30:49-16.21 16.15,16.01,16.21

SQL>

regexp_replace(str,'\d\d:.+?-')

Well, that's assuming days are always zero-padded to two characters, otherwise:
SQL> with t as (select '2:2:2011 9:2:4-16.15,1:2:2011 7:3:4-16.01,4:2:2011 4:3:9-16.21' as str from dual)
  2  select  regexp_replace(str,'\d\d:.+?-') new_str
  3    from  t
  4  /

NEW_STR
------------------------------
2:2:2011 9:2:4-16.15,1:2:2011
7:3:4-16.01,4:2:2011 4:3:9-16.
21


SQL> with t as (select '2:2:2011 9:2:4-16.15,1:2:2011 7:3:4-16.01,4:2:2011 4:3:9-16.21' as str from dual)
  2  select  regexp_replace(str,'(^|,).+?-','\1') new_str
  3    from  t
  4  /

NEW_STR
------------------------------
16.15,16.01,16.21

SQL>

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

  • Страница:
  • 1
  • 2
  • 3
Время создания страницы: 0.272 секунд