SQL and SQL*Plus Interaction

Slides:



Advertisements
Similar presentations
Session 2Introduction to Database Technology Data Types and Table Creation.
Advertisements

Data Definition Language (DDL)
CC SQL Utilities.
7 Copyright © Oracle Corporation, All rights reserved. Producing Readable Output with i SQL*Plus.
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.
Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
Writing Basic SQL statement 2 July July July Create By Pantharee Sawasdimongkol.
Introduction to Structured Query Language (SQL)
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.
SQL Query Extras MIS 433. Rerunning the last Query n Type the forward slash “/” to rerun the last query that was entered.
Chapter 1 Writing Basic SQL Statements Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
1 ORACLE SQL iSQLPlus & SQLPLUS Statements. 1-2 iSQLPlus is a application software layer that allows programmers to utilize SQL to make changes to the.
Oracle Data Definition Language (DDL)
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
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.
Database control Introduction. The Database control is a tool that used by the database administrator to control the database. To enter to Database control.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
 SQL statements are not case sensitive.  SQL statements can be on one or more lines.  Keywords cannot be abbreviated or split across lines.
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.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Stored Procedures. Definition a stored procedure is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database.
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 CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
Copyright  Oracle Corporation, All rights reserved. 8 Producing Readable Output with SQL*Plus.
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.
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.
Installation Oracle 11g Express 2 double click the "setup" button to install the Oracle.
Creating and Managing Tables. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
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
3 A Guide to MySQL.
Excel Tutorial 8 Developing an Excel Application
Development Environment
CS 3630 Database Design and Implementation
Release Numbers MATLAB is updated regularly
Using SQL*Plus.
Introduction to MySQL.
SQL Creating and Managing Tables
Current outstanding balance
Guide To UNIX Using Linux Third Edition
Introduction to PL/SQL
Using SQL*Plus.
ORACLE SQL Developer & SQLPLUS Statements
ISC440: Web Programming 2 Server-side Scripting PHP 3
DATABASE MANAGEMENT SYSTEM
SQL Creating and Managing Tables
Chapter 8 Working with Databases and MySQL
SQL Creating and Managing Tables
Oracle Data Definition Language (DDL)
Chapter 2: Creating And Modifying Database Tables
Using SQL*Plus.
IST 318 Database Administration
Producing Readable Output with iSQL*Plus
Presentation transcript:

SQL and SQL*Plus Interaction SQL Statements Buffer SQL Statements Server SQL*Plus SQL*Plus Commands Query Results SQL and SQL*Plus SQL is a command language for communication with the Oracle Server from any tool or application. Oracle SQL contains many extensions. When you enter a SQL statement, it is stored in a part of memory called the SQL buffer and remains there until you enter a new statement. SQL*Plus is an Oracle tool that recognizes and submits SQL statements to the Oracle Server for execution and contains its own command language. Features of SQL Can be used by a range of users, including those with little or no programming experience Is a nonprocedural language Reduces the amount of time required for creating and maintaining systems Is an English-like language Features of SQL*Plus Accepts ad hoc entry of statements Accepts SQL input from files Provides a line editor for modifying SQL statements Controls environmental settings Formats query results into a basic report Accesses local and remote databases Formatted Report

SQL Statements Vs SQL*Plus Commands A command language used for communication with the Oracle Server to access data When a SQL statement is entered, it is stored in a part of memory called the SQL buffer and remains there until a new statement is entered SQL*Plus An environment SQL*Plus is an Oracle tool that recognizes and submits SQL statements to Oracle Server for execution Provides a line editor for modifying SQL statements Is entered one line at a time, not stored in the SQL buffer SQL and SQL*Plus (continued) The following table compares SQL and SQL*Plus: SQL statements SQL buffer SQL*Plus commands SQL*Plus buffer

SQL Statements Vs SQL*Plus Commands It is based on ANSI standard SQL Keyword can’t be abbreviated Statements manipulate data and table definitions in the database It does not have a continuation character Uses a termination character to execute command immediately Uses functions to perform some formatting SQL*Plus Oracle proprietary interface for executing SQL statements Keywords can be abbreviated Commands do not allow manipulation of values in the database Has a dash(-) as a continuation character if the command is longer than one line Does not require a termination characters. Commands are executed immediately Uses commands to format data SQL and SQL*Plus (continued) The following table compares SQL and SQL*Plus:

