Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 4701 Chapter 10-1 Chapter 10 6e: Oracle Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut 191.

Similar presentations


Presentation on theme: "CSE 4701 Chapter 10-1 Chapter 10 6e: Oracle Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut 191."— Presentation transcript:

1 CSE 4701 Chapter 10-1 Chapter 10 6e: Oracle Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut 191 Auditorium Road, Box U-155 Storrs, CT 06269-3155 steve@engr.uconn.edu http://www.engr.uconn.edu/~steve (860) 486 - 4818 n All of these slides are being used with the permission of Dr. Ling Lui, Associate Professor, College of Computing, Georgia Tech.

2 CSE 4701 Chapter 10-2 Oracle by Example n Oracle architecture n Online book store implementation l define a simple data model l use SQL*Plus to create the DB in Oracle l overview of commands to see structure l insert, update, and delete data l more advanced Oracle SQL l SQL*Plus shell features

3 CSE 4701 Chapter 10-3 Oracle Architecture

4 CSE 4701 Chapter 10-4 Data storage in Oracle n Database l tablespaces à schema objects F data files

5 CSE 4701 Chapter 10-5 Logging in n Log in to acme n Add to your.profile file export FMHOME=/usr/local/lib/frame export ORACLE_HOME=/usr/local/oracle/8.1.7 export ORACLE_SID=ccdb export LD_LIBRARY_PATH=$ORACLE_HOME/lib On the prompt, l {acme:gte113x:145}. oraenv l ORACLE_SID = [ccdb] ? ccdb l {acme:gte113x:145} sqlplus l will ask for your username and password à Default password is gtxxxxxDDMM à Should change the password after first use

6 CSE 4701 Chapter 10-6

7 CSE 4701 Chapter 10-7 Things to remember n Always terminate your command with a n Semicolon (;) n Exit sqlplus by entering quit or exit at the SQL> prompt n Commands can be in lower or upper case n To execute a host operating system command without leaving SQL*Plus, type host l SQL> HOST ls *.sql l SQL> sample1.sql sample2.sql

8 CSE 4701 Chapter 10-8

9 CSE 4701 Chapter 10-9 Help Index

10 CSE 4701 Chapter 10-10 n Book n Customer n Order n LineItem Relational Model ISBNAuthorTitlePublisherDatePrice Cust #NameEmailStreetCityStateZip Order #Cust#CardExp.Auth Order#Book# Date

11 CSE 4701 Chapter 10-11 Create Table

12 CSE 4701 Chapter 10-12 Schema Creation n Oracle schema’s are based on user-name l You only get one schema per user using other schema’s requires permission ( GRANT ’s)

13 CSE 4701 Chapter 10-13 Schema Creation - book

14 CSE 4701 Chapter 10-14 Schema Creation - customer

15 CSE 4701 Chapter 10-15 Schema Creation - order

16 CSE 4701 Chapter 10-16 Schema Creation - line_item

17 CSE 4701 Chapter 10-17 Oracle Data types n character data types : l char(x), max 256 bytes l varchar2(x), max 2000 bytes n numerical data: l number [(x, y)], length and precision l float[(b)], binary precision (up to 126) n long: up to 2GB l restricted: one long per table;no join n Date l century year month day hour min sec

18 CSE 4701 Chapter 10-18 Browsing the catalog n view table structure l DESC book n view your tables: l SELECT table_name from user_tables;

19 CSE 4701 Chapter 10-19 Browsing the catalog n view all objects l SELECT object_name, object_type, created from user_objects;

20 CSE 4701 Chapter 10-20 Insert n Insert command l insert into book values (‘0-201-63361-2’, ‘Smith’, ‘Oracle Basics’, ‘McNeil’, sysdate, 14.99); l insert into book (isbn, author, title, publisher, pub_date, price) values (‘0-201-63361-2’, ‘Smith’, ‘Oracle Basics’, ‘McNeil’, sysdate, 14.99); n What is the difference?

21 CSE 4701 Chapter 10-21 Inserted data

