Using Oracle. Oracle Resides on Certain CPUs Computers in the GradLab Computers in ICL4 Hilly.cs.rit.edu Holly.cs.rit.edu Queeg.cs.rit.edu Log into one.

Slides:



Advertisements
Similar presentations
7 Copyright © Oracle Corporation, All rights reserved. Producing Readable Output with i SQL*Plus.
Advertisements

Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Winter 2002Judy Cushing8–1 Schedule Jan. 30 (Wed) u Modifications, Schemas, Views. Read Sections This Week (Feb 4ff) u Constraints Read Sections.
Fundamentals, Design, and Implementation, 9/e Chapter 10 Managing Databases with Oracle 9i.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Database Modifications A modification command does not return a result as a query does, but it changes the database in some way. There are three kinds.
Creating Database Tables © Abdou Illia MIS Spring /21/2015.
Database objects User schema DCL Oracle dictionary.
7/2/2015Murali Mani -- CS5421 Database Management Systems DB Application Development Project Statement + Introduction to Oracle.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Oracle SQL*plus John Ortiz. Lecture 10SQL: Overview2 Overview  SQL: Structured Query Language, pronounced S. Q. L. or sequel.  A standard language for.
Using SQL Queries to Insert, Update, Delete, and View Data © Abdou Illia MIS Spring 2015 Wednesday 1/28/2015 Chapter 3A.
SQL Query Extras MIS 433. Rerunning the last Query n Type the forward slash “/” to rerun the last query that was entered.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
ORACLE ONLINE TRAINING Contact our Support Team : SOFTNSOL India: Skype id : softnsoltrainings id:
Oracle Data Definition Language (DDL)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 10-1 David M. Kroenke’s Chapter Ten: Managing Databases with Oracle Database.
SQL functions - numeric and date Speaker notes contain additional information!
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
1 An Introduction to SQL. 2 Objectives  Understand the concepts and terminology associated with relational databases  Create and run SQL commands 
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University 1 Basic SQL Statements Oracle/SQL Plus Commands Kroenke, 11 th ed., Chapter Two.
Winter 2006Keller Ullman Cushing8–1 Turning in Assignments Please turn in hard copy (use only in the direst of circumstances). I am not your secretary.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
ISYS 365 – SQL*Plus Environment. 2 Agenda What is SQL*Plus? Command Line Editor Useful SQL*Plus Commands Useful System Tables What is PL/SQL? PL/SQL Constructs.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1 Creating and Modifying Database Objects. 2 An Oracle database consists of multiple user accounts Each user account owns database objects Tables Views.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
Personal Oracle8i Create a new user Create a new table Enter data into a new table Export & import data Start and exit SQL Plus SQL Plus Syntax.
Fundamentals, Design, and Implementation, 9/e COS 346 DAY 20.
ITBIS373 Database Development Lecture 3a - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Chapter 3 Selected Single-Row Functions and Advanced DML & DDL.
PL/SQL Oracle's Database Programming Language. Remember: Set serveroutput on With serveroutput off (default) executing procedure: With serveroutput on:
A Guide to SQL, Seventh Edition. Objectives Understand how to use functions in queries Use the UPPER and LOWER functions with character data Use the ROUND.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
1 Very basics on DB access Elke A. Rundensteiner.
Copyright  Oracle Corporation, All rights reserved. 8 Producing Readable Output with SQL*Plus.
1 Chapter 2: Creating and Modifying Database Objects.
Sql DDL queries CS 260 Database Systems.
Personal Oracle8i Create a new user Create a new table Enter data into a new table Export & import data Start and exit SQL Plus SQL Plus Syntax.
Oracle 9i. Agenda Start and exit SQL Plus (General) Start and exit SQL Plus (Tah 1006) Syntax Create a new user Create a new table Enter data into a new.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Managing Database With Oracle Replacement for Ch10 COP 4708.
© 2007 by Prentice Hall2-1 Introduction to Oracle 10g Chapter 2 Overview of SQL and SQL*Plus James Perry and Gerald Post.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Oracle PL/SQL SQL*Plus. EDIT Opens notepad with the buffer contents To use type: –Edit –Ed Opens notepad with the buffer contents To use type: –Edit –Ed.
Basic SQL*Plus edit and execute commands SQL*Plus buffer and built-in editor holds the last SQL statement Statements are created in free-flow style and.
Command-line Oracle Logon to your ORACLE account using the instructions contained in this slideshow. Create the tables with your last name in place of.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
CSE 4701 Chapter 10-1 Chapter 10 6e: Oracle Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut 191.
D Copyright © 2009, Oracle. All rights reserved. Using SQL*Plus.
SQL Tutorial CPSC 608 Database System. Connecting to Oracle Your username is identical to your UNIX account To access your Oracle account, you need to.
3 A Guide to MySQL.
Chapter 5 Introduction to SQL.
A Guide to SQL, Seventh Edition
SQL and SQL*Plus Interaction
Using SQL*Plus.
Using SQL*Plus.
ORACLE SQL Developer & SQLPLUS Statements
ORACLE.
Contents Preface I Introduction Lesson Objectives I-2
Using SQL*Plus.
Presentation transcript:

