2016-08-31 11 views
0

私はクエリ全体を実行しています。最後にエラー(タイトル)が出て、出力が下のExcelイメージのようになるまで、すべて正常に動作します。私はcharとnumとdateとして時間を保持しようとしましたが、まだエラーが発生しています。どんな助けもありがとう。お気軽に質問し、ツール内のコードを確認してください。おかげOracle SQL - 時間は0から23の間の誤差でなければなりません

Output_sample

with ht as( 
    select labno, birthdt, spectype, 
--to_char(
    ((dtrecv - dtcoll) 
    + (to_date(nvl(tmrecv, '0000'), 'hh24mi') 
    - to_date(nvl(tmcoll, '0000'), 'hh24mi')) 
    ) * 24 
--, 'hh24:mi') 
    as hours 
    from azmsds.sample_demog_view 
    where tmrecv is not null and tmcoll is not null and dtrecv is not null and dtcoll is not null 
), 


    secondQuery AS (
    select 
     ht.hours,  
     extract(year from ht.birthdt) as "YEAR", 
     extract (month from ht.birthdt) as "MONTH", 
     count(distinct ht.labno) as "initialDbsReceiptCount<1", 
    '~' AS EOL 
    from ht 
    where 1=1 
and ht.hours is not null  
     --and month not null 
     AND ht.birthdt >= '01-JAN-12' 
    -- and hours <= 23 
     and ht.spectype in (1,5,7) 
    --and hours > 23 
    group by extract(year from ht.birthdt), extract (month from ht.birthdt), ht.hours 
    order by extract(year from ht.birthdt) desc 
), 
    ThirdQuery AS (
    SELECT 
     sq.year, 
     sq.month, 
     sq."initialDbsReceiptCount<1", 
     sq.eol 
    FROM secondQuery sq 
    WHERE 1=1 
    --AND sq.hours <= 24 
) 
select * from ThirdQuery 

答えて

0

あなたは

select to_date('2500', 'hh24mi') from dual; 

を行う場合は、このエラーを受け取ることになります

...あなたはにiether tmrecv OR tmcollでいくつか間違ったデータを持っている私には思えます。

だから私は、以下しようとして開始すると、あなたにエラーを与える問題は、上記の

select to_date(nvl(tmrecv, '0000'), 'hh24mi') as hours 
from azmsds.sample_demog_view 
where tmrecv is not null and tmcoll is not null and dtrecv is not null and dtcoll is not null 

select to_date(nvl(tmcoll, '0000'), 'hh24mi')) as hours 
    from azmsds.sample_demog_view 
    where tmrecv is not null and tmcoll is not null and dtrecv is not null and dtcoll is not null 

つまたは他のです絞り込むことを選択し、あなたが調べることができますこれらのフィールドのデータを使用して、エラーの原因となっているデータを見つけます。

0

無効な時間値があるようです。これは悪いものを識別するのに役立ちます。

select * from azmsds.sample_demog_view 
where 
     tmrecv not like '[0-2][0-9][0-5][0-9]' 
    or tmcoll not like '[0-2][0-9][0-5][0-9]' 
    or not tmrecv between '0000' and '2359' 
    or not tmcoll between '0000' and '2359' 
関連する問題