Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Decode function - is it possible ?

Status
Not open for further replies.

nkshah

Programmer
Dec 16, 2009
25
US
thread186-1236075

i have exactly same problem of above Thread but it did not mention answer.

 
The subject of thread186-1236075 is dynamically translating code values into a more readable form for reporting purposes. I'm not sure why the link posted above isn't working.
 
Try this for starters:
Code:
var xrefc refcursor;

DECLARE
  v_str  VARCHAR2(10000) := 'SELECT JOB';
BEGIN
  FOR x IN (SELECT   DISTINCT deptno
            FROM     emp
            ORDER BY 1)
  LOOP
    v_str := v_str
             ||Chr(10)
             ||','
             ||'SUM(DECODE(E.DEPTNO,'''
             ||x.deptno
             ||''',e.sal,0)) AS "'
             ||x.deptno
             ||'"';
  END LOOP;
  
  v_str := v_str
           ||Chr(10)
           ||'FROM EMP E'
           ||Chr(10)
           ||'GROUP BY JOB ORDER BY JOB';
  
  dbms_output.Put_line(v_str);
  
  OPEN :xrefc FOR v_str;
END;
/
print :xrefc
[3eyes]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top