クエリが次のようなものであると仮定します (すべての異なるデータ型を処理する必要はないことに注意してください)
select column_name "Name",
(case when nullable = 'N'
then 'NOT NULL'
else null
end) "Null?",
(case when data_type = 'DATE'
then data_type
when data_type = 'NUMBER' and data_scale > 0
then data_type || '(' || data_precision || ',' || data_scale || ')'
when data_type = 'NUMBER' and data_scale = 0
then data_type || '(' || data_precision || ')'
when data_type = 'VARCHAR2'
then data_type || '(' || data_length || ')'
end) "Type"
from dba_tab_cols
where table_name = 'EMP'
order by column_id
いくつかの SQL*Plus コマンドを発行して、出力をフォーマットできます
SQL> column "Nmae" format a30;
SQL> column "Null?" format a8;
SQL> column "Type" format a30;
クエリの出力は DESCRIBE
の出力と一致します コマンド
SQL> ed
Wrote file afiedt.buf
1 select column_name "Name",
2 (case when nullable = 'N'
3 then 'NOT NULL'
4 else null
5 end) "Null?",
6 (case when data_type = 'DATE'
7 then data_type
8 when data_type = 'NUMBER' and data_scale > 0
9 then data_type || '(' || data_precision || ',' || data_scale || ')'
10 when data_type = 'NUMBER' and data_scale = 0
11 then data_type || '(' || data_precision || ')'
12 when data_type = 'VARCHAR2'
13 then data_type || '(' || data_length || ')'
14 end) "Type"
15 from dba_tab_cols
16 where table_name = 'EMP'
17* order by column_id
SQL> /
Name Null? Type
------------------------------ -------- ------------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
8 rows selected.