Using Oracle

Oracle Resides on Certain CPUs Computers in the GradLab Computers in ICL4 Hilly.cs.rit.edu Holly.cs.rit.edu Queeg.cs.rit.edu Log into one of these machines to work on Oracle

Set up Oracle Environment Variables source /usr/local/bin/coraenv –(if using bash, file is oraenv ) ORACLE_SID –Oracle system identifier ORACLE_HOME –Top level directory of the Oracle system hierarchy PATH –Path to ORACLE_HOME/bin Insert batch version of coraenv at the end of your.cshrc file: –The batch version is on our ClassNotes page in file oracleEnv –Example.cshrc file is on our ClassNotes page in file example.cshrc

Starting sqlplus SQL*Plus: Release Production on Tue Dec 16 14:56: Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Enter password: Connected to: Oracle9i Release bit Production JServer Release Production SQL>

Change your password SQL> password Changing password for chr Old password: New password: Retype new password: Password changed SQL>

Executing a file of SQL fileOfCommands.sql fileOfCommands SQL> run fileOfCommands.sql

“Getting” a file of SQL SQL> get q76.sql 1 select s.name from sailors s 2 where not exists 3 (select s2.name from sailors s2 4 where s.rating > s2.rating 5* and s2.age < 21) SQL> list 1 select s.name from sailors s 2 where not exists 3 (select s2.name from sailors s2 4 where s.rating > s2.rating 5* and s2.age < 21) SQL> / NAME Jones Moby SQL>

Editing the sqlplus buffer LIST shows the command buffer, and makes the last line in the buffer the "current" line LIST n prints line n of the command buffer, and makes line n the current line LIST m n prints lines m through n, and makes line n the current line INPUT enters a mode that allows you to input text following the current line; you must terminate the sequence of new lines with a pair of "returns" CHANGE /old/new replaces the text "old" by "new" in the current line APPEND textappends "text" to the end of the current line DELdeletes the current line

Using an editor to modify the sqlplus buffer Default editor is vi : SQL> edit Use a different editor of your choice: SQL> DEFINE _EDITOR = "emacs" SQL> edit

Recording a sqlplus session SQL> spool fileForRecording.txt SQL> select * from BasicCustomerData; NAME ARE PHONE Chris Wilkens David Smith Donald G. Gray Fred Smathers Jack Jones Jeffrey Janes Lynda Johnson Mary Beth Frederick rows selected. SQL> spool off SQL>

Issuing a Unix command from within sqlplus SQL> !cat fileForRecording.txt SQL> select * from BasicCustomerData; NAME ARE PHONE Chris Wilkens David Smith Donald G. Gray Fred Smathers Jack Jones Jeffrey Janes Lynda Johnson Mary Beth Frederick rows selected. SQL> spool off SQL>

sqlplus help SQL> help topics … SQL> help index … SQL> set pause on SQL> help column COLUMN Specifies display attributes for a given column, such as: - column heading text - column heading alignment - data format - column data wrapping Also lists the current display attributes for a single column or all columns. …

