declare
v_sql varchar2(4000);
begin
for i in (select level a from dual connect by level<=4) loop
v_sql := v_sql||'sum(decode('||i.a||','||i.a||',''a'')), ';
dbms_output.put_line(v_sql);
end loop;
end;
打印出来的结果
sum(decode(1,1,'a')),
sum(decode(1,1,'a')), sum(decode(2,2,'a')),
sum(decode(1,1,'a')), sum(decode(2,2,'a')), sum(decode(3,3,'a')),
sum(decode(1,1,'a')), sum(decode(2,2,'a')), sum(decode(3,3,'a')), sum(decode(4,4,'a')),
怎么实现只显示最下面一个
--发现打印写在循环里了
把打印拿出来,加上rtrim去掉最后一个逗号
declare
v_sql varchar2(4000);
begin
for i in (select level a from dual connect by level<=4) loop
v_sql := v_sql||'sum(decode('||i.a||','||i.a||',''a'')),';
end loop;
v_sql := rtrim(v_sql,',');
dbms_output.put_line(v_sql);
end;
v_sql varchar2(4000);
begin
for i in (select level a from dual connect by level<=4) loop
v_sql := v_sql||'sum(decode('||i.a||','||i.a||',''a'')), ';
dbms_output.put_line(v_sql);
end loop;
end;
打印出来的结果
sum(decode(1,1,'a')),
sum(decode(1,1,'a')), sum(decode(2,2,'a')),
sum(decode(1,1,'a')), sum(decode(2,2,'a')), sum(decode(3,3,'a')),
sum(decode(1,1,'a')), sum(decode(2,2,'a')), sum(decode(3,3,'a')), sum(decode(4,4,'a')),
怎么实现只显示最下面一个
--发现打印写在循环里了
把打印拿出来,加上rtrim去掉最后一个逗号
declare
v_sql varchar2(4000);
begin
for i in (select level a from dual connect by level<=4) loop
v_sql := v_sql||'sum(decode('||i.a||','||i.a||',''a'')),';
end loop;
v_sql := rtrim(v_sql,',');
dbms_output.put_line(v_sql);
end;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26477854/viewspace-1071670/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26477854/viewspace-1071670/