col red for a8
col green for a8
col blue for a8
col total for a20
--■■■正規表現の検索結果を使う方法■■■
select ID,color,
RTrim(red,'G') as red,
RTrim(green,'B') as green,
blue,
case when greatest(red,green,blue) is not null
then RTrim(red,'G') || RTrim(green,'B') || blue end as total
from (select ID,color,
RegExp_Substr(color,'R([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])G') as red,
RegExp_Substr(color,'G([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])B') as green,
RegExp_Substr(color,'B([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])$') as blue
from ColorTable);
--■■■正規表現の検索結果を使わない方法■■■
select ID,color,
RTrim(red,'G') as red,
RTrim(green,'B') as green,
blue,total
from (select ID,color,
RegExp_Substr(color,'R([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])G') as red,
RegExp_Substr(color,'G([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])B') as green,
RegExp_Substr(color,'B([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])$') as blue,
RegExp_Substr(color,'R([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])'
|| 'G([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])'
|| 'B([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])$') as total
from ColorTable);