set heading off
set termout OFF
SET FEEDBACK OFF
SET TAB OFF
set pause off
set verify off
SET UNDERLINE OFF
set trimspool on
set timing off
set echo off
set linesize 1000
set pagesize 0
COLUMN CODE2 FORMAT 09999999
SET COLSEP ';'
spool test.csv
SELECT A.e,
A.f,
A.g,
B.h as code2
FROM A
JOIN C ON C.e=A.e
JOIN B ON C.j=B.j;
spool off
exit;
или используйте to_char(B.h, '09999999')
set heading off
set termout OFF
SET FEEDBACK OFF
SET TAB OFF
set pause off
set verify off
SET UNDERLINE OFF
set trimspool on
set timing off
set echo off
set linesize 1000
set pagesize 0
SET COLSEP ';'
spool test.csv
SELECT A.e,
A.f,
A.g,
to_char(B.h, '09999999')
FROM A
JOIN C ON C.e=A.e
JOIN B ON C.j=B.j;
spool off
exit;
если поле символьное, вам нужно использовать функцию lpad.
SELECT A.e,
A.f,
A.g,
LPAD(B.h, 9, '0')
FROM A
JOIN C ON C.e=A.e
JOIN B ON C.j=B.j;