Using Left and CharIndex in Oracle


Well i was given the task to get the email id’s of the user which was stored in one of our oracle db table.

But the problem was that we wanted that part of emailid which  appears before ‘@’ .

Well coming from SQL Server background i thought it could be acheived using CharIndex and Left Function.

Let’s see what they do

Select Left(‘abcdef’,3)

-> abc

and

select charindex(‘c’,’abcde’)

-> 3

But than as expected there were no functions like charindex and left in Oracle.

After searching i finally managed to found the solution

Inplace of CharIndex we have instr function

select instr(‘ab’,’b’) from dual;

->2

and for left and also right we have

SUBSTR (`ABCDEF’,-5); //Right(..)

SUBSTR (`ABCDEF’,1,5); // Left(…

So finally the query was

substr(emailid,1,Instr(Emailid,’@’)-1)

-1 is used otherwise @ will also come along

And one more thing, to extract username portion from login name i.e  nishantr1 from

abccompany\nishantr1 we could write something as following

SUBSTRING(loginname ,charindex(‘\’,loginname)+1, len(loginname)) for sql server.


Bye

Advertisements

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

20 thoughts on “Using Left and CharIndex in Oracle”

  1. Having read this I believed it was extremely informative.
    I appreciate you spending some time and energy to put this informative article together.
    I once again find myself spending a lot of time both reading and
    leaving comments. But so what, it was still worthwhile!

    Like

  2. Greetings, I do think your website might be having browser compatibility problems.

    Whenever I look at your website in Safari, it looks fine however, if opening in Internet Explorer, it’s got some overlapping issues.
    I simply wanted to provide you with a quick heads up!
    Aside from that, wonderful blog!

    Like

  3. I hope that you’ve discovered this short Adiphene evaluation helpful and I wish you well in your weight reduction efforts.
    The issues that come with using Adiphene make it one of
    the most essential supplements that anyone can use for weight loss purposes.
    In order to energize yourself and improve your
    outlook you will have to change your diet and get moving.

    Like

  4. And the Google Content Network can pull up many advertising targeting techniques notwithstanding the fact that you have a massive inventory of
    text and image ads spread across the many websites on the internet.

    Roll forward a few years and the advent of online
    collaboration technologies has led to a different style of collaboration, one which
    opens up to a wiki approach where contributions are welcomed and encouraged from
    all parties. Perhaps it’s better not be using these social networks, they say
    they keep people connected, but only in a virtual world,
    it probably prevents a lot of people from going outside and really connecting.

    Like

  5. Lets begin with stating among the information about this excellent revolutionary weight-reduction plan capsule and
    metabolism price booster. Perhaps the main reason behind this though is that you have developed a dependence on food.
    The science behind Adiphene consists of 12 of probably
    the most power fat preventing ingredients known.

    Like

  6. you’re in point of fact a excellent webmaster. The site
    loading pace is incredible. It kind of feels that you’re doing any
    unique trick. Also, The contents are masterwork. you
    have performed a excellent activity in this matter!

    Like

  7. Hey this is kinda of off topic but I was wondering if
    blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding expertise so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!

    Like

  8. to get employee name start with ‘a’ without using “Like” operator.
    IN ORACLE SQL ONLY NOT SQL SERVER….
    CHARINDEX IS NOT ALLOWED IN SQL IT SEEMS IN 10G VERSION…

    PLEASE DO U HAVE ANOTHER OPTION…

    Like

  9. You are coals of severe winter, the summer heat is in the shade, is sprinkled turbulence in the sea fog stepping-stones wonder of the world.If I can fly in the sky, it is you give me a pair of wings; If I can sail in the sea, is that you gave me frolic in force; If I am not quenched torch, is that you gave me the youth light!,plz visit my websites:youth nfl jerseys

    Like

  10. Your articles – confused in my life the way that you lit one of our brightest lights; your article – in my thorny way of life that you shown us the way forward. You are like a red candle, though small and weak, but you have a sub-thermal, send a splitting, we finally lit up, burning his own. You can go to my site exchange with:youth nfl jerseys

    Like

Please share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.