0

Product列名の varchar2 データ型を持つテーブルがありますValue。この列の値は次のように格納されます

All,10:23,0.84522,1.245,10:54:68,
All,1:22:00,0.245,45:12:00 

(0.84522,1.245,0.245) のような浮動小数点値と、(1:22:00,45:12:00) のような ":00" で終わる浮動小数点値をすべて抽出する必要があります。

次のクエリがありますが、うまくいかないようです。文字以外のすべての値が表示されます。

select * from Product where Values BETWEEN to_char (0) and to_char (2);
4

2 に答える 2

0

このクエリを試してください:

select *
  from (select distinct regexp_substr(t.value, '[^,]+', 1, level) phrase
          from Product t
        connect by regexp_substr(t.value, '[^,]+', 1, level) is not null) ph
 where regexp_like(ph.phrase, '(\d+\.\d+)|(.+:00)')

where 句の正規表現には調整が必要な場合があります

それがすることは-

  1. すべてのフレーズを分離します (内部クエリ)
  2. 条件に一致するもののみを選択します

更新
パフォーマンスに問題がある場合は、別のアプローチを試すことができます。

create or replace type phrase_typ is object
(
  phrase varchar2(100)
)
;
/
create or replace type phrase_tab as table of phrase_typ;
/
create or replace function split_string(del in varchar2) return phrase_tab
  pipelined is

  phrase  varchar2(1000);
  str_t   varchar2(1000);
  v_del_i number;

  cursor c is with t as
    select value from product;

begin

  for r in c loop
    str_t := r.value;

    while str_t is not null loop

      v_del_i := instr(str_t, del, 1, 1);

      if v_del_i = 0 then
        phrase := str_t;
        str_t  := '';
      else
        phrase := substr(str_t, 1, v_del_i - 1);
        str_t  := substr(str_t, v_del_i + 1);
      end if;

      if regexp_like(phrase, '(\d+\.\d+)|(.+:00)') then
        pipe row(phrase_typ(phrase));
      end if;

    end loop;

  end loop;

  return;
end split_string;
/

クエリは次のようになります。

select * from table(split_string(','))
于 2012-05-09T06:00:03.153 に答える
0

私はこれがうまくいくと思う

select *
FROM  Product 
WHERE  
(Value LIKE '%:00' AND Value<>  'ALL') AND (Value BETWEEN  to_NUMBER (0) and to_NUMBER (2))
于 2012-05-09T05:29:59.743 に答える