Here is my query and whether I passs a parameter or not the function returns a different value. I did a workaround by putting the contents of the inner-most query into a global temp table and it works fine. Any way I would still like to know what is wrong with the function. Thank you for your help. I am using Oracle 8i and my function is defined as:
--------------------------------
FUNCTION RPT_INSTITUTEFEE
(
p_srctype_id IN sourcetype.srcidtyp%TYPE
, p_badgesdelivered IN CHAR
, p_payAction IN VARCHAR2
, p_mtgeventtypeid IN NUMBER
, p_col IN NUMBER
) RETURN NUMBER
----------------------------------------------
SELECT sum(totalinvoiced)
, sum(PYMT_ALLOCATION)
FROM
(
SELECT s2.regid
, s2.regnbr
, s2.srcidtype
, s2.srcid
, badgesdelivered
, totalinvoiced
, PYMT_ALLOCATION
, paidyn
FROM
(
SELECT s1.regid
, s1.regnbr
, s1.srcidtype
, ri.srcid
, badgesdelivered
, totalinvoiced
, PYMT_ALLOCATION
, DECODE (SIGN ( ROUND (totalinvoiced, 2)
- ROUND (NVL (pymt_allocation, 0), 2))
,1
,'UNPAID'
,'PAID'
) paidyn
FROM
(
SELECT id.regid
, id.regnbr
, id.srcidtype
, rper.badgesdelivered
, sum(nvl(id.TOTALINVOICED,0)) totalinvoiced
, sum(nvl(id.PYMT_ALLOCATION,0)) PYMT_ALLOCATION
FROM reg_inv_pay_detl id
, RegPerson rper
WHERE id.regid = rper.regid
AND rper.regstsID IS NULL
AND srcidtype = 2 -- events/registration -- pass param events
GROUP BY id.regid
, id.regnbr
, id.srcidtype
, rper.badgesdelivered
) s1
, reginvoice ri
WHERE s1.regid = ri.regid (+)
AND s1.srcidtype = ri.srcidtype
AND s1.badgesdelivered = 'N' -- pass parameter
)s2
, mtgevent ME
, RegMtgEvent RME
WHERE s2.SrcID=RME.MTGEVENTID(+)
AND s2.REGID=RME.REGID(+)
AND RME.MTGEVENTID=ME.MTGEVENTID(+)