SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database...

79
SQLPLUS Know more about the tool you rely on!
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    217
  • download

    0

Transcript of SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database...

Page 1: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

SQLPLUS

Know more about the tool you rely on!

Page 2: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Oracle Basics

• You must have an existing database instance before you can create an oracle relation (table).

• If you use an Oracle account, you are already given a database instance when DBA opens the account for you.

• Note that the following discussion is generic, and not specific to Oneonta account.

2

Page 3: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

How to talk to Oracle server?

• Various Client software

Page 4: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Oracle system client server architecture

•Oracle server and Oracle client

Oracle server

Oracle client Oracle client Oracle client

data managementtransaction controlrecoverysecurity

Client software provides interface to manipulate datatools to support development of application.SQL*PLUS is one of the client tools allowing developers to communicate with Oracle server.

Page 5: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Tools of Oracle• The tools provided by Oracle are so user friendly that

a person with minimum skills in the field of computers can access them with ease.

• The main tools are:– SQL *Plus– PL/SQL– Forms– Reports

5

Page 6: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

SQL*Plus

SQL*Plus is frequently used by DBAs and Developers to interact with the Oracle database.

SQL*Plus is an Oracle specific program which accepts SQL commands and PL/SQL blocks and executes them. SQL*Plus enables manipulation of SQL commands and PL/SQL blocks. It performs many additional tasks as well.

6

Page 7: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Oracle is a client-server architecture and SQL*Plus is the client.

SQL*Plus

• Interface to manipulate Oracle databases

• Tool to support the development of application

- SQL*Plus as an interface

Page 8: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

What is SQL*PLUS

• SQL*Plus is a client end interface tool and reporting tool that ships with the Oracle Database Server.

• SQL*Plus is a client terminal software allowing users to interact with Oracle server to manipulate data and data structures.

Page 9: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• It is a client agent to bridge the user and the server. It is usually used interactively. – Users type in SQL statements in SQL*Plus that

send statements to Oracle server, with simple grammar check.

– Oracle server then validates and executes the statements on its databases.

– The query results are returned to SQL*Plus and displayed to the user.

Page 10: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• Besides sending SQL statements to the server, SQL*Plus also saves them into a local buffer and allow users to view and change the statements. The following figure illustrates the process.

Page 11: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).
Page 12: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

What commands does SQL*PLUS deal with?

• It can take SQL and PL/SQL commands from users in command line mode and send those commands to Oracle server.

• Besides bypassing SQL and PL/SQL, SQL*PLUS supports also a set of SQL*PLUS commands to help format query result and preprocess SQL query.

Page 13: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• Therefore, when you use SQL*PLUS, you potentially will mingle several set of commands when you type:– SQL commands intended to pass to oracle server.– PL/SQL commands also for oracle server to run– SQL*PLUS commands for pre-processing or post-

processing for SQL*PLUS itself

Page 14: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

- To start SQL*Plus, enter Oracle username and password:

– $> sqlplus jason/athena (from a command line operating system such UNIX)

– click: Start Program Oracle (for Windows - SQL*Plus)

– At SUCO, we get access to SQL PLUS through a batch file.

Page 15: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Exiting SQL*Plus

• Three ways to exit SQL*Plus:– Type exit at the SQL prompt– lick File on the menu bar, and then click Exit– Click the Close button on the program window title bar

• Database session ends when SQL*Plus exits

Page 16: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• After you login into SQL*Plus, at the SQL prompt, you can begin typing any SQL command.

• Upon hitting return (i.e., enter key) the SQL prompt will change to line number prompts.

• When you are finished typing a command, type / or RUN to execute the SQL command.

• Also, a semicolon at the end of the SQL command will execute the command immediately after hitting return.

• In addition to SQL commands, /, and RUN, you can also executes SQL*Plus commands.

Page 17: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

SQL*Plus file commands

• SQL*Plus file command allow you to execute commands (or programs) stored in an external file, input or output data from/to a file, and save SQL commands typed during current session.

Page 18: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Some SQL*Plus file commands• SAVE filename.

– This allows you to save buffer contents into a file. • SPOOL filename.

– This allows you save SQL statements together with their outputs to a file.

• GET filename. – This retrieve a file and places it into the buffer.

