Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 21: Report writing1 Chapter Twenty One Producing Readable Output Objectives: Writing reports Page set up Page layout Queries with input.

Similar presentations


Presentation on theme: "Chapter 21: Report writing1 Chapter Twenty One Producing Readable Output Objectives: Writing reports Page set up Page layout Queries with input."— Presentation transcript:

1 Chapter 21: Report writing1 Chapter Twenty One Producing Readable Output Objectives: Writing reports Page set up Page layout Queries with input

2 Producing Readable Output Your NameJanuary 7,2001 List of courses DepartmentCourse No. Course Name CreditDate Started Max enrollment COSC100Intro32-10-9230 110Intro II32-11-9815 200Programming314-2-9320 220Application310-10-0120 Total12 MATH100Algebra41-9-9145 Grand Total Report1.sql 110 Page 1

3 Chapter 21: Report writing3 Summary of Formatting Output Commands COLUMN TTITLE BTITLE BREAK COMPUTE

4 Chapter 21: Report writing4 COLUMN: COLumnname | expression CLEar FORmatformat HEAdingText JUStify LE | CE | R NEWLine NEW_VALUE continue

5 Chapter 21: Report writing5 COLUMN:(continued) NULl text NOPRInt PRInt WRApped TRUncated

6 Chapter 21: Report writing6 Formatting Option: COLUMN NameFORMAT A10 COLUMN idFORMAT 9999 COLUMN crFORMAT 9 COLUMN GpaFORMAT 9.99 FORMAT: $9999 9 0999 990 9,999.99 DATE A10 L999

7 Chapter 21: Report writing7 Formatting Option: COLUMN NameFORMAT A10 COLUMN idFORMAT 9999 COLUMN crFORMAT 9 COLUMN GPAFORMAT 9.99 SELECT Name, id, cr, GPA FROM student WHEREMajor=‘COSC’ ORDER BY GPA;

8 Chapter 21: Report writing8 Heading Option: COLUMN NameHEADING ‘Student’’s Name’ COLUMN idHEADING ‘Student’’s ID’ COLUMN cr*gradeHEADING ‘Score’ COLUMN nameHEADING ‘Student’’s Name’ JUSTIFY LE COLumn Name HEAding ‘Name’ FORmat A10 COLumn Major FORmat A7 NULL ‘NO Major’ COL address HEADING ‘Addr’ FORMAT A7 TRUNC

9 Chapter 21: Report writing9 Column Example: COLUMN idHEADING ‘Stud ID’ FORMAT 9999 TRUNCATED

10 Chapter 21: Report writing10 Clear Setting COLumnMajor CLEarCOLumn

11 Chapter 21: Report writing11 Break on BREAK ONid SKIP 2 BREAK ON id DUPLICATE SKIP 2 BREAK ON id NODUPLICATE BREAK ON Major ON ID BREAK ON REPORT PAGE ON dept PAGE

12 Chapter 21: Report writing12 Break on Format: BREAK ON column BREAK ON row BREAK ON page BREAK ONreport SKIP n SKIP page CLEAR BREAK

13 Chapter 21: Report writing13 Compute COMPUTE SUM OF gpa ON id COMPUTE SUM LABEL ‘Total’ OF gpa ON id COMPUTE AVG OF a, b, c, d ON e COMPUTE SUM AVG COUNT OF gpa ON id AVG COUNT MAX MIN STD VAR

14 Chapter 21: Report writing14 Check the Setting: COLUMN BREAK SHOW DEFINE

15 Chapter 21: Report writing15 Page Setup Line size: SET LINESIZE 75 Page size: SET PAGESIZE 60 Blank lines at the top: SET NEWPAGE 3 Writing into a file: SPOOL filename.lis SPOOL Gstudent.lis SPOOL OFF

16 Chapter 21: Report writing16 Page Setup Display: SET TERMOUT ON SPOOL filename.lis SET TERMOUT OFF Heading separator: SET HEADSEP char SET HEADSEP ! Underlining: SET UNDERLINE OFF

17 Chapter 21: Report writing17 Page Setup Title: TTITLE text | variable TTITLE‘Information ‘ BTITLE ‘Confidential‘ TTITLE Left ‘Page: ’ SQL.PNO – Right ‘Date: ‘ SYSDATE Skip 1 – Center ‘ My Report ‘ Skip 3; SQL.LNO SQL.PNO SQL.RELEASE SQL.SQLCODE SQL.USER

18 Chapter 21: Report writing18 Page Setup Host: HOST myedit filename.SQL HOSTlist 2 Start: START filename.SQL

19 Chapter 21: Report writing19 Page Setup Summary: COLUMN COLUMN colname TTITLE BTITLE BREAK COMPUTE DEFINE SHOW HEADSEP SHOW LINESIZE SHOW PAGESIZE SHOW NEWPAGE

20 Chapter 21: Report writing20 Set Commands COLSEP [|Text] FEEDBACK[OFF| ON| n] HEADING [OFF| ON] LINESIZE [n] PAGESIZE[n] PAUSE[OFF| ON| Text] TERMOUT[OFF| ON]