Accessing DB metadata SQL> select table_name from user_tables; TABLE_NAME ARTIST ART_CUSTOMER CUSTOMER CUSTOMER_ARTIST_INT INVENTORY MDC_CUSTOMER MDC_ORDER_ITEM MDC_SALES_ORDER MDC_SERVICE MI_PURCHASE MI_SHIPMENT

Accessing DB metadata (cont.) SQL> describe artist; Name Null? Type ARTISTID NOT NULL NUMBER(9) NAME NOT NULL CHAR(25) NATIONALITY CHAR(30) BIRTHDATE NUMBER(4) DECEASEDDATE NUMBER(4) SQL>

Help with Oracle errors

Setting linesize (default = 80) SQL> select * from artist; ARTISTID NAME NATIONALITY BIRTHDATE DECEASEDDATE Miro Spanish Kandinsky Russian SQL> set linesize 150; SQL> select * from artist; ARTISTID NAME NATIONALITY BIRTHDATE DECEASEDDATE Miro Spanish Kandinsky Russian

Setting pagesize (default = 24 lines) Turns off all headings, titles and page-breaks: SQL> set pagesize 0 Sets pagesize to 50 lines per page: SQL> set pagesize 50

Setting column format SQL> column nationality format A8; SQL> select * from artist; ARTISTID NAME NATIONAL BIRTHDATE DECEASEDDATE Miro Spanish Kandinsky Russian

Setting personal defaults with login.sql Contents of file login.sql in sqlplus starting directory: set pagesize 0 set linesize 190 define _editor=vi set serveroutput on

Most common Oracle data types Varchar2 –Same as Varchar Char Number( precision, scale ) –Precision = no. of digits –Scale = no. of digits to right of decimal Date –DD-Mon-YY default format –TO_DATE( ’02/12/1948’, ‘MM/DD/YYYY’ )

CREATE TABLE CREATE TABLE SAILORS (SailorID NUMBER(4) Not Null, Name Char(20) Not Null, Rating NUMBER(2), Age NUMBER(3), CONSTRAINT SailorsPK PRIMARY KEY (SailorID)); CREATE TABLE SAILORS (SailorID NUMBER(4) Not Null CONSTRAINT SailorsPK PRIMARY KEY, Name Char(20) Not Null, Rating NUMBER(2), Age NUMBER(3), ); Using table-level constraints: Using column-level constraints:

Adding constraints to tables ALTER TABLE SAILORS ADD CONSTRAINT SailorsAK UNIQUE Name; Viewing constraints SELECT CONSTRAINT_NAME, TABLE_NAME FROM USER_CONSTRAINTS ORDER BY TABLE_NAME; SELECT CONSTRAINT_NAME, COLUMN_NAME FROM USER_CONS_COLUMNS WHERE TABLE_NAME = ‘Sailors’;

Creating an Oracle Sequence (for use as surrogate key) DROP SEQUENCE CustomerSeq; DROP SEQUENCE ArtistSeq; DROP SEQUENCE WorkSeq; DROP SEQUENCE TransSeq; CREATE SEQUENCE CustomerSeq START WITH 1000; CREATE SEQUENCE ArtistSeq START WITH 1; CREATE SEQUENCE WorkSeq START WITH 500; CREATE SEQUENCE TransSeq INCREMENT BY 10 START WITH 100;

Adding data to tables Insert Into TRANSACTION Values (TransSeq.nextval, '27-FEB-1974', 8750, '18-MAR-1974', 18500, 20000, 1003, 500); Insert Into ARTIST Values (ArtistSeq.nextval, 'Klee', 'German', 1900, null); Insert Into ARTIST Values( ArtistSeq.nextval, &name, &nationality, &birthdate, &deceaseddate); Enter value for name: Magoo Enter value for nationality: Russian Enter value for birthdate: 1939 Enter value for deceaseddate: NULL / Using substitution variables (&)

