I'm working on an assignment and the spool output is getting some weird formatting for VARCHAR2 function returns. The class uses Oracle SQL 11g.
I have this PL/SQL script:
SET echo on
SET wrap off
SET trimspool on
SET linesize 80
SET colsep '|'
SET serveroutput on
spool @assignment.txt
CREATE OR REPLACE FUNCTION dollar_fmt_sf(
p_num NUMBER
)RETURN VARCHAR2 IS
lv_amt_txt VARCHAR2(20);
BEGIN
lv_amt_txt := to_char(p_num, '$99,999.99');
RETURN lv_amt_txt;
END;
/
SELECT
idbasket,
dollar_fmt_sf(shipping),
dollar_fmt_sf(total)
FROM
bb_basket
WHERE
idbasket = 3;
spool off
This produces an output like this in assignment.txt where the last two columns are on separate lines.
IDBASKET
----------
DOLLAR_FMT_SF(SHIPPING)
--------------------------------------------------------------------------------
DOLLAR_FMT_SF(TOTAL)
--------------------------------------------------------------------------------
3
$5.00
$32.40
I would like to have it look more like this with the headers on the same line:
IDBASKET| SHIPPING| TOTAL
----------|----------|----------
3| 5| 32.4