Professional Documents
Culture Documents
Producing Readable Output With iSQL Plus
Producing Readable Output With iSQL Plus
with iSQL*Plus
Objectives
After completing this lesson, you should be abke to do the following
I want to query
different values.
…SAL = ?
…DEPTNO =?
..,JOB=?
Using iSQL*Plus, you can create reports that prompt the user to supply their own
values to restrict the range of data returned by using substitution variables.
You can embed substitution variables in a command file or in a single SQL statement.
A varaible can be thought as a container in which the values are temporarily stored.
When the statement is run, the value is substituded.
SELECT empno,ename,sal,deptno
FROM emp Variable as a number
WHERE empno=&employee number;
Character and Date Values with Substitution Variables
SELECT empno,ename,sal,deptno
FROM emp Variable as a Character or Date
WHERE job='&job';
Specifying Column Names, Expressions, and Text
•WHERE conditions
•ORDER BY clauses
•Column Expressions
•Table names
•Entire SELECT statements
Not only can you use the substitution variables in the WHERE clause of an SQL
Statement, but these variables can also be used to substitute for column names,
Expressions, or text.
SELECT empno,&COLUMN_NAME
FROM emp
WHERE &CONDITION ;
SELECT empno,ename,job,&COLUMN_NAME
FROM emp
WHERE &CONDITION
ORDER BY &ORDER_COLUMN;
SELECT empno,ename,job,&COLUMN_NAME
FROM emp
WHERE &CONDITION
ORDER BY &ORDER_COLUMN;
Defining Substitution Variables
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.
Command Description
DEFINE variable=value Create a user variable with the CHAR data and
assigns a value to it.
DEFINE variable Displays the variable, its value,and its data type
SET VERIFY ON
SELECT empno,ename,sal,deptno
FROM emp
WHERE empno=&employee_number;
This is displayed if
VERIFY is ON
Using the VERIFY Command
COLUMN
TTITLE
BTITLE
BREAK
The COLUMN command
OPTIONS DESCRIPTIONS
CLEAR Clears any column formats
HEADING Sets the column heading
FORMAT Changes the display of the column data
NOPRINT Hide the columns
NULL Specifies text to be displayed for null values
PRINT Shows the columns
COLUMN FORMAT MODEL
Break on deptno ;
CLEAR BREAK
HEADERS AND FOOTERS
TITLE ON BTITLE ON
TTITLE OFF BTITLE OFF
BTITLE ‘CONFIDENTAL’
TTITLE 'EMPLOYEES LIST'
BTITLE 'CONFIDENTAL'
SELECT * FROM EMP;
TASKS
1-Determine whether the following two statements are true or false
DEFINE & X =100
TRUE FALSE
2-DEFINE command is an SQL command
TRUE FALSE
3-Write a script to display the ename, job , and hiredates for all employees who started
within a given range of dates. Concatenate the name and job together, separated by a
space and comma, and label the column Employees. Use the DEFINE command to
provide the two ranges. Use the format DD/MON/YYYY
DEFINE lowdate=01/JAN/1980
DEFINE highdate=01/JAN/1981
4-Write a script to display the ename, job, and department names for every employee in
a given location. Search condition should allow for case-intensive searches of the
department location.
5-Modiyf the code of task 4 to create a report containing the department name,
employee name, hiredate, salary and, and ANNUAL SALARY.