Estrutura IF-Else em um Select condicinal

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Responder
Dtrindade
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Mensagens: 1
Registrado em: Qua, 17 Jun 2015 11:59 am

Pessoal , gostaria de uma ajuda com relação ao código abaixo:

Selecionar tudo

DECLARE

a VARCHAR(30):='WC';

BEGIN

if(a!=null) THEN
SELECT NP.tipo 
       count(NP.total) 
       count(NPO.total) 
       count(NPV.total) 
       ROUND((count(NPO.total)/count(NP.total)*100),2) 
       ROUND(AVG(NPO.maximo),2) 
       ROUND((SUM(NPO.Corrente) / SUM(NPO.MAXIMO)) * 100, 2) 
       COUNT(CASE
                       WHEN NPO.corrente <= NPO.maximo / 4 THEN
                        1
                     end) AS "Quarter(<=25%)",
       COUNT(CASE
                       WHEN NPO.corrente <= NPO.maximo / 2 THEN
                        1
                     end) AS "Half(<=50%)",
       COUNT(CASE
                       WHEN NPO.corrente <= (NPO.maximo / 4) * 3 THEN
                        1
                     end) AS "Half plus Quarte(<=75%)"
  FROM locn_hdr lh,
       (SELECT locn_id total,locn_size_type tipo
       from resv_locn_hdr) NP,
       (SELECT locn_id total, curr_vol corrente,max_vol maximo
          from resv_locn_hdr
         where curr_uom_qty > 0
         ) NPO,
       (SELECT locn_id total,locn_size_type
          FROM resv_locn_hdr
         where curr_uom_qty = 0
         ) NPV
         
         WHERE lh.locn_id=NP.total
         AND   lh.locn_id=NPO.total(+)
         AND   lh.locn_id=NPV.total(+)
         group by NP.tipo
        
        
         
        END IF;
bom , a minha intenção é fazer com que a variável a, dependendo se for nula, ou possuir algum conteúdo, execute o select, essa variável sera fornecida pelo usuário, em um relatório do Crystal reports, mas ocorre erro.
Avatar do usuário
madmax
Rank: DBA Pleno
Rank: DBA Pleno
Mensagens: 293
Registrado em: Qua, 13 Dez 2006 5:02 pm
Localização: São Paulo
Contato:
________________________________
Douglas - Madmax.

Cara tente assim:

Selecionar tudo

DECLARE

a VARCHAR(30):='WC';

BEGIN

IF a IS NOT NULL THEN
    SELECT NP.tipo 
    count(NP.total) 
    count(NPO.total) 
    count(NPV.total) 
    ROUND((count(NPO.total)/count(NP.total)*100),2) 
    ROUND(AVG(NPO.maximo),2) 
    ROUND((SUM(NPO.Corrente) / SUM(NPO.MAXIMO)) * 100, 2) 
    COUNT(CASE
    WHEN NPO.corrente <= NPO.maximo / 4 THEN
    1
    end) AS "Quarter(<=25%)",
    COUNT(CASE
    WHEN NPO.corrente <= NPO.maximo / 2 THEN
    1
    end) AS "Half(<=50%)",
    COUNT(CASE
    WHEN NPO.corrente <= (NPO.maximo / 4) * 3 THEN
    1
    end) AS "Half plus Quarte(<=75%)"
    FROM locn_hdr lh,
    (SELECT locn_id total,locn_size_type tipo
    from resv_locn_hdr) NP,
    (SELECT locn_id total, curr_vol corrente,max_vol maximo
    from resv_locn_hdr
    where curr_uom_qty > 0
    ) NPO,
    (SELECT locn_id total,locn_size_type
    FROM resv_locn_hdr
    where curr_uom_qty = 0
    ) NPV

    WHERE lh.locn_id=NP.total
    AND lh.locn_id=NPO.total(+)
    AND lh.locn_id=NPV.total(+)
    group by NP.tipo

END IF;
Espero ter ajudado.

Douglas - MADMAX
Responder
  • Informação
  • Quem está online

    Usuários navegando neste fórum: Nenhum usuário registrado e 9 visitantes