-
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 =
www.yahoo.com/Computers_and_Internet/
the function would then return:
www.yahoo.com
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.....
- Eric
-
Break out the book on SQL functions and read about instr and substr.
http://download-west.oracle.com/docs...s55a.htm#77600
http://download-west.oracle.com/docs...119a.htm#87068
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.....
- Eric
-
Of course, you'll be wanting to test that before using it.
Code:
1 select substr('http://tahiti.oracle.com', 0,
2 (instr('http://tahiti.oracle.com' , '/', 1)-1))
3* from dual
SQL> /
SUBST
-----
http:
-
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))
from dual
Remember that http://tahiti.oracle.com is actually http://tahiti.oracle.com/ when it's fed out as a URL.
- Eric
-
Code:
SQL> Select substr('http://tahiti.oracle.com/' , 0,
2 (instr('http://tahiti.oracle.com/' , '/', 1, 3)-1))
3 from dual
4 /
SUBSTR('HTTP://TAHITI.OR
------------------------
http://tahiti.oracle.com
Didn't you say you only wanted the "tahiti.oracle.com" (or the original yahoo one) part of the URL?
-
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
SUBSTR(SUBSTR('HTTP://TAHITI.O
tahiti.oracle.com
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.
- Eric
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|