22 CSE 4701 Chapter 10-22 Updating data

23 CSE 4701 Chapter 10-23 Delete n Delete table with drop table l DROP TABLE customer; n Delete rows with delete from l DELETE FROM customer WHERE name = “Smith”; l DELETE FROM customer; n Permanently delete rows with truncate l TRUNCATE TABLE customer; à Faster: no DELETE triggers fired; no rollback available.

24 CSE 4701 Chapter 10-24 Commit and Rollback n Modifications of tuples are temporarily stored in the database n They become permanent after commit;statement has been issued n You can undo all modifications since last commit using rollback n Any data definition command like create results in implicit commit n Termination of Oracle session also executes implicit commit

25 CSE 4701 Chapter 10-25 Bulk Loading data Create a.sql file with insert statements l @filename.sql or start filename.sql n Use SQL*Loader % SQLLOAD / CONTROL=BOOK.CTL LOG=BOOK.LOG LOAD DATA INFILE book.dat APPEND INTO TABLE book FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' (isbn, author, title, publisher, pub_date DATE "DD-Month-YYYY", price)

26 CSE 4701 Chapter 10-26 Data file Example “0-201-63361-2”, “Smith”, “Oracle Basics”, “McNeil”, 17-April-2000, 14.99 “0-13-629825-7”, “Smith”, “Java Basics”, “AW”, 12-March-1998, 35

27 CSE 4701 Chapter 10-27 Log File

28 CSE 4701 Chapter 10-28 View Create a new view of data l CREATE VIEW clerk (id_number, person, department, position) AS SELECT empno, ename, deptno, job FROM emp WHERE job = 'CLERK’; n Why?

29 CSE 4701 Chapter 10-29 View Command

30 CSE 4701 Chapter 10-30 Constraints n Column constraints: l primary key l foreign key l NULL values l create table CUSTOMER (id NUMBER CONSTRAINT pk_cust PRIMARY KEY, name VARCHAR2(250), email VARCHAR2(60) CONSTRAINT nn_email NOT NULL, addr NUMBER CONSTRAINT fk_addr REFERENCES address(id));

31 CSE 4701 Chapter 10-31 Table Constraint Clause

32 CSE 4701 Chapter 10-32 Column Constraint Clause

33 CSE 4701 Chapter 10-33 Alter Table n Add a column, or integrity constraint n Remove an integrity constraint n Cannot rename or drop a column n Keep a copy of the SQL statements you use to create and alter tables l ALTER TABLE book MODIFY (price NUMBER(7,2)); l ALTER TABLE customer DROP PRIMARY KEY CASCADE;

34 CSE 4701 Chapter 10-34 Alter Table command

35 CSE 4701 Chapter 10-35 SQL*Plus Shell n Features: l scripting l variables l report formatting n Basics l commands end with a semi-colon, a single ‘/’, or two blank lines. l Repeat last command: ‘/’ l Comments begin with /* and end with */ l comments and semi-colons don’t co-exist

36 CSE 4701 Chapter 10-36 Formatting l SQL> SELECT * from user_tables;

37 CSE 4701 Chapter 10-37 Formatting l SQL> SELECT table_name, pct_free from user_tables;

38 CSE 4701 Chapter 10-38 SQL*Plus Display commands l COLUMN table_name HEADING table l COLUMN pct_free HEADING free l COLUMN table_name FORMAT A10 l SET UNDERLINE = l TTITLE CENTER ‘TABLE FREE SPACE’

39 CSE 4701 Chapter 10-39 Running commands from a file n SQL> GET filename loads a command file into the buffer n SQL> RUN executes the buffer n SQL> @filename loads and executes a command file n % sqlplus / @filename start sqlplus and immediately runs file n login.sql like.cshrc, configures environment with SQL*Plus shell commands

40 CSE 4701 Chapter 10-40 Oracle Errors n Oracle only provides an error number and a short message n To get an explanation: use oerr


Download ppt "CSE 4701 Chapter 10-1 Chapter 10 6e: Oracle Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut 191."

Similar presentations


Ads by Google