SELECT se.sid,n.name , SUBSTR(s.PROGRAM,INSTR(S.PROGRAM,'(')+1,4) PROCESS_NAME, MAX(se.value) pga_memory,
DECODE( r.APPLY_NAME, NULL, DECODE(coor.APPLY_NAME,NULL, ser.APPLY_NAME, coor.APPLY_NAME), r.APPLY_NAME ) APPLY_NAM,
cap.CAPTURE_NAME, q.QNAME, s.USERNAME
FROM v$sesstat se, v$statname n, V$SESSION s,
V$STREAMS_APPLY_READER r, V$STREAMS_APPLY_coordinator coor, V$STREAMS_APPLY_SERVER ser,
GV$STREAMS_CAPTURE c, dba_capture cap ,
dba_queue_schedules q
WHERE n.statistic# = se.statistic#
AND s.sid= se.sid
AND n.name IN ('session pga memory')
AND s.SID = r.SID(+)
AND s.SERIAL# = r.SERIAL#(+)
AND s.SID = coor.SID(+)
AND s.SERIAL# = coor.SERIAL#(+)
AND s.SID = ser.SID(+)
AND s.SERIAL# = ser.SERIAL#(+)
AND c.CAPTURE_NAME = cap.CAPTURE_NAME(+)
AND s.SID = c.SID(+)
AND s.SERIAL# = c.SERIAL# (+)
AND s.SID = TO_NUMBER(SUBSTR (q.session_id(+), 1, INSTR(q.session_id(+), ',')- 1 ))
AND s.SERIAL# = TO_NUMBER(SUBSTR (q.session_id(+), INSTR(q.session_id(+), ',') +1 , LENGTH(q.session_id(+)) - INSTR(q.session_id(+), ',')))
GROUP BY n.name,se.sid, SUBSTR(s.PROGRAM,INSTR(S.PROGRAM,'(')+1,4),DECODE( r.APPLY_NAME, NULL, DECODE(coor.APPLY_NAME,NULL, ser.APPLY_NAME, coor.APPLY_NAME), r.APPLY_NAME ), cap.CAPTURE_NAME, q.qname, s.USERNAME
ORDER BY 4 DESC ;
DECODE( r.APPLY_NAME, NULL, DECODE(coor.APPLY_NAME,NULL, ser.APPLY_NAME, coor.APPLY_NAME), r.APPLY_NAME ) APPLY_NAM,
cap.CAPTURE_NAME, q.QNAME, s.USERNAME
FROM v$sesstat se, v$statname n, V$SESSION s,
V$STREAMS_APPLY_READER r, V$STREAMS_APPLY_coordinator coor, V$STREAMS_APPLY_SERVER ser,
GV$STREAMS_CAPTURE c, dba_capture cap ,
dba_queue_schedules q
WHERE n.statistic# = se.statistic#
AND s.sid= se.sid
AND n.name IN ('session pga memory')
AND s.SID = r.SID(+)
AND s.SERIAL# = r.SERIAL#(+)
AND s.SID = coor.SID(+)
AND s.SERIAL# = coor.SERIAL#(+)
AND s.SID = ser.SID(+)
AND s.SERIAL# = ser.SERIAL#(+)
AND c.CAPTURE_NAME = cap.CAPTURE_NAME(+)
AND s.SID = c.SID(+)
AND s.SERIAL# = c.SERIAL# (+)
AND s.SID = TO_NUMBER(SUBSTR (q.session_id(+), 1, INSTR(q.session_id(+), ',')- 1 ))
AND s.SERIAL# = TO_NUMBER(SUBSTR (q.session_id(+), INSTR(q.session_id(+), ',') +1 , LENGTH(q.session_id(+)) - INSTR(q.session_id(+), ',')))
GROUP BY n.name,se.sid, SUBSTR(s.PROGRAM,INSTR(S.PROGRAM,'(')+1,4),DECODE( r.APPLY_NAME, NULL, DECODE(coor.APPLY_NAME,NULL, ser.APPLY_NAME, coor.APPLY_NAME), r.APPLY_NAME ), cap.CAPTURE_NAME, q.qname, s.USERNAME
ORDER BY 4 DESC ;