Overview of SQL*Plus Log in to SQL*Plus. Describe the table structure. Edit your SQL statement. Execute SQL statements from SQL*Plus to: Retrieve, modify, add, and remove data from the database Format, perform calculations on, store, and print query results in the form of reports Save SQL statements to files Create script files to store SQL statements for repetitive use in the future Append SQL statements to files. Execute saved files. Load commands from file to buffer to edit. SQL*Plus SQL*Plus is an environment in which you can do the following: Execute SQL statements to retrieve, modify, add, and remove data from the database Format, perform calculations on, store, and print query results in the form of reports Create script files to store SQL statements for repetitive use in the future SQL*Plus commands can be divided into the following main categories: Class Management Note (for Page 1-27) Snippet: “Establishing a Database Session” Logging in to SQL*Plus: Release number may vary, depending on the version installed.

Logging In to SQL*Plus Logging In to SQL*Plus How you invoke SQL*Plus depends on which type of operating system or Windows environment you are running. To log in through a Windows environment: 1. Click Start—>Programs—>Oracle for Windows NT—>SQL*Plus 8.0. 2. Fill in username, password, and database. To log in through a command-line environment: 1. Log on to your machine. 2. Enter the SQL*Plus command as shown in the slide. In the command: username is your database username password is your database password (if you enter your password here, it is visible) @database is the database connect string Note: To ensure the integrity of your password, do not enter it at the operating system prompt. Instead, enter only your username. Enter your password at the Password prompt. Once you are successfully logged in to SQL*Plus, you see the following message: SQL*Plus : Release 8.0.3.0.0 - Production on Mon Oct 06 16:03:43 1997 (c) Copyright 1997 Oracle Corporation. All rights reserved.

Displaying Table Structure Use the SQL*Plus DESCRIBE command to display the structure of a table. DESC[RIBE] tablename The result of the command is to see the column names, data types, as well as whether a column must contain data. Example: SQL> DESCRIBE dept Displaying Table Structure In SQL*Plus, you can display the structure of a table using the DESCRIBE command. The result of the command is to see the column names and datatypes as well as whether a column must contain data. In the syntax: tablename is the name of any existing table, view, or synonym accessible to the user Name Null? Type ----------------- -------- ------------ DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13)

Displaying Table Structure SQL> DESCRIBE dept Name Null? Type ----------------- -------- ------------ DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13) Data Type Description NUMBER(p, s) Number value having a maximum number of digits p, the number of digits to the right of the decimal point s VARCHAR2(S) Variable-length character value of maximum size s DATE Date and time value between January 1, 4712 BC and December 31, 9999 AD CHAR(S) Fixed-length character value of size s Displaying Table Structure In SQL*Plus, you can display the structure of a table using the DESCRIBE command. The result of the command is to see the column names and datatypes as well as whether a column must contain data. In the syntax: tablename is the name of any existing table, view, or synonym accessible to the user

SQL*Plus Editing Commands A[PPEND] text C[HANGE] / old / new C[HANGE] / text / CL[EAR] BUFF[ER] DEL DEL n DEL m n I[NPUT] I[NPUT] text L[IST] L[IST] n L[IST] m n R[UN] n n text 0 text SQL*Plus Editing Commands SQL*Plus commands are entered one line at a time and are not stored in the SQL buffer. Guidelines If you press [Return] before completing a command, SQL*Plus prompts you with a line number. You terminate the SQL buffer by either entering one of the terminator characters (semicolon or slash) or pressing [Return] twice. You then see the SQL prompt.

SQL*Plus Editing Commands A[PPEND] text Adds text to the end of the current line C[HANGE] / old / new Changes old text to new text in the current line C[HANGE] / text / Deletes text from the current line CL[EAR] BUFF[ER] Deletes all lines from the SQL buffer DEL Deletes current line DEL n DEL m n SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].

SQL*Plus Editing Commands I[NPUT] Inserts an indefinite number of lines I[NPUT] text Inserts a line consisting of text L[IST] Lists all lines in the SQL buffer L[IST] n Lists one line (specified by n) L[IST] m n Lists a range of lines (from m to n) R[UN] Displays and runs the current SQL statement in the buffer n Specifies the line to make the current line n text Replaces line n with text 0 text Inserts a line before line 1 SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].

