Вы не можете создать представление, которое возвращает входные переменные в качестве значения столбца, но у вас есть 2 варианта получить то, что вы хотите:
a) Используйте простой запрос: :dt
вот вы вводите переменную привязки
with t(FROM_CODE,TO_CODE,DAYTIME,TRAN_REASON,QTY) as (
select 'A', 'B', to_date('08-OCT-2019 02:00','dd-mon-yyyy hh24:mi'), 'LEND', 100 from dual union all
select 'A', 'B', to_date('07-NOV-2019 04:00','dd-mon-yyyy hh24:mi'), 'LEND', 200 from dual union all
select 'A', 'C', to_date('20-JAN-2020 13:00','dd-mon-yyyy hh24:mi'), 'LEND', 400 from dual union all
select 'B', 'A', to_date('05-MAR-2020 20:00','dd-mon-yyyy hh24:mi'), 'RETURN', 150 from dual union all
select 'C', 'A', to_date('09-MAR-2020 23:00','dd-mon-yyyy hh24:mi'), 'RETURN', 200 from dual union all
select 'C', 'A', to_date('08-APR-2020 02:00','dd-mon-yyyy hh24:mi'), 'RETURN', 100 from dual
)
select
FROM_CODE,
TO_CODE,
:dt,
TRAN_REASON,
sum(qty)
from t
where daytime<=:dt
group by
FROM_CODE,
TO_CODE,
TRAN_REASON
b) использовать конвейерную функцию с тем же запросом: Полный пример:
create table test_data as
with t(FROM_CODE,TO_CODE,DAYTIME,TRAN_REASON,QTY) as (
select 'A', 'B', to_date('08-OCT-2019 02:00','dd-mon-yyyy hh24:mi'), 'LEND', 100 from dual union all
select 'A', 'B', to_date('07-NOV-2019 04:00','dd-mon-yyyy hh24:mi'), 'LEND', 200 from dual union all
select 'A', 'C', to_date('20-JAN-2020 13:00','dd-mon-yyyy hh24:mi'), 'LEND', 400 from dual union all
select 'B', 'A', to_date('05-MAR-2020 20:00','dd-mon-yyyy hh24:mi'), 'RETURN', 150 from dual union all
select 'C', 'A', to_date('09-MAR-2020 23:00','dd-mon-yyyy hh24:mi'), 'RETURN', 200 from dual union all
select 'C', 'A', to_date('08-APR-2020 02:00','dd-mon-yyyy hh24:mi'), 'RETURN', 100 from dual
)
select *
from t
/
create or replace package pkg_test as
type t_test_data_row is record (
DAYTIME test_data.DAYTIME%type,
FROM_CODE test_data.FROM_CODE%type,
TO_CODE test_data.TO_CODE%type,
TRAN_REASON test_data.TRAN_REASON%type,
QTY test_data.QTY%type
);
type t_test_data_tab is table of t_test_data_row;
function get_output (dt date) return t_test_data_tab pipelined;
end;
/
create or replace package body pkg_test as
function get_output (dt date) return t_test_data_tab pipelined
is
begin
for r in (
select
get_output.dt,
FROM_CODE,
TO_CODE,
TRAN_REASON,
sum(qty) as qty
from test_data
where daytime<=get_output.dt
group by
FROM_CODE,
TO_CODE,
TRAN_REASON
)
loop
pipe row (r);
end loop;
end;
end;
/
select *
from table(pkg_test.get_output(to_date('2020-03-05 21:00','yyyy-mm-dd hh24:mi')));
Результат:
DAYTIME F T TRAN_R QTY
------------------- - - ------ ----------
2020-03-05 21:00:00 A B LEND 300
2020-03-05 21:00:00 B A RETURN 150
2020-03-05 21:00:00 A C LEND 400