My code:
Declare
l_body CLOB;
l_body := '<html><head><style>tr:last-child {font-weight: bold;}</style></head><body>'
||'<table><tbody>'
|| '<tr>'
|| '<th style="font-weight:bold;border: 1px solid black; padding:6px;">Emp</th>'
|| '<th style="font-weight:bold;border: 1px solid black; padding:6px;">Days</th>'
|| '<th style="font-weight:bold;border: 1px solid black; padding:6px;">Amount</th>
</tr>';
for r in (select name, days, amount from employee)
loop
l_body := l_body || '<tr><td style="color:#000000;border: 1px solid black;">';
l_body_html := l_body_html || r.emp || '</td><td style="color:#000000;border: 1px solid black;">'
|| r.days|| '</td><td style="color:#000000;border: 1px solid black;">'
|| r.amount||'</td> </tr>';
end loop;
How to create the HTML table header and rows dynamically instead of the static columns and rows?
Based on the query, i should create the HTML table with the selected columns from the query and rows.
You table headers are set in the initialization of l_body. So all you can do, is make this initialization dynamic :
Instead of
You can do :
This assumes that you know in advance the Headers of the query you want to show. You have to pay attention though to the length of your text. the function Replace works only for clob/varchar less than 32767 characters. It the text is too long, you have to switch to concatenations instead of replacements (or write your own large text replacement functions...) like :
If you want it to be like really dynamic, this is going to be quite complex but feasible. Here is how :
Create a view for each query you want to use
Read the columns names of the view using the query :
And repeat the headers replacement as before...