25 A note on Oracle’s table ‘DUAL’ DUAL is a table owned by SYS that has only 1 row, and only 1 column called ‘dummy’. The single field contains the single character X. To understand the SQL, note the following: SQL> select * from tab1; ENO Now if you select an expression, say 1, from tab1 SQL> select 1 from tab1; If you select an expression a+b from tab1 SQL> select 'a+b' from tab1; 'A+ --- a+b a+b a+b Since DUAL has only 1 row, we can conveniently Use it to return single values: SQL> select SYSDATE from DUAL; SYSDATE APR-05 SQL> select 25000*.25 from DUAL; 25000* SQL> select CustomerID.nextVal from DUAL; NEXTVAL Adapted from Indira Aramandla on

Single-row Character Functions UPPER(‘Reynolds’)  ‘REYNOLDS’ LOWER(‘Reynolds’)  ‘reynolds’ INITCAP(‘carl reynolds’)  ‘Carl Reynolds’ SELECT name FROM Customer WHERE UPPER(state) = ‘NY’; SUBSTR(‘Carl Henry’, 7, 4)  ‘enry’ INSTR(‘Reynolds’, ‘o’)  5 TRIM(‘o’ FROM ‘oh no’)  ‘h n’ LTRIM(‘ ’, ‘0’)  ‘47.45’ RTRIM(‘foo’, ‘o’)  ‘f’ LPAD(‘Main Point’, 12, ‘*’)  ‘**Main Point’ RPAD(‘Carl’, 10, ‘ ‘) || ‘R’  ‘Carl R’ REPLACE(‘Carl Henry Reynolds’, ‘Henry’, ‘H’)  ‘Carl H Reynolds’ SQL> select RPAD('Carl', 10, ' ') || 'R' from dual; RPAD('CARL' Carl R

Single-row Numeric Functions ROUND(3.141, 2)  3.14 CEIL(3.141)  4 FLOOR(3.141)  3 TRUNC(99.999, 1)  99.9 POWER(5, 3)  125 ABS(-14)  14 MOD(12, 5)  2 SIGN(-48.4)  -1 SIGN(15)  1 SIGN(0)  0 SQL> select ceil(3.141) from dual; CEIL(3.141)

Date Functions EXTRACT(year|month|day FROM date) EXTRACT(year FROM SYSDATE)  2006 Date1 – Date2  Number of days between SQL> select to_date('12-dec-05') - to_date('31-oct-05') from dual; TO_DATE('12-DEC-05')-TO_DATE('31-OCT-05') ROUND(date, ‘MONTH’|’YEAR’) SQL> select sysdate, round(sysdate,'month') from dual; SYSDATE ROUND(SYS JAN FEB-06

Displaying dates TO_CHAR(number|date, ‘format’) 1 select sysdate, to_char(sysdate, 'Q') as quarter, 2 to_char(sysdate, 'DAY') as day, 3 to_char(sysdate, 'DDTH') as th, 4* to_char(sysdate, 'DDD') as DOY from dual SQL> / SYSDATE Q DAY TH DOY JAN-06 1 WEDNESDAY 18TH 018

Dealing with NULL values NVL(column, replacementValue) NVL(payoff, 0) NVL(hire_date, ’01-JAN-2006’) NVL2(column, ifNotNull, ifNull) SQL> select name, nvl2(deceaseddate, 'dead', 'alive') from artist; NAME NVL2( Miro dead Kandinsky dead Frings dead Klee alive Moos alive

Creating Aliases for Long Names CREATE SYNONYM FOR ; CREATE SYNONYM customer FOR jbr2389.customer; Now: SELECT * FROM customer Simpler than other form: SELECT * FROM jbr2389.customer DROP SYNONYM ; DROP SYNONYM customer;

Remember: Set serveroutput on With serveroutput off (default): With serveroutput on: Was it successful or not?!?!?! SQL> Execute Record_Sale( 'Dick Cheney', 'Cezanne', 'kindergarten', '8', 3550, :vReturn); PL/SQL procedure successfully completed. SQL> Execute Record_Sale( 'Dick Cheney', 'Cezanne', 'kindergarten', '8', 3550, :vReturn); Entered stored procedure Looking up CustomerID Looking up ArtistID Finding Work record Finding Transaction record Testing to see if a Transaction record was found No valid Transaction record exists. Transaction not completed. PL/SQL procedure successfully completed.