1 introduction to sql *plus oracle sql interface mis309 database systems

28
1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

Upload: alvin-hoover

Post on 18-Jan-2018

219 views

Category:

Documents


0 download

DESCRIPTION

3 The SQL Command Prompt

TRANSCRIPT

Page 1: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

1

Introduction to SQL *PlusOracle SQL Interface

MIS309 Database Systems

Page 2: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

2

Connect to Oracle SQL *Plus

• In MS Windows, open “Run SQL Command Line” from the “start” menu.

• Type, “Connect”• Enter “hr” for the name and password or

enter “system” and the admin password you created during the Oracle install.

Page 3: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

3

The SQL Command Prompt

Page 4: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

4

Show all Tables

Page 5: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

5

Page 6: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

6

Introduction to SQL Plus

Oracle’s proprietary SQL is named SQL*Plus. Besides the standard SQL statements, it provides an environment where you can create, save, run SQL statements and do other chores.

Some common SQL*Plus Commands:REMARK SET HEADSEP TTITLE(top title) BTITLE COLUMN BREAK ON COMPUTE SUMSET LINESIZE n SET PAGESIZE n

SPOOL SET PAUSE (ON | OFF)

Page 7: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

7

Examples

Page 8: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

8

• The SQL*Plus Editor. In Windows, the NotePad is typically assigned as the SQL*Plus Editor. • SQL*Plus always keeps the last SQL statement (not command) in the editor. If you do a mistake, you mat activate the editor to make correction. The command to activate the editor is Edit or simply Ed. When you save the edited file, by default, the system will save it in a file named afidt.buf.

Page 9: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

9

Edit the statement, save and close the file. You will be back to the SQL screen. Issue a / Command. The system will run the saved statement.

No semicolon

Page 10: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

10

The “ED” command

Page 11: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

11

New query will remove the past

query from the edit buffer

Page 12: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

12

Get Files to Run

Page 13: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

13

Introduction to SQL*Plus Scripts

• A Script file is a text file which may contain several SQL statements and some selected SQL*Plus commands. Rather than doing the queries interactively, we may write the statements in a text file and then run the statements in batch mode. • We will use the Notepad to develop a simple script. WE will save it as myScript1.txt in some directory. Then we will run the script in SQL*Plus using the START or @ command.

Page 14: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

14

Script is a text file

Page 15: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

15

Page 16: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

16

Page 17: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

17

Run Example Script

Page 18: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

18

Page 19: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

19

Copying a table to another table (with data & structure)

Page 20: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

20

Copying the structure of a table to another table (without data)

The BETWEEN Operator

Page 21: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

21

Parameter Query

Page 22: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

22

The ACCEPT commandLike a variable

Page 23: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

23

Page 24: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

24

Page 25: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

25

A list of employees with budgeted compensation. Budget is (fixed salary + quota*commRate)

Page 26: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

26

Some employees do not have fixed salary. In that case we want the budget to be quota*copmmRate. If some employees do not have quota, we want to treat it as 0.

Page 27: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

27

Using Special Pseudo-columns

Page 28: 1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems

28

End of Introduction

Other commands and information can be found in the Oracle

Documentation available online.