Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 11th, 2006, 10:00 PM
scryptKiddy scryptKiddy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Location: Hawaii
Posts: 277 scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 7 h 46 m 11 sec
Reputation Power: 11
Send a message via Yahoo to scryptKiddy
Selecting ip address octets

Hello,

I have a table with ip address stored as varchar2(20) and
I would like to select the "first two octets" of the string.

So for 1.12.2.3 and 200.245.223.223 I want the select to return

1.12.
and
200.245.

I have tried instr and substr combos, but not getting what I want...

help

SK

Reply With Quote
  #2  
Old May 12th, 2006, 02:23 PM
scryptKiddy scryptKiddy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Location: Hawaii
Posts: 277 scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 7 h 46 m 11 sec
Reputation Power: 11
Send a message via Yahoo to scryptKiddy
Still need assistance

Still no dice, I have not found the method to do this, anyone else?

Reply With Quote
  #3  
Old May 12th, 2006, 03:35 PM
scryptKiddy scryptKiddy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Location: Hawaii
Posts: 277 scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level)scryptKiddy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 7 h 46 m 11 sec
Reputation Power: 11
Send a message via Yahoo to scryptKiddy
Talking

Finally found someone who needed same thing, give him credit for it.



SQL Code:
Original - SQL Code
  1. CREATE OR REPLACE FUNCTION getClassB (ip IN VARCHAR2 DEFAULT NULL) RETURN varchar2
  2.  
  3.  
  4. /*
  5.   Author:Jonathon Wright
  6.   Version: (Release) 1.0.0
  7.   Notes: Takes in a VARCHAR IP, returns class B String
  8.     Would be same as "anding" the ip with 255.255.0.0
  9.    
  10.     LEAVE THIS IN HEADER. FOR QUESTIONS: jonathon.wright@us.army.mil
  11. */
  12. IS
  13.  
  14. posA NUMBER; --position in string to end of first octet
  15. posB NUMBER; --position in string to end of second octet
  16. first_octet  VARCHAR2(3);
  17. second_octet VARCHAR2(3);
  18. classB  VARCHAR2(20);
  19.  
  20.  
  21. BEGIN
  22.  
  23. --get position to first period
  24. SELECT instr(ip,'.') INTO posA FROM dual;
  25.  
  26. --get first octet
  27. SELECT substr(ip, 1, posA - 1) INTO first_octet FROM dual;
  28.  
  29. --get position to 2nd period
  30. SELECT instr(substr(ip, posA + 1),'.') INTO posB FROM dual;
  31.  
  32. --get 2nd octet
  33. SELECT substr(ip,posA + 1, posB - 1) INTO second_octet FROM dual;
  34.  
  35. --return classB
  36. classB := first_octet || '.' || second_octet || '.0.0';
  37.  
  38. RETURN classB;
  39.  
  40. exception WHEN others THEN
  41. dbms_output.put_line('SQLERR:'|| SQLCODE || '-' || SQLERRM);
  42.  
  43. END getClassB;
  44. /
Comments on this post
pabloj agrees: Thank you for posting the solution

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Selecting ip address octets


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT