Home » SQL & PL/SQL » SQL & PL/SQL » Count characters (9.0.4.0)
Count characters [message #323005] Tue, 27 May 2008 01:00 Go to next message
user71408
Messages: 585
Registered: November 2007
Location: NE
Senior Member

query to find no. of given characters in a string.

eg. ename : KRISTOFER

to find no. of "R" 's in the given string...

Thank you

[mod-edit]Adjusted title

[Updated on: Tue, 27 May 2008 01:44] by Moderator

Report message to a moderator

Re: query [message #323008 is a reply to message #323005] Tue, 27 May 2008 01:08 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
250 posts and you still don't know the policy of this forum?
Show us what YOU tried.
Furthermore, this is answered at least once a month, so you should be able to find it if you did a proper search.
Re: query [message #323014 is a reply to message #323008] Tue, 27 May 2008 01:32 Go to previous messageGo to next message
user71408
Messages: 585
Registered: November 2007
Location: NE
Senior Member

select length('KROSTOPHER') from dual
minus
select length(trim('R' from 'KRISTOPHER')) from dual;

am getting
O/p as "10"

[Updated on: Tue, 27 May 2008 01:33]

Report message to a moderator

Re: query [message #323015 is a reply to message #323014] Tue, 27 May 2008 01:39 Go to previous messageGo to next message
Michel Cadot
Messages: 64119
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I think you shoould think about reading SQL Reference.

MINUS is a set operator.
Minus operator for numbers is -.

Trim just remove outer characters. Choose another function.

Regards
Michel
Re: query [message #323019 is a reply to message #323015] Tue, 27 May 2008 01:46 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
One link
other options

MHE
Re: query [message #323020 is a reply to message #323015] Tue, 27 May 2008 01:50 Go to previous messageGo to next message
user71408
Messages: 585
Registered: November 2007
Location: NE
Senior Member

Michel ,

Got it.....
select length('kristopher')- length(replace('kristopher','r','')) from dual;



Thank you all
Re: query [message #323074 is a reply to message #323020] Tue, 27 May 2008 04:25 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Note that you now rely on case. Suppose the word starts with an upper R? Do you want to count that as well?
Re: Count characters [message #323088 is a reply to message #323005] Tue, 27 May 2008 04:46 Go to previous message
seyed456
Messages: 220
Registered: May 2008
Location: south india .
Senior Member

hey frank.. .

i hope my following query is correct for your qn. .

select length('kristopher')- length(replace(lower('kRistopher'),'r','')) from dual;
Previous Topic: How to combine rows that meet criteria in SQL
Next Topic: unable to union two tables?
Goto Forum:
  


Current Time: Tue Dec 06 06:37:44 CST 2016

Total time taken to generate the page: 0.10284 seconds