I have been banging my head once again on HANA syntax. I have been looking for a method of writing either a function or procedure and calling the function or procedure in a select statement to evaluate a column in a table and alter the column based on an if function.
I have created most of the script but the replace function is not working as expected. I am not too familiar with HANA, so any help would be appreciated. Thanks.
Can someone also let me know how can I call the procedure as this seems a bit more complicated in HANA? I am using HANA sp 10.
I am essentially wanting to run the function or procedure using a select statement and output the result as follows
example of what I am trying to achieve
id | string updated | temp_str from function or procedure |
---|---|---|
1 | 12212 | 12,2,12 |
2 | 21221 | 2,12,2,1 |
3 | 12212 | 12,2,12 |
create procedure update_str
language sqlscript
as
ip_str varchar:= '21222212';
temp_str varchar(100) := ip_str || ',';
pos integer :=1;
begin
while(length(:temp_str) > 0 ) do
if substr(temp_str,1,1) = '1' and substr (temp_str,2,1) = '2' then
update temp_str := replace(temp_str,'12','12,');
pos := :pos + 1;
elseif substr(temp_str,1,1) = '2' and substr (temp_str,2,1) = '1' then
update temp_str := replace(temp_str,'21','2,1');
pos := :pos + 1;
elseif substr(temp_str,1,1) = '2' and substr (temp_str,2,1) = '2' then
update temp_str := replace(temp_str,'22','2,2');
pos := :pos + 1;
else;
end if;
end if;
end if;
end while;
end;