Home » SQL & PL/SQL » SQL & PL/SQL » Display results in Table format instead of dbms_output.put_line
Display results in Table format instead of dbms_output.put_line [message #130028] Wed, 27 July 2005 14:49 Go to next message
nvillare
Messages: 11
Registered: July 2005
Junior Member
I have a declare sql script that contains 2 cursors. Depending on the day, ie, Monday, Sunday, etc. it will loop through one of the cursors. Currently I have it to show the data as dbms_output.put_line but the data isn't lined up. Is there any way to have the data appear in a table format?

This is what I currently have that is shows it on dbms_output.put_line.

SET SERVEROUT ON SIZE 100000
DECLARE
v_date varchar2(25);
Cursor C1 IS
select a.attribute9||'-'||a.segment1 "PO_NUM", a.revision_num "REV_NUM", to_char(a.approved_date,'MM/DD/YYYY') "APP_DATE"
from tableToCall a
where a.authorization_status = 'APPROVED'
and trunc(approved_date) between (trunc(sysdate) - 4) and (trunc(sysdate) - 1)
and a.org_id != 159
order by org_id, 1;
Cursor C2 IS
select a.attribute9||'-'||a.segment1 "PO_NUM", a.revision_num "REV_NUM", to_char(a.approved_date,'MM/DD/YYYY') "APP_DATE"
from tableToCall a
where a.authorization_status = 'APPROVED'
and trunc(approved_date) = (trunc(sysdate) - 1)
and a.org_id != 159
order by org_id, 1;

BEGIN

select to_char(sysdate,'Day')
into v_date
from dual;

dbms_output.put_line(chr(10) || v_date || chr(10));

begin
if v_date = 'Monday' then
for R in C1 LOOP
dbms_output.put_line('PO Number: ' || R.PO_NUM || chr(9) || 'Revision Num:' || R.REV_NUM || chr(9) || 'Approved Date: ' || R.APP_DATE);
END LOOP;
elsif v_date != 'Saturday' OR v_date != 'Sunday' OR v_date != 'Monday' then
for R in C2 loop
dbms_output.put_line('PO Number: ' || R.PO_NUM || chr(9) || 'Revision Num:' || R.REV_NUM || chr(9) || 'Approved Date: ' || R.APP_DATE);
end loop;
end if;
end;

END;
/

Any help is greatly approeciated.

Thanks,
Re: Display results in Table format instead of dbms_output.put_line [message #130156 is a reply to message #130028] Thu, 28 July 2005 08:12 Go to previous messageGo to next message
smartin
Messages: 1803
Registered: March 2005
Location: Jacksonville, Florida
Senior Member
One option is to use sql functions like lpad and rpad in your select statements to cause the data you are printing to be of a fixed length. Along with formatting options in to_char.
Re: Display results in Table format instead of dbms_output.put_line [message #130498 is a reply to message #130028] Sun, 31 July 2005 14:46 Go to previous messageGo to next message
oraclejo
Messages: 50
Registered: July 2005
Location: Ammar
Member
Hello

SQL*Plus is not really designed to give great formatting output.
Normally, you should resort to other specialized tools like Oracle Reports, Jdeveloper, PL/SQL web toolkit (owa_util.table_print) and host of other tools


Ammar Sajdi

www.e-ammar.com

Re: Display results in Table format instead of dbms_output.put_line [message #130513 is a reply to message #130028] Sun, 31 July 2005 18:56 Go to previous message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
You could also rewrite your code to open a ref cursor for one select statement, which would align the columns in the result set automtically.
Previous Topic: function probelm
Next Topic: to find 5th highest salary
Goto Forum:
  


Current Time: Sat Jun 07 09:39:38 CDT 2025