Sqlplus Command usage guide (i)

Source: Internet
Author: User
Tags date format return sqlplus
Friends familiar with Oracle know that SQL Plus is an important tool for dealing with Oracle. SQL Plus itself has a lot of commands that can help us do a lot of things, including producing standardized reports, providing human-computer interaction, and so on. Below, I will briefly explain, for everyone to refer to:
A Help command
Help helps us find SQL plus the use of each command
Example:
Sql> Help Accept

ACCEPT
------

Reads a line of input and stores it given user variable.

ACC[EPT] variable [num[ber] | CHAR | DATE] [For[mat] format]
[Def[ault] Default] [PROMPT Text | Nopr[ompt]] [HIDE]

Two Sqlplus human-Computer Interaction command
User input can be accepted in Sqlplus, and the most commonly used commands are:
(1) ACCEPT
Accept the entire row of data.
Syntax: acc[ept] variable [num[ber]| char| DATE] [For[mat] format]
[Def[ault] Default] [PROMPT text| Nopr[ompt]] [HIDE]
An example is provided:
Corner 1.sql, find the employee who has a salary greater than the input amount.
SET FEEDBACK off
SET PAUSE off
ACCEPT sal number PROMPT ' please input salary (weekly): '
Select Employee_id,last_name,first_name,salary from Employee
where salary>[$sal]
Running in Sqlplus
Sql> @c:\1.sql
Please input salary (weekly): 1000
Old 2:where Salary>&sal
New 2:where salary> 1000

employee_id last_name first_name SALARY
----------------- ------------------- ----------------------------- ----------
7499 ALLEN KEVIN 1600
7505 DOYLE JEAN 2850
7506 DENNIS LYNN 2750
7507 BAKER LESLIE 2200
7521 WARD CYNTHIA 1250
7555 PETERS DANIEL 1250
7557 SHAW KAREN 1250
7560 DUNCAN SARAH 1250
7564 LANGE GREGORY 1250
7566 JONES TERRY 2975
7569 Alberts CHRIS 3000
Note:
①accept accepts a line of input and stores the input data according to the specified type to the variable (if it does not exist, automatically creates one).
②fomrat is used to make input data formats, such as numbers can specify ' 999.99 ', characters can specify length ' A10 '
③ if the type is char, the length is maximum 240.

(2) PROMPT
The output hint information.
Syntax: pro[mpt] [text]
Example:
Sql> PROMPT Hello,world
Hello,world
(3) PAUSE
Outputs a line of information and waits for the user to enter a carriage return.
Syntax: Pau[se] [text]
Example:
sql> PAUSE Please press [return]
Please press [Return]

Sql>

Three Edit commands
The last SQL statement sent through SQL Plus is saved in a data buffer in SQL Plus, and the Sqlplus command is not included and can be edited by editing the command.
(1)/
Re-execute the SQL statement.
(2) APPEND
In the command buffer, append the characters.
Example:
Sql> select * from tab;
....
sql> A WHERE tabtype= ' VIEW '
1* SELECT * from Tabwhere tabtype= ' VIEW '
Sql>/

Tname Tabtype Clusterid
------------------------------ ------- ----------
Plsql_profiler_grand_total VIEW
Plsql_profiler_lines_cross_run VIEW
Plsql_profiler_notexec_lines VIEW
Plsql_profiler_units_cross_run VIEW
SALES VIEW

(3) list or;
Lists the contents of a buffer, and the list can list the contents of a row;
Example:
sql>;
1 SELECT * from tab WHERE tabtype= ' VIEW '
2* ORDER BY Tname
Sql> L 2
2* ORDER BY Tname
(4) INPUT
Add one line of content
Example:
sql> I order by tname
Sql> L
1 SELECT * from tab WHERE tabtype= ' VIEW '
2* ORDER BY Tname
(5) Change
Replaces the contents of the first ship in the current line with the new content,
Syntax: C[hange] Sepchar old [Sepchar [New[sepchar]]]
Example:
Sql> L
1* SELECT * FROM Employee where salary>1000 and salary<2000
Sql> C/salary/sal
1* SELECT * FROM Employee where sal>1000 and salary<2000
Note that when the buffer has two lines, the C replaces the content in the last line.
(6) Edit
In the specified text editor, edit the contents of the buffer. On Windows, the default is Notepad.
(7) SPOOL
The output is assigned to a file, a bit like the > under DOS command
Spo[ol] [File_name[.ext] | Off | Out]
Sql> Spool C:\1.txt
Sql> select * from tab;
Sql> Spool Off

Four execution command
(1) @
Load the corner of this, run.
Example:
Sql>@c:\1.sql
(2) EXECUTE
Run Pl/sql procedures and packages.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.