SlideShare a Scribd company logo
Producing Readable Output with iSQL*Plus  http://ecomputernotes.com
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  http://ecomputernotes.com
Substitution Variables  I want to query  different values.  ... salary =  ? «  « department_id = ? «  ... last_name = ? ...  User  http://ecomputernotes.com
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  http://ecomputernotes.com
Using the   &   Substitution Variable  Use a variable prefixed with an ampersand ( & ) to prompt the user for a value.  SELECT  employee_id, last_name, salary, department_id  FRO M  employees  WHERE  employee_id = &employee_num ;  http://ecomputernotes.com
Using the   &   Substitution Variable  2  101  1  http://ecomputernotes.com
Character and Date Values  with Substitution Variables  Use single quotation marks for date and character values.  SELECT last_name, department_id, salary*12  FROM  employees  WHERE  job_id = '&job_title' ;  http://ecomputernotes.com
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  http://ecomputernotes.com
Specifying Column Names,  Expressions, and Text  SELECT  employee_id, last_name, job_id,  &column_name  FRO M  employees  WHERE  &condition  ORDER BY  &order_column ;  http://ecomputernotes.com
Defining Substitution Variables  "Y ou can predefine variables using the  i S QL*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  http://ecomputernotes.com
DEFINE   and   UNDEFINE   Commands  "A  variable remains defined until you either:  Use the UNDEFINE command to clear it Exit   i SQL*Plus  "Y ou can verify your changes with the  D EFINE  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  http://ecomputernotes.com
Using the   DEFINE   Command with  &   Substitution Variable  "C reate the substitution variable using the  D EFINE  command.  DEFINE employee_num = 200  "  Use a variable prefixed with an ampersand ( & ) to substitute the value in the SQL statement.  SELECT employee_id, last_name, salary, department_id  FROM  employees  WHERE  employee_id = &employee_num ;  http://ecomputernotes.com
Using the   &&   Substitution Variable  Use the double-ampersand ( && ) if you want to reuse the variable value without prompting the user each  time.  SELECT  employee_id, last_name, job_id, &&column_name  FROM  employees  ORDER BY &column_name;  «  http://ecomputernotes.com
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;  old  3: WHERE  employee_id = &employee_num  new  3: WHERE  employee_id = 200  http://ecomputernotes.com
Customizing the   i SQL*Plus Environment  "U se  S ET  c ommands to control current session.  SET   system_variable value  "V erify what you have set by using the  S H O W  command.  SET ECHO  ON  SHOW ECHO  echo ON  http://ecomputernotes.com
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  http://ecomputernotes.com
i SQL*Plus Format Commands  "  COLUMN [ column option ]  "  TTITLE [ text  | OFF | ON]  "  BTITLE [ text  | OFF | ON]  "  BREAK  [ON   report_element ]
The   COLUMN   Command  Controls display of a column:  COL[UMN] [{ column || alias } [ option ]]]]  "  CLE[AR]: Clears any column formats  "  HEA[DING]   text : Sets the column heading  "F OR[MAT]  f ormat:  Changes the display of the  column using a format model  "  NOPRINT | PRINT  "  NULL
Using the   COLUMN   Command  "C reate column headings.  COLUMN last_name HEADING 'Employee|Name' COLUMN salary JUSTIFY LEFT FORMAT $99,990.00 COLUMN manager FORMAT 999999999 NULL 'No manager'  "  Display the current setting for the   LAST_NAME  column.  COLUMN last_name  "C lear settings for the  L AST_NAME  c olumn.  COLUMN last_name CLEAR
COLUMN   Format Models  Element  Description  Example  Result  9  Single zero-suppression  999999  1234  digit  0  Enforces leading zero  099999  001234  $  Floating dollar sign  $9999  $1234  L  Local currency  L9999  L1234  Position of decimal point  9999.99  1234.00  ,  Thousand separator  9,999  1,234
Using the   BREAK   Command  Use the   BREAK   command to suppress duplicates.  BREAK ON job_id
Using the   TTITLE   and   BTITLE   Commands  "D isplay headers and footers.  tex t |OFF|ON]  "S et the report header.  T TITLE 'Salary|Report'  "S et the report footer.  BTITLE 'Confidential'
Using the   TTITLE   and   BTITLE   Commands  "D isplay headers and footers.  TTI[TLE] [ text |OFF|ON]  "S et the report header.  TTITLE 'Salary|Report'  "S et the report footer.  BTITLE 'Confidential'
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.
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.
Sample Report  «
Sample Report  «

