7 Copyright © Oracle Corporation, 2001. All rights reserved. Producing Readable Output with i SQL*Plus.

Slides:



Advertisements
Similar presentations
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Advertisements

8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
6 Copyright © 2004, Oracle. All rights reserved. Using Subqueries to Solve Queries.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Writing Basic SQL statement 2 July July July Create By Pantharee Sawasdimongkol.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Chapter 1 Writing Basic SQL Statements Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Ceng 356-Lab2. Objectives After completing this lesson, you should be able to do the following: Limit the rows that are retrieved by a query Sort the.
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 2 Basic SQL SELECT Statements
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
1 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
Database control Introduction. The Database control is a tool that used by the database administrator to control the database. To enter to Database control.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
1 Reports. 2 Objectives  Use concatenation in a query  Change column headings and formats  Add a title to a report  Group data in a report  Include.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Oracle Command Spool Spool C:\temp\Lab9.lst Select Hotel_no, room_no, type, price From Room Order by Hotel_no; Spool Off.
A Guide to SQL, Seventh Edition. Objectives Understand how to use functions in queries Use the UPPER and LOWER functions with character data Use the ROUND.
Introduction to SQL PART Ⅰ 第一讲 Writing Basic SQL SELECT Statements.
8 Producing Readable Output with SQL*Plus. 8-2 Objectives At the end of this lesson, you should be able to: Produce queries that require an input variable.
1 Writing Basic SQL Statements. 1-2 Objectives At the end of this lesson, you should be able to: List the capabilities of SQL SELECT statements Execute.
2 第二讲 Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
15 Copyright © Oracle Corporation, All rights reserved. Using SET Operators.
Copyright © 2004, Oracle. All rights reserved. Using the Set Operators.
Copyright  Oracle Corporation, All rights reserved. 8 Producing Readable Output with SQL*Plus.
Chapter 14 Formatting Readable Output. Chapter Objectives  Add a column heading with a line break to a report  Format the appearance of numeric data.
Chapter Twelve Report Writing Objectives: -Writing reports -Page set up -Page layout.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
Oracle PL/SQL SQL*Plus. EDIT Opens notepad with the buffer contents To use type: –Edit –Ed Opens notepad with the buffer contents To use type: –Edit –Ed.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Chapter 21: Report writing1 Chapter Twenty One Producing Readable Output Objectives: Writing reports Page set up Page layout Queries with input.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following: –List the capabilities of SQL SELECT statements.
A Guide to SQL, Sixth Edition 1 Chapter 7 Reports.
3 Copyright © 2004, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Oracle 10g Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
4 Copyright © 2009, Oracle. All rights reserved. Using Conversion Functions and Conditional Expressions.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
D Copyright © 2009, Oracle. All rights reserved. Using SQL*Plus.
Retrieving Data Using the SQL SELECT Statement
A Guide to SQL, Seventh Edition
Writing Basic SQL SELECT Statements
SQL and SQL*Plus Interaction
Creating LOVs and Editors
Chapter Twenty Producing Readable Output
Retrieving Data Using the SQL SELECT Statement
Restricting and Sorting Data
Using SQL*Plus.
Restricting and Sorting Data
Using SQL*Plus.
iSQL*Plus Schedule: Timing Topic 35 minutes Lecture
Producing Readable Output with iSQL*Plus
Presentation transcript:

7 Copyright © Oracle Corporation, All rights reserved. Producing Readable Output with i SQL*Plus

7-2 Copyright © Oracle Corporation, All rights reserved. Objectives After completing this lesson, you should be able to do the following: Produce queries that require a substitution variable Customize the i SQL*Plus environment Produce more readable output Create and execute script files

7-3 Copyright © Oracle Corporation, All rights reserved. Substitution Variables I want to query different values.... salary = ? … … department_id = ? …... last_name = ?... User

7-4 Copyright © Oracle Corporation, All rights reserved. Substitution Variables Use i SQL*Plus substitution variables to: Temporarily store values –Single ampersand ( & ) –Double ampersand ( && ) –DEFINE command Pass variable values between SQL statements Dynamically alter headers and footers

7-5 Copyright © Oracle Corporation, All rights reserved. Using the & Substitution Variable Use a variable prefixed with an ampersand ( & ) to prompt the user for a value. SELECTemployee_id, last_name, salary, department_id FROMemployees WHEREemployee_id = &employee_num ;

7-6 Copyright © Oracle Corporation, All rights reserved. Using the & Substitution Variable

7-7 Copyright © Oracle Corporation, All rights reserved. SELECT last_name, department_id, salary*12 FROM employees WHERE job_id = '&job_title' ; Character and Date Values with Substitution Variables Use single quotation marks for date and character values.

7-8 Copyright © Oracle Corporation, All rights reserved. Specifying Column Names, Expressions, and Text Use substitution variables to supplement the following: WHERE conditions ORDER BY clauses Column expressions Table names Entire SELECT statements

7-9 Copyright © Oracle Corporation, All rights reserved. SELECTemployee_id, last_name, job_id, &column_name FROMemployees WHERE&condition ORDER BY&order_column ; Specifying Column Names, Expressions, and Text

7-10 Copyright © Oracle Corporation, All rights reserved. Defining Substitution Variables You can predefine variables using the i SQL*Plus DEFINE command. DEFINE variable = value creates a user variable with the CHAR data type. If you need to predefine a variable that includes spaces, you must enclose the value within single quotation marks when using the DEFINE command. A defined variable is available for the session

