SQL in Oracle.

Slides:



Advertisements
Similar presentations
Data Definition Language (DDL)
Advertisements

CC SQL Utilities.
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
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.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
This course has taken from This unique introductory SQL tutorial not only provides easy-to-understand SQL instructions, but it allows.
CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song.
1 Table Alteration. 2 Altering Tables Table definition can be altered after its creation Adding columns Changing columns’ definition Dropping columns.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
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.
DML- Insert. DML Insert Update Delete select The INSERT INTO Statement The INSERT INTO statement is used to insert new rows into a table. Syntax INSERT.
ORACLE Using ORACLE 8 SQL using ORACLE 8 PL/SQL using ORACLE 8.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
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.
Database control Introduction. The Database control is a tool that used by the database administrator to control the database. To enter to Database control.
Concepts of Database Management Seventh Edition
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
SQL FUNDAMENTALS SQL ( Structured Query Language )
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1 A Guide to SQL Chapter 2. 2 Introduction Mid-1970s: SQL developed under the name SEQUEL at IBM by San Jose research facilities to be the data manipulation.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
1 Writing Basic SQL Statements. 1-2 Objectives At the end of this lesson, you should be able to: List the capabilities of SQL SELECT statements Execute.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
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.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
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.
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.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
D Copyright © 2009, Oracle. All rights reserved. Using SQL*Plus.
Oracle: Programming Languages SQL and PL/SQL Introduction Toomas Lepikult
Dept. of Computer & Information Sciences
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
3 A Guide to MySQL.
CIT 214 Introduction to Database Management
How to: SQL By: Sam Loch.
Web Systems & Technologies
CS 3630 Database Design and Implementation
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
SQL and SQL*Plus Interaction
Using SQL*Plus.
SQL in Oracle.
Using SQL*Plus.
ORACLE SQL Developer & SQLPLUS Statements
STRUCTURED QUERY LANGUAGE
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
CS4222 Principles of Database System
Using SQL*Loader The SQL*Loader command needs to be run from a DOS window or NT. The SQL*Loader uses the following three files: control file: contains.
Introduction To Structured Query Language (SQL)
CMPT 354: Database System I
Yong Choi School of Business CSU, Bakersfield
ORACLE.
Introduction To Structured Query Language (SQL)
Using SQL*Plus.
CS3220 Web and Internet Programming SQL and MySQL
SQLPLUS: Oracle SQL Interface
CS3220 Web and Internet Programming SQL and MySQL
Turn on spool and save to file a.txt
Introduction to Oracle
Presentation transcript:

SQL in Oracle

Basic commands in SQL Create Creates a table, view, domain, etc. Drop Drops a table, view, domain, etc. Insert Adds a row of data to a table or view. Delete Deletes rows of data from table. Update Changes data in a table or view. Select Retrieves rows from a table or view.

Insertions Insert a record into a table INSERT INTO students (sid, name, age, gpa) VALUES (12, ‘Mike Patton’, 19, 3.4) Insert results of query into a table INSERT INTO tablename (attr1, attr2, …) SELECT … FROM … WHERE …;

Example Employee (ssn, fname, minit, lname, address, salary) Department (dno, dname, mgrssn) Manager (ssn, fname, minit, lname, dname) INSERT INTO managers SELECT mgrssn, fname, minit, lname, dname FROM employee, department WHERE mgrssn = ssn;

Basic Data Types char(size) Stores fixed-length character data, with a maximum size of 2,000. varchar(size) Stores variable-length character data, with a maximum size of 4,000. number(l) Stores numeric data for integers, where “l” stands for the number of digits. number(l,d) Stores numeric data for floats, where “l” stands for the number of digits before the decimal point, and “d” for the number of decimal digits. Date Stores dates from January 1,4712 B.C. to December 31, 9999 A.D. (e.g.: 21-NOV-1996)

Basic SQL*plus Commands Purpose RUN Lists and executes the SQL command or PL/SQL block currently stored in the SQL buffer START Executes the contents of the specified command file (.sql) SAVE Saves the contents of the SQL buffer in a host operating system file (a command file) GET Loads a host operating system file into the SQL buffer DESCRIBE (DESC) Lists the column definitions for the specified table, view, or synonym or the specifications for the specified function or procedure LIST Lists one or more lines of the SQL buffer EDIT Invokes a host operating system text editor on the contents of the specified file or on the contents of the buffer PASSWORD Allows you to change a password of the SQL*plus account

