Re: PL/SQL Help

From: Ken Denny <ken_at_kendenny.com>
Date: Sat, 09 Mar 2002 01:05:52 GMT
Message-ID: <Xns91CBCEBBC73D9kendenny_at_65.82.44.7>


"MA_IL" <aramraj1_at_yahoo.com> wrote in news:PDai8.2311$702.9034_at_sccrnsc02:

> Hi All
> 

>: How to convert a string example "MyTable" to "MY_TABLE"?
 

>: The program should identify the capital letter in the string and
>: prefix it with an "_" (underscrore) and also capitalize others.
 

>: I really appreciate your help
 

>: RamRaj

Create or replace
function convert_string(inp_string varchar2) return varchar2 is

    result varchar2(32000);
    prev_i integer :=1;
begin

    for i in 2..length(inp_string)
    loop

        if substr(inp_string,i,1) between 'A' and 'Z'
        then
            result := result || 
                upper(substr(inp_string,prev_i,i-prev_i)) || '_';
            prev_i := i;
        end if;

    end loop;
    result := result || upper(substr(inp_string,prev_i)); end;
-- 
Ken Denny
http://www.kendenny.com/

Q: How many programmers does it take to change a light bulb? A: None, it's 
a hardware problem.
Received on Sat Mar 09 2002 - 02:05:52 CET

Original text of this message