Parse domain from a URL
I'm trying to find out if anybody has written a function that will parse just the domain name from a URL. For example, where the URL =
the function would then return:
Am I crazy, or has somebody written this before? If so, is there some code that I can leverage in finding a solution? Thanks in advance.....
Break out the book on SQL functions and read about instr and substr.
Give it a try on your own first, and tackle it in bits and pieces. Use "select (your use of instr and substr) from dual."
That's what I was looking for! So simple, I looked right over it:
substr(URL , 0, (instr(URL , '/', 1)-1))
Thanks for the inspiration! As a side note, this little application of these functions isn't anywhere on the internet! Somebody might want to pick this up & post it where it can be found again.....
Of course, you'll be wanting to test that before using it.
1 select substr('http://tahiti.oracle.com', 0,
2 (instr('http://tahiti.oracle.com' , '/', 1)-1))
3* from dual
Sorry - forgot to mention that the data feed I'm using this for strips out the 'http://' part of the URL. However, it's a simple fix even if they didn't:
Select substr('http://tahiti.oracle.com/' , 0,
(instr('http://tahiti.oracle.com/' , '/', 1, 3)-1))
Remember that http://tahiti.oracle.com is actually http://tahiti.oracle.com/ when it's fed out as a URL.
Didn't you say you only wanted the "tahiti.oracle.com" (or the original yahoo one) part of the URL?
SQL> Select substr('http://tahiti.oracle.com/' , 0,
2 (instr('http://tahiti.oracle.com/' , '/', 1, 3)-1))
3 from dual
Yes, that is what I said. But given that the data provider already strips the 'http://' portion of the URL, the first option that I came up with works.
However, if that wasn't the case, I could still get to that result through this piece:
Select substr(substr('http://tahiti.oracle.com/' , 0,
(instr('http://tahiti.oracle.com/' , '/', 1, 3)-1)), 8) from dual
Regardless, I'm not terribly concerned with the prefix, so long as I can get rid of any extensions off of the original domain name.
Click Here to Expand Forum to Full Width