Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
--select statement passed in as v_select
FUNCTION flatten_SQL(v_select varchar2) return varchar2
IS
cur_pos number;
from_pos number;
strlen number;
select_clause varchar2(2000);
remaining_sql varchar2(2000);
new_sql varchar2(4000);
cur_char varchar2(10);
depth number := 0;
BEGIN
from_pos := instr(v_select,' FROM ');
select_clause := substr(v_select, 1, from_pos-1);
remaining_sql := substr(v_select, from_pos, length(v_select) - from_pos +1);
for cur_pos in 1 .. length(select_clause)
LOOP
cur_char := substr(select_clause, cur_pos, 1);
if cur_char = '('
THEN
depth := depth + 1;
end if;
if cur_char = ')'
then
depth := depth - 1;
end if;
if depth = 0 then
if cur_char = ','
then
cur_char := '||'',''||';
end if;
end if;
new_sql := new_sql || cur_char;
END LOOP;
--complete SQL statement
return new_sql || remaining_sql;
END;