Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oracle Tutorial (CS4347) TA Information –Name: Lidong Wu – –Office Hour:Tu. 3pm-4pm & Fr.

Similar presentations


Presentation on theme: "Oracle Tutorial (CS4347) TA Information –Name: Lidong Wu – –Office Hour:Tu. 3pm-4pm & Fr."— Presentation transcript:

1 Oracle Tutorial (CS4347) TA Information –Name: Lidong Wu –Email: lidong.wu@utdallas.edu lidong.wu@utdallas.edu –Office Hour:Tu. 3pm-4pm & Fr. 4pm-5pm @ ECSS 4.209

2 Outlines 1.Connect Oracle Account 2.SQL Commands

3 Connect Oracle Account

4 Setup Oracle Account(win.) 1.You are assumed to have an account in the Unix system at UTD. 2.Oracle is available only on the machine csoracle.utdallas.edu. NOT APACHE. Login to csoracle at first.(either using PuTTY on windows, or ssh within Mac or Linux. )

5 Setup Oracle Account (cont.) 3a. Use putty to login csoracle.utdallas.edu  The free download is available at http://www.chiark.greenend.org.uk/~sgtatham/putty/downl oad.html The hostname is csoracle.utdallas.edu The port is 22 The Connection type is SSH. Enter a Saved Session Name, then click save Open

6 Setup Oracle Account (cont.) 3b. Oracle SQL Developer  The free download is available at http://www.oracle.com/technology/software/products/sql/i ndex.html.http://www.oracle.com/technology/software/products/sql/i ndex.html Enter a Connection Name, then enter your netId and password Set Role is default, connection type is basic The hostname is csoracle.utdallas.edu The port is 1521 The SID is student. Click test; the status should show up as Success. Connect

7 Setup Oracle Account (cont.) 4.Run "oam.pl“  The account name is same as your netid;  Don ’ t use the special characters for your password, just use the letters and digitals.

8 Setup Oracle Account 5.Setup environment variables:  Use "ps" command to check the login shell you are using. {csoracle:~} ps PID TTY TIME CMD 8974 pts/4 0:00 bash {csoracle:~}

9 Setup Oracle Account Edit the configuration file (csh/tcsh):add the following lines to your ".login" file: (sh/ksh/bash): ".bash_profile" for bash and ".profile" for sh/ksh: * bash: add the following lines to your ".bash_profile" file Logout the machine csoracle.utdallas.edu and login again Run "oam.pl" if you want to change the password if [ -f /oracle/env.sh ] then. /oracle/env.sh; fi if ( -f /oracle/env.csh ) then source /oracle/env.csh endif

10 Run sqlplus {csoracle:~} sqlplus SQL*Plus: Release 11.1.0.6.0 - Production on Thu Sep 9 14:08:47 2010 Copyright (c) 1982, 2007, Oracle. All rights reserved. Enter user-name: (netID) Enter password: (what you just set up) Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production With the Oracle Label Security and Data Mining options SQL>

11 Setup Oracle Account (Mac /Linux) 1.Use SSH to login csoracle.utdallas.edu  Choose ssh protocol and csoracle.utdallas.edu as host name

12 If such an error occurs Contact #2760 #Email: cs-tech@utdallas.educs-tech@utdallas.edu SQL*Plus: Release 8.1.7.0.0 - Production on Tue Sep 2 19:06:55 2003 (c) Copyright 2000 Oracle Corporation. All rights reserved. Enter user-name: yxh038100 Enter password: ERROR: ORA-12541: TNS:no listener Enter user-name:

13 SQL Command create drop alter insert update delete select Commit

14 Table & View Basic Structure of Table: Attribution1 Attribution2 Attribution3 … Tuple1: Attr_value Attr_value Attr_value Tuple2: Attr_value Attr_value Attr_value … Example of Relation between Table Table1(Department): Attr1(DeptNo), Attr2(DeptName), … Table2(Employee): Attr1(SSN), Attr2(DNo), … View is a mirror of Table, no record is stored in the view. From view, you could only access a subset of data in tables.

15 Create tables Grammar: create table Table_Name (Attribution_Name1 attribution_type, Attribution_Name2 attribution_type, … primary key (Attribution_Name) foreign key (Attribution_Name) reference ( Table_Name2) ); create view View_Name as select Attribution_Name1, Attribution_Name2,… from Table_Name where condition;