More Related Content

What's hot (17)

PDF
Introduction to oracle functions
Nitesh Singh
 
PPT
SQL select statement and functions
Vikas Gupta
 
PPT
Les01
Sudharsan S
 
PPTX
form view
AbiMurugan2
 
PPTX
1. dml select statement reterive data
Amrit Kaur
 
PPTX
Lab5 sub query
Balqees Al.Mubarak
 
PPT
SQL Tuning Overview
Kai Liu
 
ODP
Prabu's sql quries
Prabu Cse
 
PDF
Introduction To Oracle Sql
Ahmed Yaseen
 
PPT
Myth busters - performance tuning 101 2007
paulguerin
 
ODP
Babitha2.mysql
banubabitha
 
PPTX
Enterprise Data Validation
Kevin Hazzard
 
ODP
My sql Syntax
Reka
 
PPTX
SignalR & SQL Dependency
Narato
 
PPTX
Oracle SQL Functions
A Data Guru
 
PPT
Single-Row Functions in orcale Data base
Salman Memon
 
PPTX
Oracle: Procedures
DataminingTools Inc
 
Introduction to oracle functions
Nitesh Singh
 
SQL select statement and functions
Vikas Gupta
 
form view
AbiMurugan2
 
1. dml select statement reterive data
Amrit Kaur
 
Lab5 sub query
Balqees Al.Mubarak
 
SQL Tuning Overview
Kai Liu
 
Prabu's sql quries
Prabu Cse
 
Introduction To Oracle Sql
Ahmed Yaseen
 
Myth busters - performance tuning 101 2007
paulguerin
 
Babitha2.mysql
banubabitha
 
Enterprise Data Validation
Kevin Hazzard
 
My sql Syntax
Reka
 
SignalR & SQL Dependency
Narato
 
Oracle SQL Functions
A Data Guru
 
Single-Row Functions in orcale Data base
Salman Memon
 
Oracle: Procedures
DataminingTools Inc
 

Similar to e computer notes - Producing readable output with i sql plus (20)

PPT
Les07
Vijay Kumar
 
PPT
Les08-Oracle
suman1248
 
PPT
e computer notes - Writing basic sql select statements
ecomputernotes
 
PPT
e computer notes - Creating views
ecomputernotes
 
PPT
Chinabankppt
newrforce
 
PPT
Les02
Sudharsan S
 
PPT
Les02 (restricting and sorting data)
Achmad Solichin
 
PPT
e computer notes - Subqueries
ecomputernotes
 
PPT
e computer notes - Single row functions
ecomputernotes
 
PPTX
Plsql coding conventions
Fang Yu
 
PPT
e computer notes - Restricting and sorting data
ecomputernotes
 
PPT
e computer notes - Creating and managing tables
ecomputernotes
 
PPT
e computer notes - Using set operator
ecomputernotes
 
PPT
Sql dml & tcl 2
Dr. C.V. Suresh Babu
 
PPT
Les01 (retrieving data using the sql select statement)
Achmad Solichin
 
ODP
Open Gurukul Language PL/SQL
Open Gurukul
 
PPT
Les08[1] Producing Readable Output with SQL*Plus
siavosh kaviani
 
PPTX
Oracle: Basic SQL
oracle content
 
ODP
Mysqlppt
Reka
 
TXT
Oracle sql tuning
bishnupriya Panda
 
Les08-Oracle
suman1248
 
e computer notes - Writing basic sql select statements
ecomputernotes
 
e computer notes - Creating views
ecomputernotes
 
Chinabankppt
newrforce
 
Les02 (restricting and sorting data)
Achmad Solichin
 
e computer notes - Subqueries
ecomputernotes
 
e computer notes - Single row functions
ecomputernotes
 
Plsql coding conventions
Fang Yu
 
