Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 26th, 2006, 05:12 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to itsurshailesh
Default Count character value using Stored Procedure

HI all,
I want to write stored procedure that will work.
I will provide character string to the stored procedure and stored proc should written me the value of each character.
Like.... the character string is "shelly" - so if i want the value of 's' in provided string it should give me 19(the position of 's' in between A-Z)
Any Ideas...u have ...do share with me!

Regards,
Mandy
 
Old November 14th, 2006, 01:31 AM
Registered User
 
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi mandy,

following is the stored procedure code for your task and it really works,

here cval is the character you want to search and sval is the string
that you want to compare. just execute the procedure and pass
the above two parameters to get output.


create or replace procedure charval(cval in char,sval in varchar2)
as
pos number;
begin
    if (instr(sval,cval) > 0) then
    begin
    pos:=ascii(cval);
    if(pos>=65 and pos<=91) then
      pos:=pos-64;
    else
          if(pos>=97 and pos<=123) then
             pos:=pos-96;
          end if;
    end if;
   end;
   end if;
   dbms_output.put_line('value of character is'||pos);
 end;
/


do write if you don't understand the logic behind the procedure






Similar Threads
Thread Thread Starter Forum Replies Last Post
count occurrence of a character in a string surya Javascript How-To 6 May 7th, 2012 04:23 PM
Count all occurences of a character in a string thomaz C# 2 February 9th, 2007 01:52 PM
JSP: Count character in text file life4fun7 JSP Basics 1 June 7th, 2006 09:55 AM
character count of ms-word in asp.net sh.rajkumar ASP.NET 1.0 and 1.1 Professional 0 May 19th, 2006 07:24 AM
Problems returning count in Stored Procedure planza SQL Language 1 December 21st, 2005 03:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.