7-11 Copyright © Oracle Corporation, All rights reserved. DEFINE and UNDEFINE Commands A variable remains defined until you either: –Use the UNDEFINE command to clear it –Exit i SQL*Plus You can verify your changes with the DEFINE command. DEFINE job_title = IT_PROG DEFINE job_title DEFINE JOB_TITLE = "IT_PROG" (CHAR) UNDEFINE job_title DEFINE job_title SP2-0135: symbol job_title is UNDEFINED

7-12 Copyright © Oracle Corporation, All rights reserved. SELECT employee_id, last_name, salary, department_id FROM employees WHERE employee_id = &employee_num ; Using the DEFINE Command with & Substitution Variable Create the substitution variable using the DEFINE command. Use a variable prefixed with an ampersand ( & ) to substitute the value in the SQL statement. DEFINE employee_num = 200

7-13 Copyright © Oracle Corporation, All rights reserved. SELECT employee_id, last_name, job_id, &&column_name FROM employees ORDER BY &column_name; Use the double-ampersand ( && ) if you want to reuse the variable value without prompting the user each time. … Using the && Substitution Variable

7-14 Copyright © Oracle Corporation, All rights reserved. old 3: WHERE employee_id = &employee_num new 3: WHERE employee_id = 200 Using the VERIFY Command Use the VERIFY command to toggle the display of the substitution variable, before and after i SQL*Plus replaces substitution variables with values. SET VERIFY ON SELECT employee_id, last_name, salary, department_id FROM employees WHERE employee_id = &employee_num;

7-15 Copyright © Oracle Corporation, All rights reserved. Customizing the i SQL*Plus Environment SET Use SET commands to control current session. SHOW Verify what you have set by using the SHOW command. SET ECHO ON SHOW ECHO echo ON SHOW ECHO echo ON SET system_variable value

7-16 Copyright © Oracle Corporation, All rights reserved. SET Command Variables ARRAYSIZE {20 | n} FEEDBACK {6 | n |OFF | ON} HEADING {OFF | ON} LONG {80 | n}| ON | text} SET HEADING OFF SHOW HEADING HEADING OFF SHOW HEADING HEADING OFF

7-17 Copyright © Oracle Corporation, All rights reserved. i SQL*Plus Format Commands COLUMN [column option] TTITLE [text | OFF | ON] BTITLE [text | OFF | ON] BREAK [ON report_element]

7-18 Copyright © Oracle Corporation, All rights reserved. The COLUMN Command Controls display of a column: CLE[AR] : Clears any column formats HEA[DING] text : Sets the column heading FOR[MAT] format : Changes the display of the column using a format model NOPRINT | PRINT NULL COL[UMN] [{column|alias} [option]]

7-19 Copyright © Oracle Corporation, All rights reserved. Using the COLUMN Command Create column headings. COLUMN last_name HEADING 'Employee|Name' COLUMN salary JUSTIFY LEFT FORMAT $99, COLUMN manager FORMAT NULL 'No manager' COLUMN last_name HEADING 'Employee|Name' COLUMN salary JUSTIFY LEFT FORMAT $99, COLUMN manager FORMAT NULL 'No manager' COLUMN last_name COLUMN last_name CLEAR Display the current setting for the LAST_NAME column. Clear settings for the LAST_NAME column.

7-20 Copyright © Oracle Corporation, All rights reserved. COLUMN Format Models Result $1234 L ,234 Example $9999 L ,999 Element 9 0 $ L., Description Single zero-suppression digit Enforces leading zero Floating dollar sign Local currency Position of decimal point Thousand separator

7-21 Copyright © Oracle Corporation, All rights reserved. Using the BREAK Command Use the BREAK command to suppress duplicates. BREAK ON job_id

7-22 Copyright © Oracle Corporation, All rights reserved. Using the TTITLE and BTITLE Commands Display headers and footers. Set the report header. Set the report footer. TTI[TLE] [text|OFF|ON] TTITLE 'Salary|Report' BTITLE 'Confidential'

7-23 Copyright © Oracle Corporation, All rights reserved. Using the TTITLE and BTITLE Commands Display headers and footers. Set the report header. Set the report footer. TTI[TLE] [text|OFF|ON] TTITLE 'Salary|Report' BTITLE 'Confidential'

7-24 Copyright © Oracle Corporation, All rights reserved. Creating a Script File to Run a Report 1. Create and test the SQL SELECT statement. 2.Save the SELECT statement into a script file. 3.Load the script file into an editor. 4.Add formatting commands before the SELECT statement. 5.Verify that the termination character follows the SELECT statement.

7-25 Copyright © Oracle Corporation, All rights reserved. Creating a Script File to Run a Report 6.Clear formatting commands after the SELECT statement. 7.Save the script file. 8.Load the script file into the i SQL*Plus text window, and click the Execute button.

7-26 Copyright © Oracle Corporation, All rights reserved. Sample Report …

7-27 Copyright © Oracle Corporation, All rights reserved. Sample Report …

7-28 Copyright © Oracle Corporation, All rights reserved. Summary In this lesson, you should have learned how to: Use i SQL*Plus substitution variables to store values temporarily Use SET commands to control the current i SQL*Plus environment Use the COLUMN command to control the display of a column Use the BREAK command to suppress duplicates and divide rows into sections Use the TTITLE and BTITLE commands to display headers and footers

7-29 Copyright © Oracle Corporation, All rights reserved. Practice 7 Overview This practice covers the following topics: Creating a query to display values using substitution variables Starting a command file containing variables

7-30 Copyright © Oracle Corporation, All rights reserved.

7-31 Copyright © Oracle Corporation, All rights reserved.

7-32 Copyright © Oracle Corporation, All rights reserved.