3

注文用のテーブルがあり、DATE タイプの 2 つの列 (delivery_date と order_date) があります。私のsqldeveloperでは、Java経由または手動で挿入したすべての日付は、今年の1月25日の10.01.25の形式になっています。ある日付と別の日付の間の注文の total_price を表示しようとすると、次のような形式を強制します。

create or replace function calc_Outlays (init_date IN DATE,final_date IN date)return number is

v_total_enc FORNECIMENTO.TOTAL_ENC_FORNEC%TYPE;

begin
select f.total_enc_fornec into v_total_enc from fornecimento f where f.data_entrega between init_date and final_date;
return v_total_enc;

Exception 
When no_data_found then
Insert Into errors Values (0,'No supplyment costs found for dates between '||to_char(init_date)||' and '||to_char(final_date),systimestamp);
return -1;
end;

しかし、-1 が返されます。私は次のようなクエリを実行しようとさえします:select f.total_enc_fornec from fornecimento f where f.data_entrega = '10.01.24';
このように: このselect f.total_enc_fornec from fornecimento f where f.data_entrega = to_date('10.01.24','yy-mm-dd');
ように:select f.total_enc_fornec from fornecimento f where f.data_entrega < to_date('10.01.24');そして何も返されません! しかし、私が実行すると:select f.total_enc_fornec from fornecimento f where f.data_entrega <= sysdate;想定どおりに結果が出力されます...

これどうやってするの?私は明らかにパラメータも関数も正しく渡しておらず、クエリ自体も実行していません

ところで、ある年/月/日のすべての注文を選択したい場合は? たとえば、抽出関数を使用します。方法を教えてください。試してみましたが、同じ問題を抱えていて、少なくとも概念は単純です笑。

4

1 に答える 1

3

Oracle DATE型は、日付と時刻を最も近い秒まで格納します。したがって、午前6時に10.01.24でf.data_entrega = '10.01.24'あるレコードとは一致しないと言えます。f.data_entrega同様に、SYSDATEは、現在の時刻と今日の日付を返します。

関数を日付部分のみで一致させたい場合(つまり、時間値を無視したい場合)、関数を変更する必要がある場合があります。

select f.total_enc_fornec into v_total_enc
from fornecimento f
where f.data_entrega between TRUNC(init_date) and TRUNC(final_date) + 0.99999;
于 2010-01-25T08:39:14.010 に答える