sqlplus 命令学习
admin
2023-04-29 17:23:27
0次

sqlplus 命令学习


$ sqlplus  / as sysdba

SQL> help index 可以输入sqlplus 命令


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                      XQUERY

 CONNECT       PASSWORD     SHOW


sqlplus 一个允许你输入sql语句地方 sql语句控制数据库的存取


1 查出scott.emp表的编号,姓名

SQL> select empno , ename from scott.emp; 分号结束 回车执行


     EMPNO ENAME

---------- ----------

      7369 SMITH

      7499 ALLEN

      7521 WARD

      7566 JONES

      7654 MARTIN


2 如何查看当前sql buffer 的语句 

? 命令 -----> 看帮助

? list 

SQL> ? 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]


输入 l 


3 我想修改一buffer的语句,比如加一个条件ename ='SCOTT';

 

SQL> ? EDIT


 EDIT

 ----


 Invokes 调用 an operating system text editor文本编辑器 on the contents of the

 specified file or on the contents of the SQL buffer. The buffer

 has no command history list and does not record SQL*Plus commands.


 ED[IT] [file_name[.ext]]


SQL> ed

Wrote file afiedt.buf

38


?


?

q 退出

一定在linux指定使用哪一个文本编辑器

windows用的记事本 


怎么指定用那个编辑器-----》》》》??? 变量指定

方法1 :临时指定

define _editor=vi 

输入ed


方法2: 永久指定 把变量放在.bash_profile 

 [oracle@yutianedu ~]$ vim /home/oracle/.bash_profile

 加入: export EDITOR=vi 

[oracle@yutianedu ~]$ source /home/oracle/.bash_profile

[oracle@yutianedu ~]$ echo $EDITOR

vi



ed 修改

SQL> l 查看

  1  select empno ,ename from scott.emp

  2* where ename ='SCOTT'



4 如何执行buffer cache 中的语句

SQL> ?  /


 / (slash)

 ---------


 Executes the most recently executed SQL command or PL/SQL block

 which is stored in the SQL buffer. Use slash (/) at the command

 prompt or line number prompt in SQL*Plus command line. The buffer

 has no command history and does not record SQL*Plus commands.



SQL> l

  1  select empno ,ename from scott.emp

  2* where ename ='SCOTT'

SQL> /  执行sql buffer 中的sql语句


     EMPNO ENAME

---------- ----------

      7788 SCOTT


5 保存代码一个脚本,下次执行

SQL> ? SAVE


 SAVE

 ----


 Saves the contents 内容 of the SQL buffer in a script. The

 buffer has no command history list and does not record SQL*Plus commands.


 SAV[E] [FILE] file_name[.ext] [CRE[ATE] | REP[LACE] | APP[END]]


save 文件命令 create /replace /append 

默认创建 

替换

追加


注意:脚本一定存在有权限的目录(oracle用户有权限写)


save /u01/app/oracle/1.sql 


6 保存脚本后,我想到操作系统去看一下,然后再回来执行sqlplus命令 (不退出sqlplus 到系统上执行命令)


SQL> ? HOST


 HOST

 ----


 Executes an operating system command without leaving SQL*Plus.

 Enter HOST without command to display an operating system prompt.

 You can then enter multiple operating system commands.


 HO[ST] [command]


用法1 :host 回车 ----》操作系统-----》exit -----》sqlplus 

用法2: host 操作系统命令

SQL> host ls -l /u01/app/oracle

total 24

-rw-r--r-- 1 oracle oinstall   58 Oct 11 15:26 1.sql

drwxr-x--- 3 oracle oinstall 4096 Oct 11 14:10 admin


清屏clear ---->host clear 


复制1.sql到/tmp目录

SQL> host cp /u01/app/oracle/1.sql /tmp


SQL> host ls -l /tmp

total 524

-rw-r--r-- 1 oracle oinstall     58 Oct 11 15:30 1.sql


删除 /tmp下的1.sql

host rm /tmp/1.sql


host 所有系统都支持 

在linux平台下 可以用!替换host 


7 退出sqlplus 

exit

quit 


8 在/u01/app/oracle 有一个sql脚本 在sqlplus 执行脚本???

 SQL> ? @


 @ ("at" sign)

 -------------

 Runs the SQL*Plus statements in the specified script. The script can be

 called from the local file system or a web server.


或者用

SQL> ? start


 START

 -----


 Runs the SQL*Plus statements in the specified script. The script can be

 called from the local file system or a web server.


 STA[RT] {url|file_name[.ext]} [arg ...]


@/u01/app/oracle/1.sql 

start /u01/app/oracle/1.sql



9 会把屏幕上的输出都保存到一个文件里-----》做日志用

? spool 

用法;

spool 一个文件

执行命令

spool off 结束


10 如何在用户之间切换

conn 账户名/密码 


SQL> show user;

USER is "SYS"

SQL> conn scott/oracle

sConnected.

SQL>show user;

USER is "SCOTT"

SQL> conn hr/hr

Connected.

SQL> conn / as sysdba

Connected.

SQL> show user;

USER is "SYS"



sqlplus /nolog 登录需要connect 连接数据库

SQL> conn scott/oracle

Connected.

SQL> show user;

USER is "SCOTT"


上一篇:oracle包的创建

下一篇:Oracle虚拟索引

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...