21 Chapter 21: Report writing21 Report Writing Example: Your NameJanuary 7,2001 List of courses DepartmentCourse No. Course Name CreditDate Started Max enrollment COSC100Intro32-10-9230 110Intro II32-11-9815 200Programming314-2-9320 220Application310-10-0120 Total12 MATH100Algebra41-9-9145 Grand Total Report1.sql 110 Page 1

22 Chapter 21: Report writing22 Report Writing Example: CLEAR BREAK CLEAR COMPUTE COLUMN dept HEADING ‘Department’ FORMAT A12 COLUMN c_num HEADING ‘Course|No.’ FORMAT 999 COLUMN title HEADING ‘Course|Name’ FORMAT A13 COLUMN crHEADING ‘Credit’ FORMAT 99 COLUMN D_start HEADING ‘Date|Started’ FORMAT DATE COLumn m_enrol HEAding ‘Max|Enrollment’ FORMAT 999

23 Chapter 21: Report writing23 Report Writing Example: COL SYSDATE NEW_VALUE xdate NOPRINT FORMAT A1 TRUNC BREAK ON dept SKIP 2 COMPUTE SUM OF cr ON dept --COMPUTE SUM OF cr ON dept REPORT TTITLE LEFT ‘Your Name:’SKIP 2 - RIGHT xdate SKIP 1 - CENTER ‘List of Cources’ SKIP 1

24 Chapter 21: Report writing24 Report Writing Example: BTITLE LEFT ‘Report1.sql’ - RIGHT ‘Page No: ’ SQL.PNO SELECT dept, c_num, title, cr, d_start.m_enroll FROM department WHERE dept IN (‘COSC’, ‘MATH’) ORDER BY dept;

25 Chapter 21: Report writing25 Login File Login.sql prompt login.sql loaded set feedback off set sqlprompt ‘ ‘ set sqlnumber off set numwidth 5 set pagesize 24 set linesize 79

26 Chapter 21: Report writing26 Substitution Variables Substitution variables to temporarily store values - & - & & - DEFINE and ACCEPT Pass variable values between SQL statements Dynamically alter headers and footers

27 Chapter 21: Report writing27 USING & VARIABLE: SELECTname, id, address FROMstudent WHEREid=&student_id; Enter value for student_id:

28 Chapter 21: Report writing28 & Substitution Variables User provides the input to the query SELECTName, GPA, ID FROMStudent WHEREUPPER(Major) = &Major_Input; Enter Value for Major_Input: ‘COSC’

29 Chapter 21: Report writing29 & Substitution Variables SELECTName, ID, &Column_name FROMStudent WHERE&condition ORDER BYℴ Enter Value for Column_name: Enter Value for Condition: Enter Value for Order:

30 Chapter 21: Report writing30 && Substitution Variables Use a value of a variable more than one time SELECTName, ID, &&Column_name FROMStudent WHERE&Column_name=&NewName; Enter value for Column_name:

31 Chapter 21: Report writing31 SET VERIFY ON: SQL> SET VERIFY ON SQL> SELECTname, id, address 2 FROMstudent 3 WHEREid=&student_id; Enter value for student_id: 1111 Old 3: where id=&student_id; New 3: where id= 1111

32 Chapter 21: Report writing32 Character and Date Values With Substitution Variables: SELECTname, id, b_date FROMstudent WHEREb_date = '&new_birthdate'; Enter value for new_birthdate:

33 Chapter 21: Report writing33 Specifying Column Names, Expressions, and Text at Run Time WHERE condition  ORDER BY clause  COLUMNexpression  TABLEname  Entire SELECT statement

34 Chapter 21: Report writing34 Example SELECTname, id, rank, &column_name FROMfaculty WHERE&condition ORDER BY&order_column; Enter value for column_name: Enter value for condition: Enter value for order_column:

35 Chapter 21: Report writing35 Defining User Variables You can pre-define variables using: DEFINE: Create a user variable of CHAR data type ACCEPT: Read user input and store it in a variable

36 Chapter 21: Report writing36 Defining User Variables If you need to predefine a variable that includes spaces, you need to enclose the value within single quotation marks, when using the DEFINE command. DEFINEvariable=CAR DEFINEvariable DEFINE ACCEPT

37 Chapter 21: Report writing37 ACCEPT Command: Create a customized prompt when accepting user input Explicitly defines a NUMBER or DATE datatype variable Hides user input for security

38 Chapter 21: Report writing38 ACCEPT Command: ACCEPT variable [ datatype] [FORMAT format][prompt text ] [HIDE] ACCEPTfield PROMPT 'Input your Major:‘ SELECT* FROMstudent WHEREmajor=UPPER ('&field') Input your major:

39 Chapter 21: Report writing39 DEFINE and UNDEFINE Use the UNDEFINE command to clear Exit SQL*plus To define variables for every session, modify your login.sql file

40 Chapter 21: Report writing40 Create a Variable DEFINEdept_name=COSC DEFINEdept_name SELECT* FROMfaculty WHEREdept=UPPER ('&dept_name'); UNDEFINE dept_name


Download ppt "Chapter 21: Report writing1 Chapter Twenty One Producing Readable Output Objectives: Writing reports Page set up Page layout Queries with input."

Similar presentations


Ads by Google