This is my SQL Server function and I'm trying to convert uppercase to propercase and its works successfully in SQL Server but not in Oracle, could someone help me to convert the below code:
CREATE FUNCTION CamelCase(@Text as VARCHAR(8000))
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @Index INT;
DECLARE @CurChar CHAR(1);
DECLARE @Reset BIT;
DECLARE @Ret VARCHAR(8000);
IF @Text IS NULL
RETURN NULL;
SELECT @Reset = 1,
@Index = 1,
@Ret = '';
WHILE (@Index <= len(@Text))
SELECT @CurChar = substring(@Text, @Index, 1),
@Ret = @Ret + CASE WHEN @Reset = 1 THEN UPPER(@CurChar) ELSE LOWER(@CurChar) END,
@Reset = CASE WHEN @CurChar like '[a-zA-Z]' THEN 0 ELSE 1 END,
@Index = @Index + 1
RETURN @Ret
END
I tried to translate it into Oracle function code which is shown below:
create or replace function CamelCase(Text in VARCHAR2)
RETURN VARCHAR2
IS
Ret VARCHAR2(8000):= '';
Index NUMBER:= 1;
CurChar CHAR0;
Resets BIT := 1;
BEGIN
WHILE (Index <= LENGTH(Text))
loop
CurChar := SUBSTR(Text, Index, 1);
if (Reset = 1) then
ret:= UPPER(CurChar) ;
ELSE
ret:= LOWER(CurChar);
end if ;
if (CurChar like '[a-zA-Z]') then
reset:= 0;
else
reset:= 1;
end if ;
Index := Index + 1;
end loop;
RETURN Ret;
END
But it's seems wrong, can someone help me please for conversion.