我正在学习如何编写基本的SQL * Plus报告。
练习时,我遇到了BREAK ON命令的麻烦,我不确定如何继续。
作为参考,正在使用的表格称为“报纸”,它包含报纸中要素的名称,该要素所在的部分以及该要素所在的页面。
运行以下报告时,SQL * Plus会按预期返回结果:
rem Newspaper Report
ttitle 'Newspaper Features by Section'
btitle 'Hot off the Presses'
column feature format a15 word_wrapped
column section format a7
column page format 99
column feature heading 'Feature'
column section heading 'Section'
column page heading 'Page'
break on section skip 1
set linesize 80
set pagesize 40
set newpage 0
set feedback off
spool test.sql
select section, feature, page from newspaper
order by section;
spool off
输出:
Section Feature Page
------- --------------- ----
A National News 1
Editorials 12
B Bridge 2
Movies 4
Modern Life 1
Television 7
C Comics 4
Weather 2
D Sports 1
E Business 1
F Obituaries 6
Classified 8
Doctor Is In 6
Births 7
在此示例中,只要SQL * Plus到达新功能,就会跳过一行。这就是它的工作方式。
但是,当我执行以下报告时,我的结果的格式不符合它们的格式:
rem Newspaper Report
ttitle 'Newspaper Features by Page'
btitle 'Hot off the Presses'
column feature format a15 word_wrapped
column section format a7
column page format 99
column feature heading 'Feature'
column section heading 'Section'
column page heading 'Page'
break on page skip 1
set linesize 80
set pagesize 40
set newpage 0
set feedback off
spool test.sql
select page, feature, section from newspaper
order by page;
spool off
输出:
Page Feature Section
---- --------------- -------
1 Modern Life B
Sports D
National News A
Business E
2 Weather C
Bridge B
4 Movies B
Comics C
6 Doctor Is In F
Obituaries F
7 Television B
Births F
8 Classified F
12 Editorials A
页面更改时未跳过任何行。我做错了什么或命令限制在这种方式?
答案 0 :(得分:2)
在我看来,问题是列名是" Page&#34 ;;因为页面是BREAK ACTION。您是否可以尝试将列别名为" page"并尝试:例如:
column page_temp heading 'Page'
break on page_temp skip 1
set linesize 80
set pagesize 40
set newpage 0
set feedback off
spool test.sql
select page page_temp, feature, section from newspaper
order by page;