Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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 October 14th, 2003, 05:03 PM
fingereleven fingereleven is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 13 fingereleven User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
how to count number of times a certain string appears in one field?

I'm building a basic search engine for a website and all of our content is stored in an Oracle Database. The content of each page in the site is stored in 1 field in a table ie. we do not have a column page_title, page_links, page_content. Rather all html for any one page is all in one field.

My problem is in ranking each page based on the number of times a certain string appears in the html for a page.

I don't think the count function helps me here as it will only count if a string appears in a field, it will not count how many times a string appears in one field.

Anyone have any ideas?

Sorry if I'm not clear, I'm a little tired

Reply With Quote
  #2  
Old October 14th, 2003, 10:48 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,913 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 24 m 34 sec
Reputation Power: 1018
interesting challenge

here's my idea, i'll leave it to you to implement (i don't have oracle to test on)

use the REPLACE function to replace every occurrence of the string with null

this effectively removes the string from the field

use the LENGTH function to get the length of the string, and also of the field, both before and after the string has been removed

do the math and presto, the number of times the string occurred in the field

beats looping in a scripting language, eh?

rudy
http://r937.com/

Last edited by r937 : October 14th, 2003 at 10:51 PM.

Reply With Quote
  #3  
Old October 14th, 2003, 10:48 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 23 h 15 m 53 sec
Reputation Power: 19
I can't think of a way to do that with simple sql.

I think you'd have to write your own function, it should be pretty trivial to do so but I'm not sure how fast it would be.

Reply With Quote
  #4  
Old October 14th, 2003, 10:52 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 23 h 15 m 53 sec
Reputation Power: 19
Quote:
Originally posted by r937
interesting challenge

here's my idea, i'll leave it to you to implement (i don't have oracle to test on)

use the REPLACE function to replace every occurrence of the string with null

this effectively removes the string from the field

use the LENGTH function to get the length of the string, and also of the field, both before and after the string has been removed

do the match and presto, the number of times the string occurred in the field

beats looping in a scripting language, eh?

rudy
http://r937.com/


Wow, that's a creative solution.

I was thinking of using instr with a count and keep searching with the instring pointer after where I found it but I think your solution would be faster, and easier to code.

Reply With Quote
  #5  
Old October 14th, 2003, 11:01 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,913 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 24 m 34 sec
Reputation Power: 1018
yes, something like
Code:
select (
       length(field) 
     - length(replace(field,string))
       )
     / length(string)  as  numberoftimes
  from tablename
except i can't test it because i don't have oracle (i just use their SQL Reference manual on the web)

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > how to count number of times a certain string appears in one field?


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 6 hosted by Hostway
Stay green...Green IT