Решение PL / SQL
Это будет работать, только немного сдвинув, когда печатать стрелки / переводы строк:
set serveroutput on
declare
cursor ch is
select 1 as n from dual union
select 2 from dual union
select 3 from dual union
select 4 from dual;
v_ch ch%rowtype;
first boolean := true;
begin
open ch;
loop
fetch ch into v_ch;
exit when ch%notfound;
-- Append the arrow after all rows except the first and implicitly (because of the
-- above exit) except the last, too
if not first then
dbms_output.put_line('->');
end if;
first := false;
-- Use put here, instead of put_line, such that the arrow will be appended on the
-- same line as the value on the next loop iteration
dbms_output.put(LPAD(' ',5)||v_ch.n);
end loop;
-- Finally, print a newline character
dbms_output.put_line('');
close ch;
end;
/
Решение SQL
КонечноВы можете сгенерировать стрелку также в SQL:
set serveroutput on
declare
cursor ch is
select n, case
when row_number() over (order by n) =
count(*) over () then '' else '->' end arrow
from (
select 1 as n from dual union
select 2 from dual union
select 3 from dual union
select 4 from dual
) t;
v_ch ch%rowtype;
begin
open ch;
loop
fetch ch into v_ch;
exit when ch%notfound;
dbms_output.put_line(LPAD(' ',5)||v_ch.n||v_ch.arrow);
end loop;
dbms_output.put_line('');
close ch;
end;
/
Или даже:
select listagg(n, '->' || chr(10)) within group (order by n)
from (
select 1 as n from dual union
select 2 from dual union
select 3 from dual union
select 4 from dual
);
Это работает, только если ваша строка не достигнет ограничения длины VARCHAR2