Utilisation de group by dans une fonction pl sql

amola19922 Messages postés 5 Date d'inscription   Statut Membre Dernière intervention   -  
amola19922 Messages postés 5 Date d'inscription   Statut Membre Dernière intervention   -
bonjour,
je veux savoir est ce que c'est possible d'utiliser un group by dans une fonction pl sql
create or replace
package body   non_val is  

function  get_non_val(p_id in number default 1, 
                            p_date_ref in date default sysdate, 
                             p_seg1 in varchar2, 
                             p_seg2 in varchar2, 
                             p_seg3 in varchar2)      
                        
                         return number is v_qnt number;
                             

begin
select SUM(mmt.TRANSACTION_QUANTITY) AS TRANSACTIONP
  into v_qnt
      from MTL_MA mmt, 
          mtl_s msi,
          mtl_pas mp,
          mtl_v micv 

            where 
              msi.IN_ID = mmt.INV_ID

              and mmt.ORGANIZATION_ID = mp.ORGANIZATION_ID
              and msi.ORGANIZATION_ID = mp.ORGANIZATION_ID

              and micv.inv_id = msi.inv_id 
              and micv.organization_id = msi.organization_id
            

                and trunc(mmt.transaction_date) <= TRUNC (p_date_ref)
                and  msi.organization_id =p_id 
                and msi.segm1=p_seg1
                and msi.segm2=p_seg2
                and msi.segm3=p_seg3
                group by msi.SEGM1||'.'||msi.SEGM2||'.'||msi.SEGM3,
                          mmt.ORGANIZATION_ID,
  
                           mmt.INV_ID,
                            msi.des,
                                                msi.SEGM1||'.'||msi.SEGM2,msi.segm3,
                            msi.SEGM2,
                          mp.attribute6
               having SUM(mmt.PRIMARY_QUANTITY) <> 0;



Exception 
When No_data_found Then 
null;
return nvl(v_qnt,0);

END get_non_val;





END non_val;

2 réponses

jordane45 Messages postés 38486 Date d'inscription   Statut Modérateur Dernière intervention   4 752
 
Bonjour,


est ce que c'est possible d'utiliser un group by dans une fonction pl sql

Oui.

La syntaxe étant :
SELECT expression1, expression2, ... expression_n, 
       aggregate_function (expression)
FROM tables
WHERE conditions
GROUP BY expression1, expression2, ... expression_n;

0
amola19922 Messages postés 5 Date d'inscription   Statut Membre Dernière intervention  
 
merci bcp pour votre reponse mais je veux savoir est ce que je doit utiliser aggregate ou bien group by comme j'ai deja montrer dans mon code?
merci bcp
0