我有一个很长的查询,根据句点计算几个项目。话虽如此,我有 period P1 (转换为 07:00:00 和 08:59:59,就这样。我必须按 medic 和 period 计算所有计数。我使用绑定值来搜索表格(trunc(a.dt_agenda, 'dd') between :dt_inicial 和 :dt_final ) 由于我使用 UNION ALL 将所有句点放在一起,因此查询很长,我需要将其存储在 varchar2 字段 (4000) 中。所以,我需要从我的查询中创建一个对象(可能是一个视图),在查询中搜索视图而不是表。视图不接受绑定值并且没有绑定我无法插入开始日期和结束日期。有人对我如何完成这项工作有任何提示吗?提前致谢
我尝试创建仅在查询中包含日期列的视图,但之后我无法使其工作(针对视图进行查询)
SELECT
t.medico,
t.periodo,
t.capacidademaxima,
t.disponiveis,
t.usados,
t.faltas,
t.cancelamentos,
t.pa,
t.reforcopa,
t.compromissoparicular,
t.outrosempregos,
t.reunioeshdp,
t.reunioeslaboratorios,
t.almoco,
t.exameseprocedimentos,
t.hospitaisecirurgias,
t.aulas,
t.congresso,
t.ferias,
t.maternidade,
t.tratamentomedico
FROM (
SELECT
obter_desc_agenda(cd_agenda) medico,
'P1' periodo,
count(case when a.ie_status_agenda <> 'C' then 1 else null end) capacidademaxima,
count(case when nvl(a.nr_seq_motivo_transf,0) not in (30) and a.ie_status_agenda <> 'C' then 1 else null end) disponiveis,
count(case when a.ie_status_agenda in ('E','L','N') then 1 else null end) usados,
count(case when a.ie_status_agenda in ('I') then 1 else null end) faltas,
count(case when a.ie_status_agenda in ('C') then 1 else null end) cancelamentos,
count(case when nvl(a.nr_seq_motivo_transf,0) in (10) then 1 else null end) pa,
count(case when nvl(a.nr_seq_motivo_transf,0) in (15) then 1 else null end) reforcopa,
count(case when nvl(a.nr_seq_motivo_transf,0) in (28) then 1 else null end)compromissoparicular,
count(case when nvl(a.nr_seq_motivo_transf,0) in (12) then 1 else null end) outrosempregos,
count(case when nvl(a.nr_seq_motivo_transf,0) in (16) then 1 else null end) reunioeshdp,
count(case when nvl(a.nr_seq_motivo_transf,0) in (26) then 1 else null end) reunioeslaboratorios,
count(case when nvl(a.nr_seq_motivo_transf,0) in (20) then 1 else null end) ferias,
count(case when nvl(a.nr_seq_motivo_transf,0) in (33) then 1 else null end) almoco,
count(case when nvl(a.nr_seq_motivo_transf,0) in (27) then 1 else null end) exameseprocedimentos,
count(case when nvl(a.nr_seq_motivo_transf,0) in (11) then 1 else null end) hospitaisecirurgias,
count(case when nvl(a.nr_seq_motivo_transf,0) in (13) then 1 else null end) aulas,
count(case when nvl(a.nr_seq_motivo_transf,0) in (14) then 1 else null end) congresso,
count(case when nvl(a.nr_seq_motivo_transf,0) in (32) then 1 else null end) tratamentomedico,
count(case when nvl(a.nr_seq_motivo_transf,0) in (31) then 1 else null end) maternidade
FROM
agenda_consulta a
WHERE
trunc(a.dt_agenda, 'dd') between :dt_inicial and :dt_final
AND to_char(a.dt_agenda, 'HH24:MI:SS') between ('07:00:00') and ('08:59:59')
GROUP BY
obter_desc_agenda(cd_agenda), 'P1'
UNION ALL
SELECT
obter_desc_agenda(cd_agenda) medico,
'P2' periodo,
count(case when a.ie_status_agenda <> 'C' then 1 else null end) capacidademaxima,
count(case when nvl(a.nr_seq_motivo_transf,0) not in (30) and a.ie_status_agenda <> 'C' then 1 else null end) disponiveis,
count(case when a.ie_status_agenda in ('E','L','N') then 1 else null end) usados,
count(case when a.ie_status_agenda in ('I') then 1 else null end) faltas,
count(case when a.ie_status_agenda in ('C') then 1 else null end) cancelamentos,
count(case when nvl(a.nr_seq_motivo_transf,0) in (10) then 1 else null end) pa,
count(case when nvl(a.nr_seq_motivo_transf,0) in (15) then 1 else null end) reforcopa,
count(case when nvl(a.nr_seq_motivo_transf,0) in (28) then 1 else null end)compromissoparicular,
count(case when nvl(a.nr_seq_motivo_transf,0) in (12) then 1 else null end) outrosempregos,
count(case when nvl(a.nr_seq_motivo_transf,0) in (16) then 1 else null end) reunioeshdp,
count(case when nvl(a.nr_seq_motivo_transf,0) in (26) then 1 else null end) reunioeslaboratorios,
count(case when nvl(a.nr_seq_motivo_transf,0) in (20) then 1 else null end) ferias,
count(case when nvl(a.nr_seq_motivo_transf,0) in (33) then 1 else null end) almoco,
count(case when nvl(a.nr_seq_motivo_transf,0) in (27) then 1 else null end) exameseprocedimentos,
count(case when nvl(a.nr_seq_motivo_transf,0) in (11) then 1 else null end) hospitaisecirurgias,
count(case when nvl(a.nr_seq_motivo_transf,0) in (13) then 1 else null end) aulas,
count(case when nvl(a.nr_seq_motivo_transf,0) in (14) then 1 else null end) congresso,
count(case when nvl(a.nr_seq_motivo_transf,0) in (32) then 1 else null end) tratamentomedico,
count(case when nvl(a.nr_seq_motivo_transf,0) in (31) then 1 else null end) maternidade
FROM
agenda_consulta a
WHERE trunc(a.dt_agenda, 'dd') between :dt_inicial and :dt_final
AND to_char (a.dt_agenda, 'HH24:MI:SS') between ('09:00:00') and ('11:59:59')
GROUP BY obter_desc_agenda(cd_agenda), 'P2'
UNION ALL
Then it repeats to P3, P4, P5 and the last part is "Total"
SELECT
obter_desc_agenda(cd_agenda) medico,
'Total' periodo,
count(case when a.ie_status_agenda <> 'C' then 1 else null end) capacidademaxima,
count(case when nvl(a.nr_seq_motivo_transf,0) not in (30) and a.ie_status_agenda <> 'C' then 1 else null end) disponiveis,
count(case when a.ie_status_agenda in ('E','L','N') then 1 else null end) usados,
count(case when a.ie_status_agenda in ('I') then 1 else null end) faltas,
count(case when a.ie_status_agenda in ('C') then 1 else null end) cancelamentos,
count(case when nvl(a.nr_seq_motivo_transf,0) in (10) then 1 else null end) pa,
count(case when nvl(a.nr_seq_motivo_transf,0) in (15) then 1 else null end) reforcopa,
count(case when nvl(a.nr_seq_motivo_transf,0) in (28) then 1 else null end)compromissoparicular,
count(case when nvl(a.nr_seq_motivo_transf,0) in (12) then 1 else null end) outrosempregos,
count(case when nvl(a.nr_seq_motivo_transf,0) in (16) then 1 else null end) reunioeshdp,
count(case when nvl(a.nr_seq_motivo_transf,0) in (26) then 1 else null end) reunioeslaboratorios,
count(case when nvl(a.nr_seq_motivo_transf,0) in (20) then 1 else null end) ferias,
count(case when nvl(a.nr_seq_motivo_transf,0) in (33) then 1 else null end) almoco,
count(case when nvl(a.nr_seq_motivo_transf,0) in (27) then 1 else null end) exameseprocedimentos,
count(case when nvl(a.nr_seq_motivo_transf,0) in (11) then 1 else null end) hospitaisecirurgias,
count(case when nvl(a.nr_seq_motivo_transf,0) in (13) then 1 else null end) aulas,
count(case when nvl(a.nr_seq_motivo_transf,0) in (14) then 1 else null end) congresso,
count(case when nvl(a.nr_seq_motivo_transf,0) in (32) then 1 else null end) tratamentomedico,
count(case when nvl(a.nr_seq_motivo_transf,0) in (31) then 1 else null end) maternidade
FROM
agenda_consulta a
WHERE trunc(a.dt_agenda, 'dd') between :dt_inicial and :dt_final
GROUP BY
obter_desc_agenda(cd_agenda), 'Total'
) t
order by medico, periodo