Download Oracle Database 10g: Administration Workshop I

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Database wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Navitaire Inc v Easyjet Airline Co. and BulletProof Technologies, Inc. wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Oracle Database wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
Database Interfaces
Copyright © 2004, Oracle. All rights reserved.
Objectives
After completing this lesson, you should be able to do
the following:
• Use SQL*Plus and iSQL*Plus to access the Oracle
Database 10g
• Describe the logical structure of tables
• Use SQL to query, manipulate, and define data
• Identify common database interfaces
4-2
Copyright © 2004, Oracle. All rights reserved.
What Is SQL?
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
SQL unifies all of the preceding tasks in one
consistent language.
4-3
Copyright © 2004, Oracle. All rights reserved.
Using SQL
There are several tools for interfacing with the
database using SQL:
• Oracle SQL*Plus and iSQL*Plus
• Oracle Forms, Reports, and Discoverer
• Oracle Enterprise Manager
• Third-party tools
4-4
Copyright © 2004, Oracle. All rights reserved.
Enterprise Manager: Seeing the SQL
4-5
Copyright © 2004, Oracle. All rights reserved.
What Is SQL*Plus?
•
•
Command-line tool
Used interactively or in batch mode
$ sqlplus /nolog
SQL*Plus: Release 10.1.0.2.0 - Production on Tue Feb
17 06:17:14 2004
Copyright (c) 1982, 2004, Oracle. All rights
reserved.
SQL> connect ric
Enter password:
Connected.
SQL> SELECT * FROM dual;
D
X
SQL>
4-6
Copyright © 2004, Oracle. All rights reserved.
What Is iSQL*Plus?
4-7
Copyright © 2004, Oracle. All rights reserved.
Using iSQL*Plus
4-9
Copyright © 2004, Oracle. All rights reserved.
Describing Data
4-10
Copyright © 2004, Oracle. All rights reserved.
Querying Data
The SELECT has three basic parts:
• The SELECT List
• The FROM clause
• The WHERE condition (optional)
4-11
Copyright © 2004, Oracle. All rights reserved.
Sorting the Data
SQL> SELECT last_name, department_id, phone_number
2 FROM employees
3 ORDER BY last_name;
LAST_NAME
DEPARTMENT_ID PHONE_NUMBER
--------------- ------------- -------------------Abel
80 011.44.1644.429267
Ande
80 011.44.1346.629268
Atkinson
50 650.124.6234
Austin
60 590.423.4569
Baer
70 515.123.8888
Baida
30 515.127.4563
Banda
80 011.44.1346.729268
4-12
Copyright © 2004, Oracle. All rights reserved.
Joining Tables
Getting data from more than one table
4-13
Copyright © 2004, Oracle. All rights reserved.
Manipulating Data
SQL>
2
3
4
5
6
7
INSERT INTO employees
(EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,
HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,
MANAGER_ID,DEPARTMENT_ID)
VALUES
(9999,'Bob','Builder','[email protected]',NULL,sysdate,
'IT_PROG’,NULL,NULL,100,90);
1 row created.
SQL> UPDATE employees SET SALARY=6000
2 WHERE EMPLOYEE_ID = 9999;
1 row updated.
SQL> DELETE from employees
2 WHERE EMPLOYEE_ID = 9999;
1 row deleted.
4-15
Copyright © 2004, Oracle. All rights reserved.
Defining Data
4-16
Copyright © 2004, Oracle. All rights reserved.
Overview of Transactions
Transaction 1
4-17
COMMIT;
Transaction 2
Copyright © 2004, Oracle. All rights reserved.
Transaction Control Statements
SQL> SELECT * FROM local_temp;
no rows selected
SQL> INSERT INTO local_temp VALUES
2 (SYSDATE, 76, 58);
1 row created.
SQL> SELECT * from local_temp;
TEMP_DATE
HI_TEMP
LO_TEMP
--------- ---------- ---------27-OCT-03
76
58
SQL> ROLLBACK;
Rollback complete.
SQL> SELECT * FROM local_temp;
no rows selected
4-18
Copyright © 2004, Oracle. All rights reserved.
Locking Data
Oracle Database 10g automatically locks data so that
only one user can make changes at a time.
4-19
Copyright © 2004, Oracle. All rights reserved.
Other Statement Categories
•
•
•
4-20
Session control statements: Manage the
properties of a user session
System control statement: Manages the properties
of an Oracle instance
Embedded SQL statements: SQL statements
within a procedural language program
Copyright © 2004, Oracle. All rights reserved.
What Is PL/SQL?
PL/SQL is a block-structured language, which extends
SQL with:
• Declarations:
– Variables
– Constants
– Cursors
•
Control structures:
– Conditional control
– Iterative control
– Sequential control
•
4-21
Error handling
Copyright © 2004, Oracle. All rights reserved.
Example PL/SQL Block
DECLARE
qty_on_hand NUMBER(5);
BEGIN
SELECT quantity INTO qty_on_hand FROM
inventory
WHERE product = 'TENNIS RACKET'
FOR UPDATE OF quantity;
IF qty_on_hand > 0 THEN -- check quantity
UPDATE inventory SET quantity = quantity - 1
WHERE product = 'TENNIS RACKET';
INSERT INTO purchase_record
VALUES ('Tennis racket purchased', SYSDATE);
ELSE
INSERT INTO purchase_record
VALUES ('Out of tennis rackets', SYSDATE);
END IF;
COMMIT;
END;
4-22
Copyright © 2004, Oracle. All rights reserved.
Uses of PL/SQL
Blocks of PL/SQL are used in:
• Anonymous blocks
• Functions
• Procedures
• Packages
• Triggers
• Object types
4-23
Copyright © 2004, Oracle. All rights reserved.
What Is Java?
Java is an industry-standard, object-oriented
programming language. It includes the following
concepts:
• A Java Virtual Machine (JVM), which provides
platform independence
• Automated storage management techniques
• Language syntax that borrows from C and
enforces strong typing
4-24
Copyright © 2004, Oracle. All rights reserved.
Oracle and Java
A PL/SQL function:
FUNCTION balance (acct_id NUMBER) RETURN NUMBER IS
acct_bal NUMBER;
BEGIN
SELECT bal INTO acct_bal FROM accts
WHERE acct_no = acct_id;
RETURN acct_bal;
END;
Calling the function with Java:
CallableStatement
cstmt = conn.prepareCall("{? = CALL balance(?)}");
cstmt.registerOutParameter(1, Types.FLOAT);
cstmt.setInt(2, acctNo);
cstmt.executeUpdate();
float acctBal = cstmt.getFloat(1);
4-25
Copyright © 2004, Oracle. All rights reserved.
What Is OCI?
OCI provides for:
• The Oracle Call Interface (OCI) is how all database
features are made accessible to application
developers.
• OCI makes scalable and high-performance
applications possible.
• Higher-level APIs and tools use OCI indirectly for
database access.
4-26
Copyright © 2004, Oracle. All rights reserved.
Other APIs
•
•
•
•
•
•
•
4-27
Java Database Connectivity (JDBC)
Pro*C/C++
Pro*COBOL
Oracle C++ Interface (OCCI)
Open Database Connectivity (ODBC)
Oracle Data Provider for .NET (ODP.NET)
Oracle Objects for OLE (OO4O)
Copyright © 2004, Oracle. All rights reserved.
Summary
In this lesson, you should have learned how to:
• Use SQL*Plus and iSQL*Plus to access Oracle
Database 10g
• Describe the logical structure of tables
• Use SQL to query, manipulate, and define data
• Identify common database interfaces
4-29
Copyright © 2004, Oracle. All rights reserved.
Practice 4: Using SQL
This practice covers using iSQL*Plus to:
• Describe tables
• Select from tables
• Update a table
• Delete from a table
• Undo changes
4-30
Copyright © 2004, Oracle. All rights reserved.