45,000 Jobs - Get an Interview Call,  Post Your Resume Here
SURESHKUMAR.NET FORUMS
Registered Member Login:
Not a member? Register today!



Welcome to the SURESHKUMAR.NET FORUMS.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.




Oracle SQL to HTML table

        

In this blog I will post all FAQs, code snippets, real time problems and solutions and any other links which I feel every one needs and can take advantage of.
Rate this Entry

Oracle SQL to HTML table

Posted 14-10-08 at 01:06 PM by sk_kireeti
This can be a very handy script if you want to convert a SQL query output into a HTML table.

Execute following anonymous pl/sql block in your SQL*Plus editor -

* Sorry for bad formatting



declare
c number;
d number;
col_cnt integer;
f boolean;
rec_tab dbms_sql.desc_tab;
col_num number;
column_value varchar2(32767);
col_index integer;
sql_query varchar2(32767);
begin
sql_query := 'SELECT * FROM all_tables where rownum<2';
c := dbms_sql.open_cursor;
dbms_sql.parse(c, sql_query, dbms_sql.native);

dbms_sql.describe_columns(c, col_cnt, rec_tab);
dbms_output.put_line('<table border=2>');
dbms_output.put_line('<th>');
/*
* Following loop could simply be for j in 1..col_cnt loop.
* Here we are simply illustrating some of the PL/SQL table
* features.
*/
col_num := rec_tab.first;
if (col_num is not null) then
loop
DBMS_SQL.DEFINE_COLUMN (c, col_num, column_value,32767);
dbms_output.put_line('<td>'||rec_tab(col_num).col_name || '</td>');
col_num := rec_tab.next(col_num);
exit when (col_num is null);
end loop;
end if;
dbms_output.put_line('</th>');
d := dbms_sql.execute(c);

LOOP
/* Fetch next row. Exit when done. */
EXIT WHEN DBMS_SQL.FETCH_ROWS(c) = 0;
dbms_output.put_line('<tr>');
for col_index in 1..col_cnt
loop
DBMS_SQL.COLUMN_VALUE (c, col_index, column_value);
dbms_output.put_line('<td>' || trim(nvl(column_value,'-')) || '</td>');
end loop;
dbms_output.put_line('</tr>');
END LOOP;
dbms_output.put_line('</table>');

dbms_sql.close_cursor(c);
end;
/



For your requirements, you can change "sql_query" variable to match your requirements.

Thanks,
Krishna
Total Comments 0

Comments

 

All times are GMT +6.5. The time now is 10:22 AM.

More Interview Questions Here...

Content Relevant URLs by vBSEO 3.3.0