首发:http://www.arppinging.com/wordpress/?p=93
Oracle菜鸟学习之 Oracle基础命令
1.connect和show user
连接用户和查看当前用户
SQL> show user;
USER is "SCOTT"
SQL> conn /as sysdba
Connected.
SQL> show user
USER is "SYS"
SQL>
2.clear screen
清除屏幕输出
3.spool
记录输出内容到文本
开启记录
SQL> spool /tmp/sql.txt
SQL> select * from student;
SNO SNAME BIRTHDAY
---------- ------------------------------ -------------------
1 A 0011-01-01 00:00:00
2 B 2011-01-01 00:00:00
3 1981-02-23 00:00:00
4 D
SQL> spool off
#关闭记录
# 查看文本是否有记录内容
[root@localhost tmp]# cat /tmp/sql.txt
SQL> select * from student;
SNO SNAME BIRTHDAY
---------- ------------------------------ -------------------
1 A 0011-01-01 00:00:00
2 B 2011-01-01 00:00:00
3 1981-02-23 00:00:00
4 D
SQL> spool off
[root@localhost tmp]#
4.set time on
将时间信息打印在提示符的左边
#开启时间显示
SQL> set time on
16:02:39 SQL>
16:02:41 SQL> set time off
# 关闭时间显示
SQL>
5.host
host可以执行linux或者windows的命令
SQL> host ls -l
total 40
-rw-r--r--. 1 oracle oinstall 20 Oct 3 12:59 afiedt.buf
drwxr-xr-x. 2 oracle oinstall 4096 Oct 2 10:54 Desktop
drwxr-xr-x. 2 oracle oinstall 4096 Oct 2 10:54 Documents
drwxr-xr-x. 2 oracle oinstall 4096 Oct 2 10:54 Downloads
drwxr-xr-x. 2 oracle oinstall 4096 Oct 2 10:54 Music
drwxr-x---. 3 oracle oinstall 4096 Oct 2 11:28 oradiag_oracle
drwxr-xr-x. 2 oracle oinstall 4096 Oct 2 10:54 Pictures
drwxr-xr-x. 2 oracle oinstall 4096 Oct 2 10:54 Public
drwxr-xr-x. 2 oracle oinstall 4096 Oct 2 10:54 Templates
drwxr-xr-x. 2 oracle oinstall 4096 Oct 2 10:54 Videos
SQL>
6.@
@在oracle中可以用来执行脚本中的内容
# 查看脚本信息
[root@localhost tmp]# cat test.sql
select * from student;
show user;
[root@localhost tmp]#
# 执行脚本
SQL> @/tmp/test.sql
SNO SNAME BIRTHDAY
---------- ------------------------------ -------------------
1 A 0011-01-01 00:00:00
2 B 2011-01-01 00:00:00
3 1981-02-23 00:00:00
4 D
USER is "SCOTT"
SQL>