Job Seekers   Employers
dbapool: Authors | Submissions | Contact Us
   Forgot password? | Sign up
  Home   Discussion Forum   Articles   Interview Questions   FAQs   Scripts   Rewards   Analyzer   White Papers   Blog   Certification   Downloads   Tools
 

Topic: SQL*Plus and PL/SQL >> Function To get the number of dots in string variable

Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property. You may review the entire Oracle Certification Program Candidate Agreement online Here.



  


 Title: Function To get the number of dots in string variable
 muzu  Posted: Sep 04, 2007 04:42:57 AM

 Total Post: 37
 Joined: Aug, 2007






 Function To get the number of dots in string variable
--------------------------------------------------------------------------------

Is there any function in SQL to get the number of dots in a string variable.

Suppose
str1 is a varchar2 type variable

str1='adf.hjk.jhh.jhkjh.'

Any function or any method is available in sql to get the number of dots in the string data variable. The result should give the number of dots present i.e it should give 4 as value.

 Mitesh
Posted: Sep 04, 2007 05:19:28 AM  

 Total Post: 6
 Joined: Aug, 2007






 
Hi,

Try this:

declare
-- Local variables here
v_index integer :=0;
v_cnt integer :=0;
str1 varchar2(200) :='adf.hjk.jhh.jhkjh' ;
begin
-- Test statements here
while true loop
v_index := instr( str1,'.',v_index+1);
exit when v_index =0;
v_cnt :=v_cnt+1;
end loop;

dbms_output.put_line('total number of dots ' || v_cnt);
end;

Thanks



 gps
Posted: Sep 04, 2007 11:03:22 PM  

 Total Post: 40
 Joined: May, 2006






 
Hi, try this as well ..

set serveroutput on
declare
str1 varchar2(100);
cnt number;
begin
str1:='agsjd.asd.sf.sdf.rt.fgh.';
cnt:=length(str1)-length(translate(str1,'a.','a'));
dbms_output.put_line('No. of dots = '||cnt);
end;
/



Gurwinder

 bhmadhukar
Posted: Feb 21, 2008 03:04:41 AM  

 Total Post: 14
 Joined: Jan, 2008






 
check 7th page in this forum

>>> How to count number of occurance of a particular character in a string?

SYS>>select occurance('adf.hjk.jhh.jhkjh.','.') from dual;


 Time Zone: EDT

  




Forum Rules & Description


Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user




 








Get FREE Magazines

Top 10 Forum User

  Murtuja Khokhar857
  Mohammed Taj746
  positive fanatic483
  Jayanta Sur479
  Vigyan Kaushik386
  Vinoth Kumar357
  Gopu Gopi340
  Gitesh Trivedi322
  neeraj sharma258
  Ramesh Jois246






oracle Mag



  About Us Advertise Terms of Use Privacy Newsletters Contact Us    

Home   Discussion Forum   FAQs  Articles  Jobs   Newsletters  Directory  Downloads 

Our Premium Sponsor
Confio Software