我正在努力实现这些结果:
使用以下代码,格式化会令人困惑。这一切都与DB" Consultant"中的一个表有关。 (见表格末尾):
Set echo off
Remark *** Set up the SQL*Plus environment ***
Set Pagesize 24
Set Feedback Off
Remark *** Format the Columns ***
Column ctype Format A5 Heading Car|Type
Column grade Format A5 Heading Grade
Column A Format A3 Heading A
Column B Format A3 Heading B
Column C Format A3 Heading C
Column D Format A3 Heading D
Column E Format A3 Heading E
Column F Format A3 Heading F
Column G Format A3 Heading G
Remark *** The Query ***
SELECT c_type# as ctype,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'A')) as A,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'B')) as B,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'C')) as C,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'D')) as D,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'E')) as E,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'F')) as F,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'G')) as G
FROM consultant
GROUP BY c_type#
ORDER BY ctype
/
Remark *** Reset the environment ***
Clear columns
Ttitle Off
Btitle Off
Set Feedback on
Set Pagesize 20
Set Echo on
到目前为止,我得到了这个结果:
create table CONSULTANT (
Consultant_Id char(7)
constraint pk_consultant_Consultant_Id primary key
constraint cc_consultant_Consultant_Id check
((substr(Consultant_Id,1,1) between 'A' and 'Z')
and
(substr(Consultant_Id,2,1) between '0' and '9')
and
(substr(Consultant_Id,3,1) between '0' and '9')
and
(substr(Consultant_Id,4,1) between '0' and '9')
and
(substr(Consultant_Id,5,1) between '0' and '9')
and
(substr(Consultant_Id,6,1) between '0' and '9')
and
(substr(Consultant_Id,7,1) between '0' and '9')),
Name varchar2(28)
constraint cc_consultant_Name check (Name = upper (Name))
constraint nn_consultant_Name not null,
Address varchar2(80)
constraint cc_consultant_Address check (Address = upper (Address))
constraint nn_consultant_Address not null,
DOB date
constraint nn_consultant_DOB not null,
Grade char(1)
constraint nn_consultant_Grade not null
constraint fk_consultant_Grade references GRADE(Grade),
C_Type# char(3)
default 'GF8'
constraint fk_consultant_C_Type# references CAR_TYPE(C_Type#),
Mileage_Allow number(3,2)
default null
constraint cc_consultant_Mileage_Allow check (Mileage_Allow between 0 and 0.67),
constraint cc_consultant_C_Type#_Mlg_Allw check
((C_Type# is null and Mileage_Allow is not null)
or
(C_Type# is not null and Mileage_Allow is null))
)
/