SQL*Plus Editing Commands SELECT FEATUER, PAGE FROM NEWSPAPER WHERE SECTION = ‘F’; ORACLE responds: ERROR at line 1: ORA-0704: invalid column name TWO Solutions: 1. Retype the whole query 2. Use command to correct spelling of FEATUER SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].

SQL*Plus Editing Commands SELECT FEATUER, PAGE FROM NEWSPAPER WHERE SECTION = ‘F’; Solution: Name of command: list SQL>list Result: 1 SELECT FEATUER, PAGE 2 FROM NEWSPAPER 3* WHERE SECTION = ‘F’ SQL*Plus shows all three lines, and numbered them. It also places * next to line 3, which means it is the line your editing commands are able to affect. But we want to change line 1, so type: SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].

SQL*Plus Editing Commands SELECT FEATUER, PAGE FROM NEWSPAPER WHERE SECTION = ‘F’; Solution: Name of command: list 1 SQL>list 1 Result: 1* SELECT FEATUER, PAGE Line 1 is displayed and is now the current line. We change it by typing: CHANGE /FEATUER/FEATURE 1* SELECT FEATURE, PAGE SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].

SQL*Plus Editing Commands Check the whole query again with: list 1 SELECT FEATUER, PAGE 2 FROM NEWSPAPER 3* WHERE SECTION = ‘F’; Place / at SQL> prompt and query will be executed. SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].

SQL*Plus Editing Commands Check the whole query again with: list 1 SELECT FEATUER, PAGE 2 FROM NEWSPAPER 3* WHERE SECTION = ‘F’; To delete the current line: del 1 SELECT FEATUER, PAGE 2* FROM NEWSPAPER SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].

SQL*Plus Editing Commands To clear the whole select statement completely, type: clear buffer If you like to append something to the current line, type: SQL>list 1 1* SELECT FEATUER, PAGE SQL>append “where it is” 1* SELECT FEATUER, PAGE “where it is” append places its text right up against the end of the current line, with no spaces in between. To put a space in, type two spaces between the word append and the text. SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].

SQL*Plus Editing Commands We may also input a whole new line after the current line: SQL> list 1 SELECT FEATUER, PAGE 2* FROM NEWSPAPER SQL>input where section = ‘A’ 2 FROM NEWSPAPER 3* where section = ‘A’ Run it SQL> / SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].

SQL*Plus File Commands SAVE filename GET filename START filename @ filename EDIT filename SPOOL filename SQL*Plus File Commands SQL statements communicate with the Oracle Server. SQL*Plus commands control the environment, format query results, and manage files. You can use the commands identified in the following table:

SQL*Plus File Commands SAV[E] filename[.ext] [ REPLACE | APP[END] ] Saves current contents of SQL buffer to a file. Use APPEND to add to an existing file; use REPLACE to overwrite an existing file. The default extension is .sql. GET filename[.ext] Writes the contents of a previously saved file to the SQL buffer. The default extension is .sql. START filename[.ext] Runs a previously saved command file. @ filename Runs a previously saved command file (same as START). ED[IT] Invokes the editor and saves the buffer contents to a file named afiedt.buf ED[IT] filename[.ext] Invokes editor to edit contents of a saved file SPO[OL] [ filename[.ext] | OFF OUT ] Stores query results in a file. OFF closes the spool file. OUT closes the spool file and sends the file results to the system printer. EXIT Leaves SQL*Plus. SQL*Plus File Commands SQL statements communicate with the Oracle Server. SQL*Plus commands control the environment, format query results, and manage files. You can use the commands identified in the following table:

SQL*Plus File Commands We can save the SQL created so far: SQL> save abc.sql SQL*PLUS responds: Wrote file abc.sql Now, the SQL statement is in file abc.sql. SQL*Plus Editing Commands (continued) You can enter only one SQL*Plus command per SQL prompt. SQL*Plus commands are not stored in the buffer. To continue a SQL*Plus command on the next line, end the current line with a hyphen (-). Class Management Note Show students the use of the commonly used editing commands, such as A[PPEND], C[HANGE], DEL, L[IST], and R[UN].