Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.51 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to concatenate strings?
  2. select id, wm_concat(paragraph) from paragraphs group by id
  3.        
  4. SQL> set serveroutput on
  5. SQL>
  6. SQL> create table tmp_test ( a varchar2(30) );
  7.  
  8. Table created.
  9.  
  10. SQL> insert into tmp_test
  11.   2   select object_name
  12.   3     from all_objects
  13.   4          ;
  14.  
  15. 81219 rows created.
  16.  
  17. SQL>  commit ;
  18.  
  19. Commit complete.
  20.  
  21. SQL>
  22. SQL> declare
  23.   2
  24.   3    i integer := 1;
  25.   4    k number(10);
  26.   5    v_stragg varchar2(32767);
  27.   6    v_test varchar2(32767) := '';
  28.   7    start_time timestamp;
  29.   8
  30.   9  begin
  31.  10
  32.  11    select count(*)
  33.  12      into k
  34.  13      from tmp_test;
  35.  14
  36.  15    for i in 1 .. k loop
  37.  16      start_time := systimestamp;
  38.  17      begin
  39.  18
  40.  19        select wm_concat(a) into v_test
  41.  20          from tmp_test
  42.  21         where rownum < i;
  43.  22
  44.  23      exception when others then
  45.  24        dbms_output.put_line('wm_concat: ' || length(v_test));
  46.  25        dbms_output.put_line(systimestamp - start_time);
  47.  26        exit;
  48.  27     end;
  49.  28    end loop;
  50.  29
  51.  30    for i in 1 .. k loop
  52.  31      start_time := systimestamp;
  53.  32
  54.  33      select stragg(a) into v_test
  55.  34        from tmp_test
  56.  35       where rownum < i;
  57.  36
  58.  37      if v_test = 'OVERFLOW' then
  59.  38        dbms_output.put_line('stragg: ' || length(v_stragg));
  60.  39        dbms_output.put_line(systimestamp - start_time);
  61.  40        exit;
  62.  41      else v_stragg := v_test;
  63.  42      end if;
  64.  43    end loop;
  65.  44  end;
  66.  45  /
  67. wm_concat: 3976
  68. +000000000 00:00:00.005886000
  69. stragg: 3976
  70. +000000000 00:00:00.005707000
  71.  
  72. PL/SQL procedure successfully completed.