Presentation is loading. Please wait.

Presentation is loading. Please wait.

4 Copyright © 2004, Oracle. All rights reserved. Database Interfaces.

Similar presentations


Presentation on theme: "4 Copyright © 2004, Oracle. All rights reserved. Database Interfaces."— Presentation transcript:

1 4 Copyright © 2004, Oracle. All rights reserved. Database Interfaces

2 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 i SQL*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

3 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-4 Copyright © 2004, Oracle. All rights reserved. Using SQL There are several tools for interfacing with the database using SQL: Oracle SQL*Plus and i SQL*Plus Oracle Forms, Reports, and Discoverer Oracle Enterprise Manager Third-party tools

5 4-5 Copyright © 2004, Oracle. All rights reserved. Enterprise Manager: Seeing the SQL

6 4-6 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>

7 4-7 Copyright © 2004, Oracle. All rights reserved. What Is i SQL*Plus?

8 4-8 Copyright © 2004, Oracle. All rights reserved. What Is i SQL*Plus? Full Notes Page

9 4-9 Copyright © 2004, Oracle. All rights reserved. Using i SQL*Plus

10 4-10 Copyright © 2004, Oracle. All rights reserved. Describing Data

11 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)

12 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.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

13 4-13 Copyright © 2004, Oracle. All rights reserved. Joining Tables Getting data from more than one table

14 4-14 Copyright © 2004, Oracle. All rights reserved. Joining Tables Full Notes Page

15 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.

16 4-16 Copyright © 2004, Oracle. All rights reserved. Defining Data

17 4-17 Copyright © 2004, Oracle. All rights reserved. Overview of Transactions Transaction 1Transaction 2 COMMIT;

18 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

19 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.

20 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

21 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

22 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;

23 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

24 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

25 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 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:

26 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.

27 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)

28 4-28 Copyright © 2004, Oracle. All rights reserved. Other APIs Full Notes Page

29 4-29 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Use SQL*Plus and i SQL*Plus to access Oracle Database 10g Describe the logical structure of tables Use SQL to query, manipulate, and define data Identify common database interfaces

30 4-30 Copyright © 2004, Oracle. All rights reserved. Practice 4: Using SQL This practice covers using i SQL*Plus to: Describe tables Select from tables Update a table Delete from a table Undo changes

31 4-31 Copyright © 2004, Oracle. All rights reserved. Practice 4 – Using SQL Full Notes Page

32 4-32 Copyright © 2004, Oracle. All rights reserved.


Download ppt "4 Copyright © 2004, Oracle. All rights reserved. Database Interfaces."

Similar presentations


Ads by Google