2009-07-08 40 views
0

我設計的HTML報告,有效地提取列從一個表預言:配置列的輸出報告

列在此表中的數字是相當大的,我想一些辦法有效的方法配置應用程序以說明要顯示的列。注意:這不是每個用戶的設置。

可以說我有主表:

MAIN_TABLE 
id 
first_name 
last_name 
weight 
height 
attribute_4 
attribute_5 
attribute_6 
... 
attribute_99 

我在想一個表像

MAIN_TABLE_DISPLAY 
column_name 
display 

或許

MAIN_TABLE_DISPLAY 
display_id 
display_first_name 
display_last_name 
display_weight 
display_height 
display_attribute_4 
display_attribute_5 
display_attribute_6 
... 
display_attribute_99 

但我想執行有效加入。

有什麼建議嗎?

謝謝。

回答

0

您是否想過使用視圖?您的應用程序可以從中提取數據,並更改顯示的列,更改視圖。你將不得不改變事物的表現方面來考慮不同的列。

+0

我想一個視圖不會做太多你,因爲你仍然必須調整演示文稿的一面。你使用什麼語言/報告工具? – 2009-07-08 20:35:30

0

正如jva所說,您需要使用動態SQL。像這樣的東西(與適當的錯誤修復)應該這樣做:

type column_table is table of varchar2(30); 

function table_as_html(table_name varchar2, columns column_table) return clob is 
    sql_query varchar2(32767); 
    sql_cursor sql_refcursor; 
    html_row clob; 
    html_text clob; 
begin 
    sql_query := 'select ''<tr>'; 
    for column in 1 .. columns.count loop 
    sql_query := sql_query||'||''<td>''||'||columns(column)||'||''</td>''' 
    end loop; 
    sql_query := sql_query||'||''</tr>'' from '||table_name; 

    open sql_cursor for sql_query; 
    loop 
    fetch sql_cursor into html_row; 
    exit when sql_cursor%notfound; 

    html_text := html_text||html_row||chr(10); 
    end loop; 
    close sql_cursor; 

    return html_text; 
end;