如何在Dbms_output.put_line('')中使用<br/>标签;在PL / SQL Oracle?

时间:2015-09-18 13:08:23

标签: sql oracle plsql procedure

我有一个我在一个应用程序中使用的查询,我很难在PL / SQL中使用
标签。查询是:

SELECT LISTAGG(last_name, 'br') WITHIN group (ORDER BY last_name) 
into lastname from employees;

DBMS_OUTPUT.PUT_LINE(lastname);

我得到的输出是:Abel br Ande br Baer br

我想要的输出:
亚伯·安德 贝尔

1 个答案:

答案 0 :(得分:2)

“br”在Oracle中没有特殊含义,我知道,使用CHR(10)(即回车)。 (或者如果在Windows中工作,则为CHR(10)+ CHR(13))

    1  with w_data as ( select level id from dual connect by level <= 10 )
    2  select listagg ( id, chr(10) ) within group (order by id )
    3*   from w_data
  SQL> /

  LISTAGG(ID,CHR(10))WITHINGROUP(ORDERBYID)
  --------------------------------------------------------------------------------
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10


  1 row selected.

注意它是如何显示“选择1行”的,但事情被分成了单独的行......我相信这是你所追求的效果?

[编辑]抱歉,刚刚意识到你在pl / sql ..这里是pl / sql中相同的测试查询,通过dbms_output ...:

  declare
     lv_str   varchar2(4000);
  begin

  with w_data as ( select level id from dual connect by level <= 10 )
  select listagg ( id, chr(10) ) within group (order by id )
    into lv_str
    from w_data;

  dbms_output.put_line ( lv_str );
  end;
  /

  "gg.sql" 15 lines, 259 characters

  SQL> @gg
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10

  PL/SQL procedure successfully completed.