oracle 使用sqlplus
AUsing SQL Command LineThis section provides an introduction to SQL Command Line (SQL*Plus),an interactive and batch command-line query tool that is installed with Oracle Database Express Edition. This section contains the following topics:
For information about running SQL language statements,seeChapter 3,"Using SQL". See Also:
Overview of SQL Command LineSQL Command Line (SQL*Plus) is a command-line tool for accessing Oracle Database XE. It enables you to enter and run SQL,PL/SQL,and SQL*Plus commands and statements to:
You can use SQL Command Line to generate reports interactively,to generate reports as batch processes,and to write the results to a text file,to a screen,or to an HTML file for browsing on the Internet. Using SQL Command LineThis section describes SQL Command Line (SQL*Plus),a command-line utility to run SQL and PL/SQL. This contains the following topics:
Note: Before starting SQL Command Line,make sure that the necessary environmental variables have been set up properly. SeeOracle Database Express Edition 2 Day DBAfor information about setting environmental variables for SQL Command Line. Starting and Exiting SQL Command LineTo start SQL Command Line from the operating-system command prompt,enter the following:
When prompted,enter the username and password of the user account (schema) that you want to access in the local database. For example,enter You can also include the username and password when you start SQL Command Line. For example:
If you want to connect to a database running on a remote system,you need to include a connect string when starting SQL Command Line. For example:
After you have started SQL Command Line,the
At the When you want to exit SQL Command Line,enter
Displaying Help With SQL Command LineTo display a list of Help topics for SQL Command Line,enter
From the list of SQL Command Line Help topics,you can display Help about an individual topic by entering
Entering and Executing SQL Statements and CommandsTo enter and execute SQL statements or commands,enter the statement or command at the SQL prompt. At the end of a SQL statement,put a semi-colon (;) and then press the Enter key to execute the statement. For example:
If the statement does not fit on one line,enter the first line and press the Enter key. Continue entering lines,and terminate the last line with a semi-colon (;). For example:
The output from the previous
Note that a terminating semi-colon (;) is optional with SQL Command Line commands,such as SQL Command Line DESCRIBE Command 描述表字段情况SQL Command Line provides the
SQL Command Line SET Commands 数据多的情况修改样式等。The SQL Command Line
To enable output from PL/SQL blocks with
To view all the settings,enter the following at the SQL prompt:
For information about the SQL Command Line See Also: SQL*Plus User's Guide and Referencefor information about setting up the SQL Command Line environment with a login file Running Scripts From SQL Command Line 通过命令行批量运行脚本You can use a text editor to create SQL Command Line script files that contain SQL*Plus,SQL,and PL/SQL statements. For consistency,use the A SQL script file is executed with a
A SQL script file can be executed in a Linux environment as follows:
You can use When running a script,you need to include the full path name unless the script is located in the directory from which SQL Command Line was started,or the script is located in the default script location specified by the See Also:
Spooling From SQL Command Line 将查询结果输入文本里面The To start spooling the output to an operating system file,you enter the
If you want to append the output to an existing file:
To stop spooling and close a file,enter the following:
Using Variables With SQL Command LineYou can create queries that use variables to make When using a variable in a SQL statement,the variable name must be begin with an ampersand (&). This section contains the following topics:
For information about using bind variables in PL/SQL code,see"Using Bind Variables With PL/SQL". Prompting for a Variable Value in a Query 可以随时多次输入参数查询You can use Example A-1 Prompting for a Variable Value in SQL Command Line -- prompt for employee_id in a query,you need to enter a valid ID such as 125 SELECT employee_id,last_name,job_id FROM employees WHERE employee_id = &employee_id; When you run the previous
Reusing a Variable Value in a QueryYou can use Example A-2 Reusing a Variable Value in SQL Command Line -- prompt for a column name,such as job_id,which is then substituted in the -- remaining identical substitution variables prefixed with && SELECT employee_id,&&column_name FROM employees ORDER BY &&column_name; Defining a Variable Value for a QueryInExample A-3,the Example A-3 Defining a Variable for a Query in SQL Command Line -- define a variable value for a query as follows DEFINE job_id = "ST_CLERK" -- run a query using the defined value for job_id (ST_CLERK) SELECT employee_id,last_name FROM employees WHERE job_id = '&job_id'; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |