CREAR CURSOR A STRING O VARCHAR
create or replace function join
(
p_cursor sys_refcursor,
p_del varchar2 := ','
) return varchar2
is
l_value varchar2(32767);
l_result varchar2(32767);
begin
loop
fetch p_cursor into l_value;
exit when p_cursor%notfound;
if l_result is not null then
l_result := l_result || p_del;
end if;
l_result := l_result || l_value;
end loop;
return l_result;
end join;
select join(cursor(SELECT 'A' AS LETRA FROM DUAL UNION SELECT 'B' AS LETRA FROM DUAL),'-') from dual;
A-B
- Crear Función
create or replace function join
(
p_cursor sys_refcursor,
p_del varchar2 := ','
) return varchar2
is
l_value varchar2(32767);
l_result varchar2(32767);
begin
loop
fetch p_cursor into l_value;
exit when p_cursor%notfound;
if l_result is not null then
l_result := l_result || p_del;
end if;
l_result := l_result || l_value;
end loop;
return l_result;
end join;
- Prueba
select join(cursor(SELECT 'A' AS LETRA FROM DUAL UNION SELECT 'B' AS LETRA FROM DUAL),'-') from dual;
- Resultado 2
A-B
Comentarios
Publicar un comentario