トップページに戻る
次のSQLパズルへ
前のSQLパズルへ
10-343 To_DsInterVal関数でInterVal型に変換
SQLパズル
InterValTable
StrVal
-----------
00:07:06.63
00:05:19.51
00:09:39.52
00:03:53.08
11:12:34.56
StrValをInterVal型とみなして、合計を求める。
出力結果
SumInterVal
-----------------------------
+000000000 11:38:33.300000000
データ作成スクリプト
create table InterValTable(StrVal) as
select '00:07:06.63' from dual union all
select '00:05:19.51' from dual union all
select '00:09:39.52' from dual union all
select '00:03:53.08' from dual union all
select '11:12:34.56' from dual;
SQL
--■■■model句を使う方法(10g以降)■■■
select Val as SumInterVal
from InterValTable
model return updated rows
dimension by(RowNum as soeji)
measures(To_DsInterVal('0 ' || StrVal) as Val)
rules iterate(999)
until (presentV(Val[ITERATION_NUMBER+3],1,0) = 0)
(Val[1] = Val[1]+Val[ITERATION_NUMBER+2]);
--■■■NumToDsInterVal関数を使う方法■■■
select
NumToDsInterVal(
sum( to_number(substr(StrVal,1,2))*60*60
+to_number(substr(StrVal,4,2))*60
+to_number(substr(StrVal,7))),'second') as SumInterVal
from InterValTable;
解説