Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Join of gv$session and gv$sqlarea

CastellSep 29 2016 — edited Oct 1 2016

DB Version:11.2.0.4

OS : Oracle Linux 6.5

When I join gv$session and gv$sqlarea , should I use SQL_ID  or SQL_ADDRESS as the join condition ? ie. Which is correct ; Query1 or Query2 ?

Query1:

SELECT count(*)

    FROM gv$session a INNER JOIN  gv$sqlarea b on A.sql_id = B.SQL_ID

   WHERE a.inst_id = b.inst_id

   and    a.status = 'ACTIVE' AND a.TYPE = 'USER' AND a.username IS NOT NULL 

ORDER BY sql_exec_start ASC

Query2:

SELECT count(*)

    FROM gv$session a INNER JOIN  gv$sqlarea b on a.sql_address=b.address

    where a.inst_id = b.inst_id

   and a.status = 'ACTIVE' AND a.TYPE = 'USER' AND a.username IS NOT NULL 

ORDER BY sql_exec_start ASC

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 29 2016
Added on Sep 29 2016
10 comments
2,614 views