コンテキストに依存しすぎるため、正規表現で連続した数字を識別することはできません。
ただし、これは PL/SQL では簡単に可能であり、SQL でもおそらく可能であると思います。
SQLのみを使用する場合connect by
は、文書化されていない関数wm_contact
またはユーザー定義関数のいずれかとの組み合わせを使用して、連続した数字の文字列を生成できます。stragg
何かのようなもの:
select replace(stragg(level),',','')
from dual
connect by level <= 5
これを正規表現と連結すると、近づくかもしれませんが、これが道だとは思いません。PL/SQL関数を使用して調査し、正規表現を完全に忘れている可能性があります。
以下を実行すると、数値が配列に分割され、ループして操作できるようになります。要求どおり、これは単なる開始点であり、多くの変更を加えたい場合があります。実際の SQL はなく、単なる文字列操作であるため、このようなことを行うと非常に効率的です。
create or replace function validate_phone( P_phone number )
return number is
type t__phone is table of number index by binary_integer;
t_phone t__phone;
l_consecutive varchar2(150);
begin
-- Test whether we actually have a number first ( code below ).
if is_number(P_phone) = 0 then
return null;
end if;
-- Split out the phone number into individual array elements.
for i in 1 .. length(to_char(P_phone)) loop
t_phone(i) := substr(to_char(P_phone, i, 1))
end loop;
for i in t_phone.first .. t_phone.last loop
-- If we find a consecutive number then build this string.
if t_phone.exists(i + 1)
and t_phone(i) = t_phone(i + 1) - 1 then
l_consecutive := l_consecutive || t_phone(i);
end if;
end loop;
return something;
end validate_phone;
上記のように、最初に電話番号が実際に数字であるかどうかを確認することができます。
create or replace function is_number( P_number varchar2 )
return number is
/* Test a number to see whether it actually is one
return a 1 / 0 rather than boolean so it can also
be used in plain SQL.
*/
l_number number;
begin
l_number := P_number;
return 1;
exception when others then
return 0;
end is_number;