Home » SQL & PL/SQL » SQL & PL/SQL » count, characters from string
count, characters from string [message #215780] Tue, 23 January 2007 21:53 Go to next message
ashish_pass1
Messages: 114
Registered: August 2006
Location: delhi
Senior Member
hello all

i want to count no. of characters from string .
suppose i enter 'ashish'.
then counter count
 
    count          character
    -------       ----------
     1               a
     2               s
     2               h
     1               i
     2               s
     2               h

also i need to remove the duplication i.e-
  
       2            s
       2            s
       2            h
       2            h

i dnt want repetition.

i did a query -
declare
 v_str varchar2(1000);
  v_chr varchar2:='a'
   v_cnt number:=0;
begin
 v_str:='&name';
  for i in 1..length(v_str)
   loop
    if v_chr=substr(v_str, i, 1) then
      v_cnt:=v_cnt+1;
    end if;
   end loop;
 dbms_output.put_line('No of:'||v_chr||':'||v_cnt);
end;
/


enter value for name: ashish
no of: a:1

but i want, if i enter a string then it will count character of each without repetion.

please help me out by this puzzle, also please mentioned the comment so that it will help me to understand.

with regards
ashish

[Updated on: Tue, 23 January 2007 21:54]

Report message to a moderator

Re: count, characters from string [message #215870 is a reply to message #215780] Wed, 24 January 2007 02:28 Go to previous messageGo to next message
rameshuddaraju
Messages: 69
Registered: June 2005
Location: India
Member

See the following code for your requirement


declare
 v_str varchar2(1000) := '&name';
 v_chr varchar2(1);
 v_cnt number:=0;
begin
    for i in 1..length(v_str) loop
          v_chr := substr(v_str,i,1);
          v_cnt := 0;
      for j in 1..length(v_str) loop
          if v_chr = substr(v_str, j, 1) then
              v_cnt:=v_cnt+1;
          end if;  
      end loop;
      if instr ( substr(v_str,1,i-1),v_chr) = 0 or i = 1 then
          dbms_output.put_line('No of:'||v_chr||':'||v_cnt);
      end if; 
    end loop;
end;


Re: count, characters from string [message #215890 is a reply to message #215870] Wed, 24 January 2007 03:25 Go to previous message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
Search the board.

http://www.orafaq.com/forum/fa/448/0/

I'm sure you'll find more examples as you go.

MHE

[Updated on: Wed, 24 January 2007 03:26]

Report message to a moderator

Previous Topic: can any one help in this it is very urgent..
Next Topic: how delete last 10 records from the table
Goto Forum:
  


Current Time: Fri Dec 09 09:41:22 CST 2016

Total time taken to generate the page: 0.09125 seconds