Monday, January 7, 2013

Character count from the string



CREATE OR REPLACE PROCEDURE AKURCHANIA.QA_STRING_LENGTH(char_str_cnt varchar2) IS  -- input parameter so you can enter any string or sentence
str1 varchar2(100);
str2 varchar2(100);
len NUMBER(10);
c CHAR(1);
cnt NUMBER;
/******************************************************************************
   NAME:       String
   PURPOSE:   

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        1/7/2013   akurchania       1. Created this procedure.

   NOTES:

   Automatically available Auto Replace Keywords:
      Object Name:     String
      Sysdate:         1/7/2013
      Date and Time:   1/7/2013, 12:52:53 PM, and 1/7/2013 12:52:53 PM
      Username:        akurchania (set in TOAD Options, Procedure Editor)
      Table Name:       (set in the "New PL/SQL Object" dialog)

******************************************************************************/
BEGIN

str1 := char_str_cnt;
str1 := upper(str1);
Len := length(str1);

WHILE len > 0 LOOP
  c := SUBSTR(str1, 1, 1);
  str2 := REPLACE(str1, c, NULL);
  cnt := LENGTH(str1) - NVL(LENGTH(str2),0);
  IF cnt > 0 AND c <> ' ' THEN
     dbms_output.put_line(c ||' '|| cnt);
  END IF;
  len := LENGTH(str2);
  str1 := str2;
END LOOP;

END QA_STRING_LENGTH;