16 Create tables (Cont.) SQL> create table Merchandize (ItemID int, ItemType char(15), Price real, primary key (ItemID)); Table created. SQL> create view MerType as select ItemType from Merchandize where ItemID = 1; View created.

17 Create tables (Cont.) SQL> create table Electronics (ItemID int check (ItemID <= 10), BrandName char(15), Category char(15), primary key (ItemID), foreign key (ItemID) references Merchandize); Table created.

18 Alter Table SQL>alter table Electronics add ItemSize int; Table altered. Structure of Electronics: Previous: ItemID, BrandName, Category Current: ItemID, BrandName, Category, ItemSize

19 Insert record SQL>insert into Merchandize(ItemID, ItemType, Price) values(1, 'Electronics', 39.99); 1 Row created. Update records SQL>update Merchandize set Price=9.99 where ItemID=1 and ItemType= 'Electronics'; 1 Row updated. Let’s insert a few more records now…

20 select SQL>select ItemID, ItemType, Price from Merchandize where price > 39.99; SQL>select Merchandize.Price, Electronics.Category from Merchandize, Electronics where Merchandize. ItemID = Electronics.ItemID;

21 Delete all records SQL>delete from Merchandize; 1 Row deleted. SQL>delete from Merchandize where price > 9.99; Delete specific record(s)

22 Drop Table SQL>drop table Merchandize; Table dropped.

23 Other useful commands List all tables: List all fields in a table Submit the work SQL>select * from tab; SQL>describe mytable; SQL>commit;

24 Other useful commands(cont.) List only distinct (different) values : Sorts the records in ascending order by default: SQL> select distinct ItemType from Merchandize; SQL> select * from Merchandize order by ItemType;

25 Other useful commands(cont.) Returns the largest value of the selected column: SQL> select max(Price) as HighestPrice from Merchandize;

26 A transaction in Oracle All changes of data in an Oracle database can only be done within a transaction. A transaction must either be committed or rolled back.committedrolled back Data changed within a transaction is not visible to another session until it is committed.session

27 Store & Run commands in sql files Edit your sql commands and save it as a file, the file extension must be. sql, the file name should end with ". sql “ Put that file in your sqlplus working directory (it depends from where you run your sqlplus command). Run @myscript after login the sqlplus system

28 Examples of sql file Example 1: One sql command in a file The Table "Merchandize" will be created >vi create.sql create table Merchandize (ItemID char(6), ItemType char(15), Price real, primary key(ItemID)); SQL>@create;

29 Examples of sql file Example 2: many sql commands in one file Two records will insert into the table "Merchandize", then list all the records of the table " Merchandize ". >vi myscript.sql insert into Merchandize(ItemID, ItemType, Price) values(2,'Electronics', 39.99); insert into Merchandize(ItemID, ItemType, Price) values(4, 'Tools', 19.99); select * from Merchandize; SQL>@myscript;

30 Save the output Use sql command: All output result will be redirected to a.lst Close output redirection: "spool off" SQL>spool a SQL>spool off

31 Purge Recyclebin Use sql command to delete the garbage: SQL> BIN$4qjxjq0zKpPgQLAKDFxDqQ==$0 TABLE BIN$4qjxjq0mKpPgQLAKDFxDqQ==$0 TABLE BIN$4qjxjq0gKpPgQLAKDFxDqQ==$0 TABLE SQL>purge recyclebin

32 Check the error reason Example: Logout sqlplus and run "oerr ora 942" in linux System will output the cause of this error >oerr ora 942 SQL> drop table merchandize1; drop table merchandize1 * ERROR at line 1: ORA-00942: table or view does not exist

33 Review If you can not execute sqlplus, –Make sure you login in csoracle NOT apache –Make sure you have set oracle environment correctly If you can create oracle account but can not access oracle server, –Contact System administrator #2760 cs-tech@utdallas.edu –TA is NOT oracle administrator.

34 Students outside the UTD’s network Login apache.utdallas.edu Type in “ssh csoracle.utdallas.edu”

35 Useful links SQL Demo in Oracle –http://sqlzoo.net/http://sqlzoo.net/ –http://www.w3schools.com/sql/default.asphttp://www.w3schools.com/sql/default.asp


Download ppt "Oracle Tutorial (CS4347) TA Information –Name: Lidong Wu – –Office Hour:Tu. 3pm-4pm & Fr."

Similar presentations


Ads by Google