› Fóruns › Developer,Designer e Discoverer › Select no Plus OK, no Forms naum vai!! › Select no Plus OK, no Forms naum vai!!
Bom…tive que desmembrar a Query em três!
A primeira e principal, faz as consultas dos primeiros parâmetros, e informa um parâmetro às outras duas!
Ficou assim:
cursor X is
SELECT distinct
(b.cd_identdisc) B_IDENTIDISC,b.cd_disc,
(b.cd_disc||'#'||b.nm_abrev||'#' ) linha
FROM f_estat_geral_aproveitamento a,
f_Disciplina b,
f_departamento d
WHERE to_char(a.aa_anomatr)||to_char(a.ss_semematr) = :TXT_ANO||:TXT_SEM
AND a.id_idtfdisc = b.cd_identdisc
AND a.cd_dept = :CD_DEPT
AND a.cd_dept = d.cd_dept
order by b.cd_disc;
CURSOR TOTAL_ALUNO(p_identdisc f_disciplina.cd_identdisc%Type) IS
select sum(c.QT_QTDTOTAL)
from f_estat_geral_aproveitamento c,f_departamento d,
f_disciplina b
where to_char(c.aa_anomatr)||to_char(c.ss_semematr) = :TXT_ANO||:TXT_SEM
and c.id_idtfdisc = b.cd_identdisc
and d.cd_dept = :CD_DEPT
and c.cd_dept = d.cd_dept
and b.cd_identdisc = p_identdisc;
CURSOR REPROVADOS(p_identdisc f_disciplina.cd_identdisc%Type) IS
select sum(QT_QTDTOTAL)
from f_estat_geral_aproveitamento c,f_departamento d,
f_disciplina b
where to_char(c.aa_anomatr)||to_char(c.ss_semematr) = :TXT_ANO||:TXT_SEM
and c.id_idtfdisc = b.cd_identdisc
and c.cd_condaprv not in ('AP','SA')
and d.cd_dept = :CD_DEPT
and c.cd_dept = d.cd_dept
and b.cd_identdisc = p_identdisc;
Na hora de abrir dar um FETCH:
for r in x loop
open TOTAL_ALUNO(r.B_IDENTIDISC);
fetch TOTAL_ALUNO into v_total_alunos;
close Total_aluno;
open REPROVADOS(r.B_IDENTIDISC);
fetch REPROVADOS into v_total_REPROVA;
close REPROVADOS;
end loop;
É isso aí!
Abraços!
Toad