e computer notes - Restricting and sorting data
ecomputernotes
 
e computer notes - Creating and managing tables
ecomputernotes
 
e computer notes - Using set operator
ecomputernotes
 
Sql dml & tcl 2
Dr. C.V. Suresh Babu
 
Les01 (retrieving data using the sql select statement)
Achmad Solichin
 
Open Gurukul Language PL/SQL
Open Gurukul
 
Les08[1] Producing Readable Output with SQL*Plus
siavosh kaviani
 
Oracle: Basic SQL
oracle content
 
Mysqlppt
Reka
 
Oracle sql tuning
bishnupriya Panda
 
Ad

More from ecomputernotes (20)

PPT
computer notes - Data Structures - 30
ecomputernotes
 
PPT
computer notes - Data Structures - 39
ecomputernotes
 
PPT
computer notes - Data Structures - 11
ecomputernotes
 
PPT
computer notes - Data Structures - 20
ecomputernotes
 
PPT
computer notes - Data Structures - 15
ecomputernotes
 
DOC
Computer notes - Including Constraints
ecomputernotes
 
DOC
Computer notes - Date time Functions
ecomputernotes
 
DOC
Computer notes - Subqueries
ecomputernotes
 
DOC
Computer notes - Other Database Objects
ecomputernotes
 
PPT
computer notes - Data Structures - 28
ecomputernotes
 
PPT
computer notes - Data Structures - 19
ecomputernotes
 
PPT
computer notes - Data Structures - 31
ecomputernotes
 
PPT
computer notes - Data Structures - 4
ecomputernotes
 
PPT
computer notes - Data Structures - 13
ecomputernotes
 
DOC
Computer notes - Advanced Subqueries
ecomputernotes
 
DOC
Computer notes - Aggregating Data Using Group Functions
ecomputernotes
 
PPT
computer notes - Data Structures - 16
ecomputernotes
 
PPT
computer notes - Data Structures - 22
ecomputernotes
 
PPT
computer notes - Data Structures - 35
ecomputernotes
 
PPT
computer notes - Data Structures - 36
ecomputernotes
 
computer notes - Data Structures - 30
ecomputernotes
 
computer notes - Data Structures - 39
ecomputernotes
 
computer notes - Data Structures - 11
ecomputernotes
 
computer notes - Data Structures - 20
ecomputernotes
 
computer notes - Data Structures - 15
ecomputernotes
 
Computer notes - Including Constraints
ecomputernotes
 
Computer notes - Date time Functions
ecomputernotes
 
Computer notes - Subqueries
ecomputernotes
 
Computer notes - Other Database Objects
ecomputernotes
 
computer notes - Data Structures - 28
ecomputernotes
 
computer notes - Data Structures - 19
ecomputernotes
 
computer notes - Data Structures - 31
ecomputernotes
 
computer notes - Data Structures - 4
ecomputernotes
 
computer notes - Data Structures - 13
ecomputernotes
 
Computer notes - Advanced Subqueries
ecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
ecomputernotes
 
computer notes - Data Structures - 16
ecomputernotes
 
computer notes - Data Structures - 22
ecomputernotes
 
computer notes - Data Structures - 35
ecomputernotes
 
computer notes - Data Structures - 36
ecomputernotes
 
Ad

Recently uploaded (20)

PPTX
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
PPTX
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PPTX
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PPTX
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
PDF
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
PPT
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
PPTX
How to use _name_search() method in Odoo 18
Celine George
 
PDF
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
PDF
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
PPTX
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
PDF
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PPTX
Peer Teaching Observations During School Internship
AjayaMohanty7
 
DOCX
DLL english grade five goof for one week
FlordelynGonzales1
 
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
How to use _name_search() method in Odoo 18
Celine George
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
Peer Teaching Observations During School Internship
AjayaMohanty7
 
DLL english grade five goof for one week
FlordelynGonzales1
 