Getting Help To get online help for SQL commands, type HELP at the command prompt followed by the name of the command. SQL>HELP CREATE To get all the commands in the system: SQL>HELP COMMAND

A Complete Example Step1: Execute contents in file SQL> start createall.sql Step2: see the all the tables or views SQL> select * from tab; Step3: Describe table SQL> describe customer

Cont. Step4: type the SQL command to buffer SQL>select firstname, lastname, orderid 2 from customer, order_ 3 where customer.customerid = order_.customerid Step5: edit the SQL buffer SQL>edit Step6: Execute the SQL in buffer SQL> run or SQL>/

Cont. Step7: Show the contents in SQL buffer SQL> list Step8: Save SQL Buffer to File SQL> save try Step9: Read buffer from File SQL> get try Step10: append SQL Buffer to the end of the File SQL> save try app

Insert data into tables (data.sql) /* Customer Table */ insert into customer values(9,'Brad','Pitt','(237) 369-8524','Morgan Street','Apt. 12','Minneapolis','MN','78922'); insert into customer values(10,'Bart','Simpson','(706) 852-9874','Box 9874',NULL,'Reading','MA','96521'); /* Product Table */ insert into product values(1,'Microsoft SQL Sever 2000','Microsoft',1500,1800); insert into product values(2,'Oracle 8i Server','Oracle Corporation',7000,9500); /* Order Table */ insert into order_ values(1,to_date('12-AUG-2000'),1); insert into order_ values(2,to_date('15-JUL-2000'),6);

SQL*Loader SQL*Loader loads data from external files into tables of an Oracle database.

A simple control file (customer.ctl) LOAD DATA INFILE * INTO TABLE customer FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (customerID, firstName, lastName, phone, address1, address2, city, state, zip) BEGINDATA 1, Zhen, Liu, (662) 325-8073, Box 1111, NULL, Mississippi State, MS, 39762, 2, Giovanni, Modica, (662) 324-5772, Box 2618, NULL, Mississippi State, MS, 39762, 3, Tom, Cruise, (987) 456-0515, Nash Street, Apt #1, Los Angeles, CA, 58746, 4, Alicia, Silverstone, (662) 323-4624, Box 2345, NULL, Starkville, MS, 39759, 5, Cristina, Aguilera, (276) 587-9851, Sunset Boulevard, Number 5, Orlando, FL,56984, 6, Silvester, Stallone, (873) 632-9651, Main Street, Apt B, Portland, OR, 48751, 7, Bill, Gates, (759) 695-7541, University Drive, NULL, New York, NY, 69354, 8, Britney, Spears, (456) 325-9654, Bourbon Street, Number 34G, Miami, FL, 12547, 9, Kim, Basinger, (981) 741-8526, 5th Avenue, NULL, Houston, TX, 69541, 10, Brad, Pitt, (237) 369-8524, Morgan Street, Apt. 12, Minneapolis, MN, 78922, 11, Bart, Simpson, (706) 852-9874, Box 9874, NULL, Reading, MA, 96521

Descriptions of the control file The LOAD DATA statement is required at the beginning of the control file INFILE * specifies that the data is found in the control file and not in an external file The INTO TABLE statement is required to identify the table to be loaded (customer) into. By default, SQL*Loader requires the table to be empty before it inserts any records FIELDS TERMINATED BY specifies that the data is terminated by commas, but may also be enclosed by quotation marks The names of columns of the table to load are enclosed in parentheses BEGINDATA specifies the beginning of the data

Another Control File Example LOAD DATA INFILE ‘customer.dat’ INTO TABLE customer FIELDS TERMINATED BY ',‘ OPTIONALLY ENCLOSED BY '"' (customerID, firstName, lastName, phone, address1, address2, city, state, zip) Data are stored in an external file customer.dat

Invoking SQL*Loader sqlldr username/password Construct a loading file myload.ldr: sqlload xt1/xt1 control=customer.ctl sqlload xt1/xt1 control=product.ctl