Hi Experts,
I have one select query which having some one function call and taking very long time to give the result.
Please find the code below:
Please note below function "getrolesforuse r" is being called from above SQL.
I want select query posted above should fetch the records within half minute.
Pls provide some solution on this asap.
Thanks in Advance
Bhushan
I have one select query which having some one function call and taking very long time to give the result.
Please find the code below:
Code:
SELECT a.ID, a.idtype, a.username, a.firstname, a.lastname, a.status,
a.languageid, a.languagename, getrolesforuser (a.username) ROLES,
0 clubid, a.isdisabled, 0 region
FROM (SELECT w.ID, w.idtype, w.username, p.firstname, p.lastname,
w.acct_statcd status, w.preferredlanguage languageid,
lt.langname languagename, p.sortfirstname, p.sortlastname,
w.isdisabled, TRUNC (w.createdt) createdt, registration_type
FROM webuser w JOIN person p ON w.ID = p.ID AND w.idtype = p.idtype
LEFT JOIN langtype lt ON w.preferredlanguage = lt.langty
) a
WHERE 1 = 1 AND TRUNC (a.createdt) BETWEEN '01-Jun-2009' AND '30-Oct-2009'
Code:
FUNCTION getrolesforuser (pusername IN webuser.username%TYPE)
RETURN VARCHAR2
IS
vroles VARCHAR (1000);
CURSOR cursorout (pusernames VARCHAR2)
IS
SELECT /*+INDEX(PH) INDEX(WU)INDEX(PN)*/
NVL2 (c.commdesc,
pn.posdesc || '-' || c.commdesc,
pn.posdesc
) rolename
FROM positionholder ph,
webuser wu,
positionname pn,
(SELECT /*+INDEX(CD)INDEX(CN)*/
cd.commid, cn.commdesc
FROM committee cd, commname cn
WHERE cn.commid = cd.commid
AND cd.effdt <= SYSDATE
AND (cd.enddt >= SYSDATE OR cd.enddt IS NULL)
AND cn.langty = 0) c
WHERE ph.ID = wu.ID
AND ph.idtype = wu.idtype
AND ph.positionid = pn.positionid
AND ph.commid = c.commid(+)
AND ph.effdt <= SYSDATE
AND (ph.enddt >= SYSDATE OR ph.enddt IS NULL)
AND UPPER (wu.username) = UPPER (pusernames)
AND pn.langty = 0
AND pn.gender = 'M'
UNION
SELECT /*+INDEX(PN)*/
pn.posdesc
FROM positionname pn
WHERE pn.posdesc = 'All Constituents';
-- Declare program variables as shown above
BEGIN
FOR rec_cur IN cursorout (pusername)
LOOP
IF vroles IS NULL
THEN
LOOP
vroles := rec_cur.rolename;
END LOOP;
ELSE
vroles := vroles || ', ' || rec_cur.rolename;
END IF;
END LOOP;
RETURN vroles;
EXCEPTION
WHEN OTHERS
THEN
BEGIN
DBMS_OUTPUT.put ('error');
END;
END getrolesforuser;
Pls provide some solution on this asap.
Thanks in Advance
Bhushan
Comment