e computer notes - Producing readable output with i sql plus

  • 1. Producing Readable Output with iSQL*Plus http://ecomputernotes.com
  • 2. 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 http://ecomputernotes.com
  • 3. Substitution Variables I want to query different values. ... salary = ? « « department_id = ? « ... last_name = ? ... User http://ecomputernotes.com
  • 4. 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 http://ecomputernotes.com
  • 5. Using the & Substitution Variable Use a variable prefixed with an ampersand ( & ) to prompt the user for a value. SELECT employee_id, last_name, salary, department_id FRO M employees WHERE employee_id = &employee_num ; http://ecomputernotes.com
  • 6. Using the & Substitution Variable 2 101 1 http://ecomputernotes.com
  • 7. Character and Date Values with Substitution Variables Use single quotation marks for date and character values. SELECT last_name, department_id, salary*12 FROM employees WHERE job_id = '&job_title' ; http://ecomputernotes.com
  • 8. 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 http://ecomputernotes.com
  • 9. Specifying Column Names, Expressions, and Text SELECT employee_id, last_name, job_id, &column_name FRO M employees WHERE &condition ORDER BY &order_column ; http://ecomputernotes.com
  • 10. Defining Substitution Variables "Y ou can predefine variables using the i S QL*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 http://ecomputernotes.com
  • 11. DEFINE and UNDEFINE Commands "A variable remains defined until you either: Use the UNDEFINE command to clear it Exit i SQL*Plus "Y ou can verify your changes with the D EFINE 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 http://ecomputernotes.com
  • 12. Using the DEFINE Command with & Substitution Variable "C reate the substitution variable using the D EFINE command. DEFINE employee_num = 200 " Use a variable prefixed with an ampersand ( & ) to substitute the value in the SQL statement. SELECT employee_id, last_name, salary, department_id FROM employees WHERE employee_id = &employee_num ; http://ecomputernotes.com
  • 13. Using the && Substitution Variable Use the double-ampersand ( && ) if you want to reuse the variable value without prompting the user each time. SELECT employee_id, last_name, job_id, &&column_name FROM employees ORDER BY &column_name; « http://ecomputernotes.com
  • 14. 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; old 3: WHERE employee_id = &employee_num new 3: WHERE employee_id = 200 http://ecomputernotes.com
  • 15. Customizing the i SQL*Plus Environment "U se S ET c ommands to control current session. SET system_variable value "V erify what you have set by using the S H O W command. SET ECHO ON SHOW ECHO echo ON http://ecomputernotes.com
  • 16. 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 http://ecomputernotes.com
  • 17. i SQL*Plus Format Commands " COLUMN [ column option ] " TTITLE [ text | OFF | ON] " BTITLE [ text | OFF | ON] " BREAK [ON report_element ]
  • 18. The COLUMN Command Controls display of a column: COL[UMN] [{ column || alias } [ option ]]]] " CLE[AR]: Clears any column formats " HEA[DING] text : Sets the column heading "F OR[MAT] f ormat: Changes the display of the column using a format model " NOPRINT | PRINT " NULL
  • 19. Using the COLUMN Command "C reate column headings. COLUMN last_name HEADING 'Employee|Name' COLUMN salary JUSTIFY LEFT FORMAT $99,990.00 COLUMN manager FORMAT 999999999 NULL 'No manager' " Display the current setting for the LAST_NAME column. COLUMN last_name "C lear settings for the L AST_NAME c olumn. COLUMN last_name CLEAR
  • 20. COLUMN Format Models Element Description Example Result 9 Single zero-suppression 999999 1234 digit 0 Enforces leading zero 099999 001234 $ Floating dollar sign $9999 $1234 L Local currency L9999 L1234 Position of decimal point 9999.99 1234.00 , Thousand separator 9,999 1,234
  • 21. Using the BREAK Command Use the BREAK command to suppress duplicates. BREAK ON job_id
  • 22. Using the TTITLE and BTITLE Commands "D isplay headers and footers. tex t |OFF|ON] "S et the report header. T TITLE 'Salary|Report' "S et the report footer. BTITLE 'Confidential'
  • 23. Using the TTITLE and BTITLE Commands "D isplay headers and footers. TTI[TLE] [ text |OFF|ON] "S et the report header. TTITLE 'Salary|Report' "S et the report footer. BTITLE 'Confidential'
  • 24. 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.
  • 25. 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.