• START filename. – This allows you to execute a batch of SQL statements stored in a file.

• @ filename.

– This allows you to execute a PL/SQL procedure(s) stored in a file.

Page 19: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Retrieving a File

• To retrieve SQL command from a file use GET filename or START filename.

• GET filename places the file into the buffer. • START filename executes the commands in the file. • The @ (at symbol) is equivalent to the START

command and is used to run SQL*Plus command scripts.

Page 20: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Using Scripts to Create Database Tables

• One or more SQL commands saved in a text file• Usually have .sql extension• To run from SQL*Plus:

– Start full file path (c:\temp\myfile.sql)– @full file path (@c:\temp\myfile.sql)– Extension can be omitted if it is .sql

Page 21: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Sending the Results to a Fileusing spool

• To send queries and their results to a file for later printing (e.g., turning in a running session for homework assignments), the spool command is used.

• On the menu go to FILE/Spool to begin spooling--it will ask for a file name. To quit spooling, go to FILE/Spool and then click on end Spool.

• Or you can always issue appropriate SQLPLUS commands to activate the …

Page 22: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Example of using spool

• spool test.out• select * from employee; • spool off

Page 23: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Line-by-line Editing• The previously executed commands (in current SQL*Plus session) are

stored in the local buffer. One way to change an SQL statement in the buffer is by using the line editor. The following are a list of line edit commands. – LIST or L--Lists the contents of the buffer – LIST n or L n--Lists the contents of line number n in the buffer and makes the

