oracle实验4:使用sqlplus
SQLPLUS介绍
Sql*plus是oracle提供的一个工具程序,既可以在oracle服务器使用,也可以在oracle客户端使用。
Sql*plus是一个最常用的工具,具有很强的功能,主要有:
- 数据库的维护,如启动,关闭等,这一般在服务器上操作。
- 执行sql语句执行pl/sql。
- 执行sql脚本。
- 数据的导出,报表。
- 应用程序开发、测试sql/plsql。
- 生成新的sql脚本。
- 供应用程序调用,如安装程序中进行脚本的安装。
实验4:使用sqlplus,进入sqlplus并进行简单的操作
进入sqlplus
通过Windows下dos进入
1) 开始-运行
>cmd
2) 进入sqlplus
·不登录进入sqlplus程序界面
>sqlplus /nolog
·不登录进入windows界面(windows特有的)
>sqlplusw /nolog
弹出windows窗口界面
3)连接远程数据库
>sqlplus /nolog不登录进入sqlplus程序界面
>conn scott/scott@192.168.137.112:1521/orcl
以scott用户连接到远程服务器地址192.168.137.112:1521
>show user 查询到已登录用户scott。
sqlplus的基本操作
连接到本地最高账号
SQL> connect / as sysdba
已连接。
SQL> show user
USER 为 "SYS"
显示sqlplus命令的帮助。
SQL> help index
Enter Help [topic] for help.
@ COPY PAUSE SHUTDOWN
@@ DEFINE PRINT SPOOL
/ DEL PROMPT SQLPLUS
ACCEPT DESCRIBE QUIT START
APPEND DISCONNECT RECOVER STARTUP
ARCHIVE LOG EDIT REMARK STORE
ATTRIBUTE EXECUTE REPFOOTER TIMING
BREAK EXIT REPHEADER TTITLE
BTITLE GET RESERVED WORDS (SQL) UNDEFINE
CHANGE HELP RESERVED WORDS (PL/SQL) VARIABLE
CLEAR HOST RUN WHENEVER OSERROR
COLUMN INPUT SAVE WHENEVER SQLERROR
COMPUTE LIST SET
CONNECT PASSWORD SHOW
进一步的帮助
SQL> help list
LIST
----
Lists one or more lines of the most recently executed SQL command
or PL/SQL block which is stored in the SQL buffer. Enter LIST with
no clauses to list all lines. In SQL*Plus command-line you can also
use ";" to list all the lines in the SQL buffer. The buffer has no
command history list and does not record SQL*Plus commands.
L[IST] [n | n m | n * | n LAST | * | * n | * LAST | LAST]
显示当前SQLPLUS的环境变量
SQL> show all
显示当前所登录的用户
SQL> show user
USER 为 "SYS"
查看当前缓冲区内的语句
SQL> list
1* select * from emp
SQL> help list
LIST
----
Lists one or more lines of the most recently executed SQL command
or PL/SQL block which is stored in the SQL buffer. Enter LIST with
no clauses to list all lines. In SQL*Plus command-line you can also
use ";" to list all the lines in the SQL buffer. The buffer has no
command history list and does not record SQL*Plus commands.
L[IST] [n | n m | n * | n LAST | * | * n | * LAST | LAST]
spool命令
spool是将屏幕的显示输入到文本文件内,以便查看。
SQL> spool F:\1.txt
SQL> select * from emp;
SQL> spool off
以上是将spool和spool off之间的屏幕输出到F:\1.txt文件中。
SQL> spool F:\1.txt append
SQL> select * from emp;
SQL> spool off
append是续写文件,如果不加,将覆盖原文件。
run 运行sqlplus缓冲区内的SQL语句,可以缩写为r
/ 与run命令相同
@脚本 运行指定的脚本
@@ 运行相对路径下的脚本
将select * from emp;保存到F:\test\s1.sql
SQL> @F:\test\s1.sql
输出select * from emp;的执行结果
save 将当前SQLPLUS缓冲区内的SQL语句保存到指定的文件中
save F:\2.txt
get 将文件中的SQL语句调入到SQLPLUS缓冲区内。
get F:\2.txt
eidt 编辑当前SQLPLUS缓冲区内的SQL语句
注释
--注释当前行
/* */是注释多行
清屏
SQL> clear screen
返回目录 http://www.cnblogs.com/downpour/p/3155689.html