3

我有一个程序可以在以下位置生成一个表spool

create procedure.....
......
loop
...
dbms_output.put_line(p_taskno||'   '||p_descrip||'  '||p_hrs||' '||p_start_date);
.........

输出是正确的,但格式不正确:

***************************************                                         
ABC Company         Projects:                                                   
Project: 5555                                                                   
TaskNo  Description      Hours StartDate                                        
_____________________________________________                                   
11      Prototype New Screens  30 23-AUG-06                                     
12      Convert Data Files  10.5 15-SEP-06                                      
13      Create Test Plan  15 14-AUG-06                                          
62      Develop Enterprise Model  280 26-OCT-06                                 
_____________________________________________                                   
Number of Tasks: 4                                                              
Total Project Hours: 335.5  

我不能使用column description format a20 word_wrapped,因为该表是dbms_output.put_line. 我怎样才能格式化它?

4

1 回答 1

14

You need to work out the maximum size of the column and then pad the output with spaces.

So you want taskno to align with its header, that's six characters. Because it's a numeric you'll want it to align on the right:

lpad(to_char(taskno), 6)

Whereas Description is a string, so you'll want to align it on the left

rpad(p_description, 30)

Use these functions on the elements of the header too, to get the neatest output.

于 2013-06-22T09:40:21.287 回答