I did not see a forum for SQLPLUS, so I hope this is the correct forum to post my question to.
After running the following script (did not put in all columns, because it is too many):
set termout on
set echo off
set feedback off
spool &directory
declare
cursor get_fore
is
select fortype, forarea, forlocal, ..., ...
from forcast;
begin
dbms_output.put_line
( rpad('fortype', 20 ) ||
rpad('forarea', 20) ||
rpad('forlocal' ,20) ||
...
...
rpad...);
dbms_output.put_line
( rpad( '-', 20, '-') ||
rpad(' -',20,'-') ||
rpad(' -',20,'-')
...
...
rpad...);
for for_rec in get_fore loop
dbms_output.put_line
( rpad( for_rec.fortype, 20 ) ||
rpad( for_rec.forarea, 20 ) ||
rpad( for_rec.forlocal, 20 )
...
...
rpad...);
end loop;
end;
/
spool off
set serveroutput off
I received the following error: ORA-06502: PL/SQL: numeric or value error: host bind array too small.
I understand this happens due to restrictions of 255 characters on DBMS_OUTPUT.PUT_LINE.
So, I changed to
set termout on
set echo off
set feedback off
spool &directory
declare
cursor get_fore
is
select fortype, forarea, forlocal, ..., ...
from forcast;
var1 varchar2(4000);
var2 varchar2(4000);
begin
var1 := rpad('Forecast Type', 20 ) ||
rpad('Forecast Area',20) ||
rpad('Forecast Local',20)||
...
...
rpad( '-', 10, '-') ||
rpad(' -',10,'-') ||
rpad(' -',10,'-')
...
...
rpad...);
str_len := length(var1);
while loop_cnt < str_len
loop
dbms_output.put_line(substr(var1, loop_count +1, 255));
end loop;
str_len := 0;
loop_count := 0;
for for_rec in get_fore loop
var2 := rpad( for_rec.fortype, 10 ) ||
rpad( for_rec.forarea, 10 ) ||
rpad( for_rec.forlocal, 10 ) ||
...
...
rpad... );
str_len := length(var1);
while loop_cnt < str_len
loop
dbms_output.put_line(substr(var1, loop_count +1, 255));
end loop;
end loop;
end;
/
spool off
set serveroutput off
So, the problem is that the formatting is really off.
Before the change the results looked like:
Forecast Type Forecast Area Forecast Local ... ....
-----------------------------------------------------------
xxxxxxx xxxxxxx xxxxxxxxxx
Now the headings, underscores and data wrap:
Forecast Type Forecast Area
Forecast Local ... ....
-----------------------------------------------------------
xxxxxxx xxxxxxx
xxxxxxxxxx xxxx xxxx
I am new at formatting using SQLPLUS and if anyone could give me some answers, I would appreciate it.
Thanks.
getjbb
After running the following script (did not put in all columns, because it is too many):
set termout on
set echo off
set feedback off
spool &directory
declare
cursor get_fore
is
select fortype, forarea, forlocal, ..., ...
from forcast;
begin
dbms_output.put_line
( rpad('fortype', 20 ) ||
rpad('forarea', 20) ||
rpad('forlocal' ,20) ||
...
...
rpad...);
dbms_output.put_line
( rpad( '-', 20, '-') ||
rpad(' -',20,'-') ||
rpad(' -',20,'-')
...
...
rpad...);
for for_rec in get_fore loop
dbms_output.put_line
( rpad( for_rec.fortype, 20 ) ||
rpad( for_rec.forarea, 20 ) ||
rpad( for_rec.forlocal, 20 )
...
...
rpad...);
end loop;
end;
/
spool off
set serveroutput off
I received the following error: ORA-06502: PL/SQL: numeric or value error: host bind array too small.
I understand this happens due to restrictions of 255 characters on DBMS_OUTPUT.PUT_LINE.
So, I changed to
set termout on
set echo off
set feedback off
spool &directory
declare
cursor get_fore
is
select fortype, forarea, forlocal, ..., ...
from forcast;
var1 varchar2(4000);
var2 varchar2(4000);
begin
var1 := rpad('Forecast Type', 20 ) ||
rpad('Forecast Area',20) ||
rpad('Forecast Local',20)||
...
...
rpad( '-', 10, '-') ||
rpad(' -',10,'-') ||
rpad(' -',10,'-')
...
...
rpad...);
str_len := length(var1);
while loop_cnt < str_len
loop
dbms_output.put_line(substr(var1, loop_count +1, 255));
end loop;
str_len := 0;
loop_count := 0;
for for_rec in get_fore loop
var2 := rpad( for_rec.fortype, 10 ) ||
rpad( for_rec.forarea, 10 ) ||
rpad( for_rec.forlocal, 10 ) ||
...
...
rpad... );
str_len := length(var1);
while loop_cnt < str_len
loop
dbms_output.put_line(substr(var1, loop_count +1, 255));
end loop;
end loop;
end;
/
spool off
set serveroutput off
So, the problem is that the formatting is really off.
Before the change the results looked like:
Forecast Type Forecast Area Forecast Local ... ....
-----------------------------------------------------------
xxxxxxx xxxxxxx xxxxxxxxxx
Now the headings, underscores and data wrap:
Forecast Type Forecast Area
Forecast Local ... ....
-----------------------------------------------------------
xxxxxxx xxxxxxx
xxxxxxxxxx xxxx xxxx
I am new at formatting using SQLPLUS and if anyone could give me some answers, I would appreciate it.
Thanks.
getjbb