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

Preview:

DESCRIPTION

3 The SQL Command Prompt

Citation preview

1

Introduction to SQL *PlusOracle 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.

3

The SQL Command Prompt

4

Show all Tables

5

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)

7

Examples

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.

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

10

The “ED” command

11

New query will remove the past

query from the edit buffer

12

Get Files to Run

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.

14

Script is a text file

15

16

17

Run Example Script

18

19

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

20

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

The BETWEEN Operator

21

Parameter Query

22

The ACCEPT commandLike a variable

23

24

25

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

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.

27

Using Special Pseudo-columns

28

End of Introduction

Other commands and information can be found in the Oracle

Documentation available online.

Recommended