4 copyright © 2004, oracle. all rights reserved. database interfaces
Post on 26-Dec-2015
223 Views
Preview:
TRANSCRIPT
4Copyright © 2004, Oracle. All rights reserved.
Database Interfaces
4-2 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-3 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-4 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-5 Copyright © 2004, Oracle. All rights reserved.
Enterprise Manager: Seeing the SQL
4-6 Copyright © 2004, Oracle. All rights reserved.
What Is SQL*Plus?
• Command-line tool
• Used interactively or in batch mode
$ sqlplus /nologSQL*Plus: Release 10.1.0.2.0 - Production on Tue Feb 17 06:17:14 2004Copyright (c) 1982, 2004, Oracle. All rights reserved.SQL> connect ricEnter password:Connected.SQL> SELECT * FROM dual;
D-XSQL>
4-7 Copyright © 2004, Oracle. All rights reserved.
What Is iSQL*Plus?
4-9 Copyright © 2004, Oracle. All rights reserved.
Using iSQL*Plus
4-10 Copyright © 2004, Oracle. All rights reserved.
Describing Data
4-11 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-12 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.429267Ande 80 011.44.1346.629268Atkinson 50 650.124.6234Austin 60 590.423.4569Baer 70 515.123.8888Baida 30 515.127.4563Banda 80 011.44.1346.729268
4-13 Copyright © 2004, Oracle. All rights reserved.
Joining Tables
Getting data from more than one table
4-15 Copyright © 2004, Oracle. All rights reserved.
Manipulating Data
SQL> INSERT INTO employees 2 (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER, 3 HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT, 4 MANAGER_ID,DEPARTMENT_ID) 5 VALUES 6 (9999,'Bob','Builder','bob@abc.com',NULL,sysdate, 7 '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-16 Copyright © 2004, Oracle. All rights reserved.
Defining Data
4-17 Copyright © 2004, Oracle. All rights reserved.
Overview of Transactions
Transaction 1 Transaction 2COMMIT;
4-18 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-19 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-20 Copyright © 2004, Oracle. All rights reserved.
Other Statement Categories
• 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
4-21 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
• Error handling
4-22 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-23 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-24 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-25 Copyright © 2004, Oracle. All rights reserved.
Oracle and Java
A PL/SQL function:
CallableStatement cstmt = conn.prepareCall("{? = CALL balance(?)}"); cstmt.registerOutParameter(1, Types.FLOAT); cstmt.setInt(2, acctNo); cstmt.executeUpdate();float acctBal = cstmt.getFloat(1);
FUNCTION balance (acct_id NUMBER) RETURN NUMBER ISacct_bal NUMBER;BEGIN SELECT bal INTO acct_bal FROM accts WHERE acct_no = acct_id; RETURN acct_bal;END;
Calling the function with Java:
4-26 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-27 Copyright © 2004, Oracle. All rights reserved.
Other APIs
• 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)
4-29 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-30 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
top related