これを行う方法があります。パフォーマンスが問題であれば重要な標準文字列関数を使用します(標準関数は正規表現関数よりもはるかに高速です)。
ただし、'do-it-yourself'
という文字列も'000do-00it-yo'
に変換されることに注意してください。それが望ましくない場合は、元の投稿のすべてのルールを説明する必要があります。
with
inputs (str) as (
select '1111-2222-33' from dual union all
select '11111-222-33' from dual union all
select '11111-2222-3' from dual union all
select '1234-03-0' from dual
)
-- End of simulated inputs (for testing only, not part of the solution).
-- SQL query begins BELOW THIS LINE. Use your actual table and column names.
select str,
lpad(substr(str, 1, instr(str, '-') - 1), 5, '0') || '-' ||
lpad(substr(str, instr(str, '-') + 1,
instr(str, '-', 1, 2) - instr(str, '-') - 1), 4, '0')
|| '-' || lpad(substr(str, instr(str, '-', 1, 2) + 1), 2, '0') as new_str
from inputs
;
STR NEW_STR
------------ -------------
1111-2222-33 01111-2222-33
11111-222-33 11111-0222-33
11111-2222-3 11111-2222-03
1234-03-0-0003-00
これまで行ったことはありますか? SOはコーディングサービスではありません。 –
@Temani Afif私はあなたを得ませんでした。 –
[so]は_freeコーディング_ウェブサイトではありません。あなたが今までに試したことや努力をあなたに伝えてください。私たちはあなたが問題にぶつかるときに役立ちます**あなたのためにあなたのコードを書く**ではありません。適切な質問をする方法を学ぶために、[ツアー]をして[質問]ページを読むことをお勧めします。 – Shogunivar