line current – LIST * or L *--Lists the current line – LIST m n--Lists the range from m to n line – Append text or A text--Adds to the end of the current line (e.g., "A ," adds a

comma to the end of line – INPUT or I--Adds one or more lines after the current line so you can begin

adding the text. – CHANGE /text--Deletes text from the current line – CHANGE /oldtext/newtext--Replaces oldtext with newtext in the current line – DEL -- Deletes the current line

• I would not recommend you spend time on this topic, for the best way is to directly use a text editor to edit your script then copy paste or run the script file as a whole directly.

Page 24: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Editing Prior Commands

• Using a Text editor• EDIT--Places you in an editor (Notepad or

textpad depending the default editor setting). The buffer contents are put into the editor .

Page 25: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Using Notepad

• Useful to use Notepad to edit sql commands– Commands can be edited without retyping– Commands can be saved– Saving multiple sql commands in a file creates a script

Page 26: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

SQL*PLUS variables

• There are two types of variables that can be used in SQL*Plus: – Substitution Variables

• which are declared with define• A kind of more like a constant

– bind variables • Using command variable (var)• Real variables

Page 27: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Substitution variables

• You can define substitution variables, for repeated use in a single script by using the SQL*Plus DEFINE command.

• define sets a user variable or displays its value.– & symbol– Accept allows sqlplus use more user friendly

prompts for variables, instead of variable names.– Like define in c. The defined symbolic name will be

replaced by the affiliated value.

Page 28: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• The following command sets the variable cname to ONEONTA.

• define cname=ONEONTA• From now on, whenever SQL*Plus encounters

a &cname, it replaces it with ONEONTA. • The ampersand & is the default prefix for

defined variables.

Page 29: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• The value of cname can be displayed with (assuming the default escape character was set to the ampersand (&) and hasn't been changed.– prompt &cname

• A defined variable can be undefined with undefine.

Page 30: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• By default, when SQL*Plus encounters a defined variable, it prints the original line and the line with the substitued values:

• define s="4+3'"• define t=dual• select &s from &t;• old 1: select &s from &t• new 1: select 4+3 from dual

• 4+3• ---------• 7

Page 31: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Suppressing old and new values

• This behavior can be turned with setting verify to off:• set verify off• define thousand=1000• define twelve = 12• define plus = +• select &thousand &plus &twelve from dual;• 1000+12• ----------• 1012

Page 32: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• The ampersand is the default prefix for defined variables. • However, default can be changed with set define. • set define x• set define x specifies the prefix-character for substitution

variables. The default is the ampersand (&). • set define + • select * from dba_objects where object_name like '%

+object_name%';

Page 33: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Accept

• A user variable can (mostly useful in a script) be set interactively with accept.– Setting a value of a variable interactively

• With accept, it is possible to interactively set a value for a user variable in SQL*Plus. – accept foo prompt 'Enter value for foo'

• Inputting passwords– accept pw prompt 'Enter your secret password' hide

Page 34: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Accept• accept variable • accept variable number • accept variable char • accept variable date • accept variable binary_float • accept variable binary_double • accept variable format format-string accept variable default

default-value accept variable prompt prompt-string accept variable noprompt

• accept variable hide

Page 35: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Output format enhancement

• Present data result more friendly.• Produce more readable Output.• Formatting column Headings

Page 36: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Binding variables

• In SQL*Plus, a binding variable declares a bind variable that can be embedded in subsequent SQL statements.

• a bind variable is declared with variable:

• var cenrollment number• var cname varchar2(15)

Page 37: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• After the declaration, a value can be assigned to the variable

• begin• select 'oneonta', 44

into :cname, :cenrollment from dual;• end;• /

Page 38: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• The value of the bind variable can then be printed with print:

• print cname

Page 39: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• • begin• select 55 into :cage from dual;• end;• /

Page 40: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• Assigning a value to a bind variable with execute– Since an execute is basically a wrapper around a

begin .. end PL/SQL block, a variable can be assigned a value like

• exec :cname:='oneonta' • exec insert into sunycampus values

(:cname, :cenrollment)• select * from sunycampus;

Page 41: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• variable bind_var_name number • variable bind_var_name char • variable bind_var_name char(n) • variable bind_var_name nchar • variable bind_var_name nchar(n) variable bind_var_name

varchar2 variable bind_var_name varchar2(n) variable bind_var_name nvarchar2(n) variable bind_var_name clob

• variable bind_var_name nclob • variable bind_var_name refcursor • variable bind_var_name binary_float • variable bind_var_name binary_double

Page 42: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Formatting Output in SQL*Plus

• To change default column headings:– Specify alternate column headings: SELECT fieldname1

"heading1_text", fieldname2 "heading2_text", ...– Use an alias for column headings: SELECT fieldname1 AS

alias_name1...• To change SQL*Plus line and page size settings

– Select Options/Environment on menu bar– Modify linesize and pagesize to desired values

• Please go through chapter 4

Page 43: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Simple formatting query results

• To format a number attribute to a dollar format, use the column <attribute> format <format>:

• SQL> COLUMN salary FORMAT $999,999 • To indicate the displayed width of a character string attribute, use the

column <attribute> format <A'format>. • For example, set the width of the name attribute to 8 characters. SQL>

COLUMN name FORMAT A8 • If a name is longer than 8 characters, the remaining is displayed at the

second line (or several lines)

Page 44: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• column c1 heading "First Name" Format a15

• COLUMN column_name CLEAR• COLUMN column_name FORMAT model• COLUMN SALARY FORMAT 99,990• COLUMN SALARY FORMAT $99,990

Page 45: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

set

• The set command can be used to change the default number of lines per page (14) and the number of characters per line (80).

• For example, to set the number of lines per page to 60, use the following command:

• SQL> SET PAGESIZE 60 • All formatting remain active until they are cleared or

reset or after you exit from SQL*Plus. • SQL> CLEAR COLUMN

Page 46: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• Sometimes when you get something fuzzy, you can try the following

• SQL> SET SERVEROUTPUT ON• SQL> set verify off

Page 47: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

• SQL> set timing on• SQL> create table tff(f1 int);

• Table created.

• real: 188• SQL> set timing off• It is measured in Milliseconds

Page 48: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Errors

• When an error occurs error information is displayed:– Line number– Position on line– Error code– Description of error

• Error codes– 3 letter prefix (I.e. ORA) – 5 digit code– More information on errors can be found at

http://otn.oracle.com

Page 49: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

The role of SQLPLUS

• If you are familiar with other databases, sqlplus is equivalent to – "sql" in Ingres, – "isql" or in Sybase – “sql analyzer” for SQLServer, – "db2" in IBM DB2, – "psql" in PostgresQL, – "mysql" in MySQL.

Page 50: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 50

Chapter 2

How to use Oracle SQL Developer

and other tools

Page 51: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Objectives

Applied

Start or stop the Oracle database server and listener.

Use SQL*Plus to run a SQL statement.

Use Oracle SQL Developer to do any of the following:

Create a database connection Export or import database connections Navigate through the objects of a database View the column definitions for a table View the data for a table Edit the column definitions for a table

Use Oracle SQL Developer to enter, run, open, and save SQL statements and scripts.

Use the SQL Reference manual to look up information about SQL statements.

Page 52: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 52

Objectives (continued)

Knowledge

Briefly describe the function of each of these products:

Database Home Page SQL*Plus Oracle SQL Developer SQL Reference manual

Page 53: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 53

How to stop the database StartAll Programs

Oracle Database 10g Express Edition Stop Database

The DOS window when the database is stopped

Page 54: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 54

How to start the database StartAll Programs

Oracle Database 10g Express Edition Start Database

The DOS window when the database is started

Page 55: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 55

Terms to know Database service (database server, database engine)

Database listener

Page 56: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 56

The Database Home Page

Page 57: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 57

How to start the Database Home Page from the Windows Start menu All Programs

Oracle Database 10g Express Edition Go To Database Home Page.

Use the Database Login page to log in.

How to use the Database Home Page to create a user for a database Log in as the system user.

Administration Database Users Create User.

Use the resulting web page to create the user.

Page 58: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 58

The SQL*Plus tool

Page 59: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 59

How to start SQL*Plus Select the Run command from the Start menu.

Enter “sqlplus”, and click the OK button.

How to connect to a database with SQL*Plus Enter the username and password.

How to run a SQL statement with SQL*Plus Type the statement.

Type a semicolon, and press the Enter key.

Page 60: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 60

The SQL Developer dialog box for creating database connections

Page 61: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 61

How to create a database connection Right-click on the Connections node.

Select the New Connection command.

Enter a connection name, username, and password.

Click the Test button to test the connection.

Click the Save button to save the connection.

Page 62: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 62

How to export database connections Right-click the Connections node.

Select the Export Connections command.

Select the connections that you want to export.

Specify the path and filename for the XML file for the connections.

How to import database connections Right-click the Connections node.

Select the Import Connections command.

Navigate to the XML file for the connections.

Select the connections that you want to import.

Page 63: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 63

The Connection Information dialog box

Page 64: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 64

The tables available to the AP user

Page 65: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 65

The column definitions for a table

Page 66: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 66

How to view the column definitions for a table Click on the name of the table in the Connections window.

By default, the columns are displayed in the sequence in which they were created.

How to view the data for a table Click on the Data tab.

Page 67: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 67

Editing the column definition of a table

Page 68: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 68

A SELECT statement and its results

Page 69: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 69

How to change the connection for a worksheet Use the Connections list

How to comment out or uncomment a line Press Ctrl+/.

Two ways to execute a SQL statement Press the F9 key.

Click the Execute Statement button in the toolbar.

Page 70: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 70

Using the snippets window

Page 71: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 71

Handling syntax errors

Page 72: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 72

Common causes of errors Misspelling the name of a table or column

Misspelling a keyword

Omitting the closing quotation mark

Being connected as the wrong user

Page 73: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 73

The Open File dialog box

Page 74: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 74

Three ways to open a SQL file Click the Open button in the toolbar.

Press Ctrl+O.

Select the FileOpen command.

How to switch between open statements Select the appropriate tab.

How to cut, copy, and paste code Use the standard Windows techniques.

Page 75: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 75

Three ways to save a SQL file Click the Save button in the toolbar.

Press Ctrl+S.

Select the FileSave command.

How to change the default directory for new statements Use the ToolsPreferences command.

Expand the Database node.

Click on the Worksheet Parameters node.

Change the default path for scripts.

Page 76: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 76

A SQL script and its results

Page 77: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 77

How to run an entire SQL script Press F5 or click the Run Script button.

How to run one statement within a script 1. Move the cursor into the statement you want to execute.

2. Press F9 or click the Execute Statement button.

Note The results of a statement are displayed in the Results tab.

The results of a script are displayed in the Script Output tab.

Page 78: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

Murach’s Oracle SQL and PL/SQL, C2

© 2008, Mike Murach & Associates, Inc.Slide 78

The Oracle Database SQL Reference manual

Page 79: SQLPLUS Know more about the tool you rely on!. Oracle Basics You must have an existing database instance before you can create an oracle relation (table).

http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_five.htm#i1211130