Within a PL/SQL procedure, wrap a query or refcursor in HTML table

后端 未结 2 789
甜味超标
甜味超标 2021-01-05 22:20

It seems really easy if you are using SQL*Plus to use

SQL> set markup html on;

and get some lovely results to the SQL*Plus window. we

2条回答
  •  春和景丽
    2021-01-05 23:08

    One option is to use hypertext functions HTF:

    set define off
    
    create table so14t (id number, data varchar2(25));
    
    insert all
    into so14t values(101, 'one hundred & one')
    into so14t values(202, 'two hundred & two')
    into so14t values(303, 'three hundred & three')
    select 1 from dual;
    
    declare
      v_html varchar2(32767);
    begin
      v_html := htf.tableopen;
    
      for i in (select * from so14t) loop
        v_html := v_html || htf.tablerowopen;
        v_html := v_html || htf.tabledata(i.id);
        v_html := v_html || htf.tabledata(htf.escape_sc(i.data));
        v_html := v_html || htf.tablerowclose;
      end loop;
    
      v_html := v_html || htf.tableclose;
    
      dbms_output.put_line(v_html);
    end;
    /
    

    Prints (formatted for readability):

    101one hundred & one
    202two hundred & two
    303three hundred & three

提交回复
热议问题