-- UDTF to return a camelcase of a string for column naming purposes
-- Simply paste this gist into ACS SQL and run it to create the UDTF.
-- Note: I am using library QUSRSYS. I suggest you put it into your own tool library
-- It is a cool example how far you can go with SQL: Have fun -
-- (C) Niels Liisberg 2021
-- This gist is distributed on an "as is" basis, without warranties
-- or conditions of any kind, either express or implied.
----------------------------------------------------------------------------------------------
create or replace function qusrsys.camel_case (
name varchar(128)
)
returns varchar(128)
no external action
set option output=*print, commit=*none, dbgview = *list
begin
declare temp varchar(128);
declare outString varchar(128);
declare i int;
declare upperNext int;
declare c char(1);
-- First snake-case the name to sanitise it AND it will also works if the string is already snake-case
set temp = lower(name);
set temp = regexp_replace(temp , '[æ]' , 'ae');
set temp = regexp_replace(temp , '[ø@]' , 'oe');
set temp = regexp_replace(temp , '[å]' , 'aa');
set temp = regexp_replace(temp , '[^a-z0-9]' , ' ');
set temp = trim(temp); -- Done here if the name has trailing invalid chars
set temp = regexp_replace(temp , ' +', '_');
-- Columns names can not begin with a digit
if substring(temp , 1 , 1) >= '0' then
set temp = 'x' concat temp;
end if;
set i = 1;
set upperNext = 0;
set outString = '';
while i <= length(temp) do
set c = substr(temp , i ,1);
if c = '_' then
set upperNext = 1;
elseif upperNext = 1 then
set outString = outString || upper(c);
set upperNext = 0;
else
set outString = outString || c;
end if;
set i = i +1;
end while;
return outString;
end;
DISCLAIMER. Before opening any attachments, check them for viruses and defects. This email and its attachments may contain confidential information. If you are not the intended recipient, please do not read, distribute or copy this email or its attachments but notify sender and delete it. Any views expressed in this email are those of the individual sender
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.