SQL Plus: PL/SQL Blocks On The Results of A Query in The Form of Reports
SQL Plus: PL/SQL Blocks On The Results of A Query in The Form of Reports
•The Oracle Corporation also supplies interface tools to access data stored in
an Oracle database
•SQL * Plus is a Oracle utility that recognizes SQL commands and sends these
commands to Oracle server for execution.
•SQL*Plus – A command line tool used to manipulate tables and other
database objects in an Oracle database
DESCRIBE EMPLOYEES
Viewing EMPLOYEES Table Data with
SQL*Plus
COLUMN FIRST_NAME FORMAT A20
COLUMN LAST_NAME FORMAT A25
COLUMN PHONE_NUMBER FORMAT A20
DESCRIBE EMPLOYEES
schema
• A schema is a collection of database objects that
can include: tables, views, indexes and
sequences.
• By default, each user has their own the schema
which has the same name as the Oracle
username. For example, a single Oracle database
can have separate schemas for HOLOWCZAK,
JONES, JSHIH, SMITH and GREEN
• Any object in the database must be created in
only one schema. The object name is prefixed by
the schema name as in: schema.object_name
Schema
A schema is a collection of logical structures of data,
called schema objects.
12
Schema objects
-Tables
-Indexes
-Constraints
… but also (in ORACLE)
-Links
-Views
-Triggers
-Operators
-Sequences
-Stored functions
-Stored procedures
-Synonyms
…and more
13
• By default, all objects are created in the user’s
own schema
• If JONES creates an EMPLOYEE table, the full
name of the table becomes: JONES.EMPLOYEE
Unlocking the Sample Tables
Eg:
• Select query on emp table
SQL> select empno,ename,job,hiredate,sal
from emp
order by 2;
Changing Page size
• Eg
• SQL>1
• Changing column listing
Eg: Change empno to deptno
SQL>c/empno/deptno
Formatting a column
• Eg: format col sal to $999,999.00 format
Eg
SQL> 1
SQL > c/empno/deptno
Formatting Output
• Changing date format to mm/dd/yyyy
• Eg
• SQL> col job format a15
• Redoing formatting
• SQL>help define
SQL
• Structured Query Language (SQL) is the set of
statements with which all programs and users
access data in an Oracle database
• SQL Standards
• industry-accepted committees are the
American National Standards Institute (ANSI)
and the International Organization for
Standardization (ISO)
• SQL provides statements for a variety of tasks,
including:
• Querying data
• Inserting, updating, and deleting rows in a table
• Creating, replacing, altering, and dropping
objects
• Controlling access to the database and its objects
• Guaranteeing database consistency and integrity
Data Manipulation Language
Statements
• Retrieve or fetch data from one or more tables or views
(SELECT);
• Add new rows of data into a table or view (INSERT).
• Change column values in existing rows of a table or view
(UPDATE).
• Update or insert rows conditionally into a table or view
(MERGE).
• Remove rows from tables or views (DELETE).
• View the execution plan for a SQL statement (EXPLAIN
PLAN).
• Lock a table or view, temporarily limiting other users'
access (LOCK TABLE).
• Some examples of DML statements are:
– SELECT last_name, manager_id, commission_pct +
salary FROM employees;
– INSERT INTO employees VALUES (1234, 'DAVIS',
'SALESMAN', 7698, '14-FEB-1988', 1600, 500, 30);
DELETE FROM employees WHERE last_name IN
('WARD','JONES');
Displaying Selected Columns Under New
Headings
• [use hr schema]
SELECT LAST_NAME,
SALARY "Monthly Pay",
SALARY * 12 "Annual Pay"
FROM EMPLOYEES
WHERE DEPARTMENT_ID = 90
ORDER BY SALARY DESC;
Using an Arithmetic Expression in
a Query
select last_name,salary as "Monthy Pay",salary *
12 as "Annual Pay"
from employees
where department_id=90
order by salary desc
Using Numeric Functions in
Queries
select last_name,salary as "Monthy
Pay",round((salary * 12)/365,2) as "Daily Pay"
from employees
where department_id=100
order by salary desc