How to Get Your SID? USERENV vs V$MYSTAT!

Hello everyone,

This is an easy question. How to find your own session SID and when you ask Google for it, you will find many answers. While reading some documents, I realized that some Gurus are using V$MYSTAT to get current SID:

I always prefer USERENV(‘SID’) context to get SID and curious about which one is faster and consume less cpu resources. So I created this sample code:

as you see, USERENV(‘SID’) is much faster and consume less cpu resource than v$mystat method. so I will keep using it and suggest you do the same.

6 thoughts on “How to Get Your SID? USERENV vs V$MYSTAT!

  1. Gaz

    Hey Mustafa,

    A point about “USERENV()” is that it is a legacy functioned maintained only for backward compatibility.
    The interesting thing is, the userenv() function is also quicker than the preferred “sys_context(‘userenv’, ‘sid)”.

    • Mustafa

      Hi Gaz, it’s nice to see you šŸ™‚ I realized that while I was testing this code but didn’t add my findings to my post and actually sys_context is not slower but giving lowercase parameter values to sys_context cause that slowness šŸ™‚ just make your test with SYS_CONTEXT(‘USERENV’, ‘SID’) almost has the same performance with userenv. so maybe we should have a rule about case sensitivity while passing parameters.

      • Gaz

        … userenv() still comes out on top speed and cpu wise.
        Btw really liking the refreshingly dark colour scheme of your site.


        • Mustafa

          Thanks mate, all of us will suffer from our eyes so I use dark theme on everything šŸ™‚

  2. Amit

    The way of subscribing is ugly.

    • Mustafa

      Hi Amit,

      you might be right. I am literally just an oracle guy and don’t like web stuff šŸ™‚ I ask for a friend to look into it.

Leave a Reply

Your email address will not be published. Required fields are marked *