sqlplus 命令学习

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

[[email protected] ~]$ vim /home/oracle/.bash_profile

加入: export EDITOR=vi

[[email protected] ~]$ source /home/oracle/.bash_profile

[[email protected] ~]$ 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"

时间: 2024-08-27 20:01:15

sqlplus 命令学习的相关文章

(转)Linux命令学习总结:dos2unix - unix2dos

Linux命令学习总结:dos2unix - unix2dos 命令简介: 原文:http://www.cnblogs.com/kerrycode/p/5077969.html dos2unix是将Windows格式文件转换为Unix.Linux格式的实用命令.Windows格式文件的换行符为\r\n ,而Unix&Linux文件的换行符为\n. dos2unix命令其实就是将文件中的\r\n 转换为\n. 而unix2dos则是和dos2unix互为孪生的一个命令,它是将Linux&Un

linux五大搜索命令学习

五大搜索命令学习 分别解释locate,find,which,whereis,grep 五大linux搜索命令 locate 解释:由man手册可以看出,locate查找就是根据文件名进行查找,只是依赖于updatedb命令.该命令更新linux中的查找数据库/var/lib/locatedb 这个数据库中含有本地所有文件信息.Linux系统自动创建这个数据库,并且每天自动更新一次,所以使用locate命令查不到最新变动过的文件.为了避免这种情况,可以在使用 locate之前,先使用update

oracle sqlplus命令详解

涉及到的知识要点a.带有一个&的替换变量的用法b.带有两个&的替换变量用法c.define命令用法d.accept命令用法e.定制SQL*Plus环境f.在glogin.sql文件中保存定制结果g.sqlplus编辑命令 a.带有一个&的替换变量的用法1).使用带有一个&号的变量值来提示用户输入一个值.eg.SQL> SELECT     empno, ename, sal, deptno FROM  emp WHERE empno = &empno;输入 e

基础命令学习总结

基础命令总结: 1.获取帮助命令: help man info 2.日期时间命令: date hwclock cal 3.系统管理命令: shutdown halt reboot poweroff bash tty 4.文件管理命令: cd type file echo which  whereis whatis dirname basename makewhatis mkdir pwd      touch 基础命令学习总结,布布扣,bubuko.com

Git命令学习之旅——日志和穿梭版本号

在总结了git命令的基础之后,接下来我们看一下基础的一些进阶内容:删除撤销命令.日志查看命令等 既然有加入文件的功能,那么相相应的肯定有移除文件的功能,命令例如以下:git rm [文件名称] 在输入命令之后,例如以下图所看到的: 提示已经删除了"c.txt"文件.这个时候再用git status查看一下状态,例如以下图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JB

Java命令学习系列(7):Javap(转)

原文出处: Hollis(@Hollis_Chuang) javap是jdk自带的一个工具,可以对代码反编译,也可以查看java编译器生成的字节码. 一般情况下,很少有人使用javap对class文件进行反编译,因为有很多成熟的反编译工具可以使用,比如jad.但是,javap还可以查看java编译器为我们生成的字节码.通过它,可以对照源代码和字节码,从而了解很多编译器内部的工作. 实例 javap命令分解一个class文件,它根据options来决定到底输出什么.如果没有使用options,那么

linux shell 命令学习(5) xxd- make a hexdump or do the reverse.

对于标准输入或者给定的文件,显示其16进制的内容.也可以反过来进行转换. ? 1 2 3 xxd -h[elp] xxd [options] [infile [outfile]] xxd -r[evert] [options] [infile [outfile]] 如果没有指定输入文件, 则采用标准输入. -b: 以2进制格式进行输出 ? 1 2 3 4 [[email protected] src]$ xxd -b train.ini 0000000: 01011011 01110100 01

Linux命令学习之—每天发一个命令—mkdir

Linux命令学习之-每天发一个命令-mkdir mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1.命令格式: mkdir [选项] 目录... 2.命令功能: 通过 mkdir 命令可以实现在指定位置创建以 DirName(指定的文件名)命名的文件夹或目录.要创建文件夹或目录的用户必须对所创建的文件夹的父文件夹具有写权限.并且,所创建的文件夹(目录)不能与其父目录(即父文件夹)中的文件名重名,即同一个目录下不能

oracle sqlplus命令和常用函数

常用命令: 连接sqlplus命令行下运行cmd进入,如以sys模式登陆,命令如下:(1).sqlplus "sys/zhb126 as sysdba" (2).sqlplus/nolog  connect sys/zhb126 as sysdba (3).sqlplus scott/tiger 启动数据库实例 startup --启动数据库的同时启动控制文件.数据文件 startup mount --启动数据库的同时启动控制文件.不启动数据文件 startup nomount --仅