替代变量

1.&+标识符  替代变量 类似于其它语言进行变量赋值

[email protected]>select ename,&aa from emp;
Enter value for aa: job
old   1: select ename,&aa from emp
new   1: select ename,job from emp

ENAME                JOB
-------------------- ------------------
SMITH                CLERK
ALLEN                SALESMAN
WARD                 SALESMAN
JONES                MANAGER
MARTIN               SALESMAN
BLAKE                MANAGER
CLARK                MANAGER
SCOTT                ANALYST
KING                 PRESIDENT
TURNER               SALESMAN
ADAMS                CLERK
JAMES                CLERK
FORD                 ANALYST
MILLER               CLERK

14 rows selected.

2.define 查看当前的环境变量

  define aa=1 定义一个环境变量

  undefine aa 取消环境变量的定义

  && aa  定义一个环境变量

  该定义只在当前会话有效

  set verify off 关闭 新老变量的数值提示

[email protected]>define
DEFINE _DATE           = "28-APR-17" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "sales" (CHAR)
DEFINE _USER           = "SCOTT" (CHAR)
DEFINE _PRIVILEGE      = "" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000400" (CHAR)
DEFINE _EDITOR         = "vim" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE      = "1102000400" (CHAR)
DEFINE GNAME           = "[email protected]" (CHAR)
[email protected]>define aa=1;
[email protected]>define
DEFINE _DATE           = "28-APR-17" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "sales" (CHAR)
DEFINE _USER           = "SCOTT" (CHAR)
DEFINE _PRIVILEGE      = "" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000400" (CHAR)
DEFINE _EDITOR         = "vim" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE      = "1102000400" (CHAR)
DEFINE GNAME           = "[email protected]" (CHAR)
DEFINE AA              = "1" (CHAR)
[email protected]>undefine aa
[email protected]>define
DEFINE _DATE           = "28-APR-17" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "sales" (CHAR)
DEFINE _USER           = "SCOTT" (CHAR)
DEFINE _PRIVILEGE      = "" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000400" (CHAR)
DEFINE _EDITOR         = "vim" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE      = "1102000400" (CHAR)
DEFINE GNAME           = "[email protected]" (CHAR)
[email protected]>select &&aa from dual;
Enter value for aa: 1
old   1: select &&aa from dual
new   1: select 1 from dual

         1
----------
         1

[email protected]>define
DEFINE _DATE           = "28-APR-17" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "sales" (CHAR)
DEFINE _USER           = "SCOTT" (CHAR)
DEFINE _PRIVILEGE      = "" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000400" (CHAR)
DEFINE _EDITOR         = "vim" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE      = "1102000400" (CHAR)
DEFINE GNAME           = "[email protected]" (CHAR)
DEFINE AA              = "1" (CHAR)

3.保存命令成脚本

  1.list 查看最后一条命令(l)

  2.save a.sql 保存命令到a.sql 脚本文件中去

  3.get a.sql 查看a.sql 脚本

  [email protected] 执行脚本

  5.set echo on 打开执行脚本时,显示脚本内容

[email protected]>l
  1  select sum(decode(to_char(hiredate,‘yyyy‘),1980,1,0)) "1980",
  2  sum(decode(to_char(hiredate,‘yyyy‘),1981,1,0)) "1981",
  3  sum(decode(to_char(hiredate,‘yyyy‘),1982,1,0)) "1982",
  4  sum(decode(to_char(hiredate,‘yyyy‘),1987,1,0)) "1987"
  5* from emp
[email protected]>save 1.sql;
Created file 1.sql
[email protected]>get 1.sql
  1  select sum(decode(to_char(hiredate,‘yyyy‘),1980,1,0)) "1980",
  2  sum(decode(to_char(hiredate,‘yyyy‘),1981,1,0)) "1981",
  3  sum(decode(to_char(hiredate,‘yyyy‘),1982,1,0)) "1982",
  4  sum(decode(to_char(hiredate,‘yyyy‘),1987,1,0)) "1987"
  5* from emp
[email protected]>@ 1.sql

      1980       1981       1982       1987
---------- ---------- ---------- ----------
         1         10          1          2
[email protected]>set echo on
[email protected]>@ 1.sql
[email protected]>select sum(decode(to_char(hiredate,‘yyyy‘),1980,1,0)) "1980",
  2  sum(decode(to_char(hiredate,‘yyyy‘),1981,1,0)) "1981",
  3  sum(decode(to_char(hiredate,‘yyyy‘),1982,1,0)) "1982",
  4  sum(decode(to_char(hiredate,‘yyyy‘),1987,1,0)) "1987"
  5  from emp
  6  /

      1980       1981       1982       1987
---------- ---------- ---------- ----------
         1         10          1          2

4.set命令变量

  feedback  在select一个表的时候,在最下方显示共有多少行,默认在函数大于6的时候才显示。

  

一般使用SQL PLUS导出数据时一般使用以下参数就可以了。

set echo off; -- 不显示脚本中的每个sql命令(缺省为on)
set feedback off; -- 禁止回显sql命令处理的记录条数(缺省为on)
set heading off; -- 禁止输出标题(缺省为on)
set pagesize 0; -- 禁止分页输出
set linesize 1000; -- 设置每行的字符输出个数为1000,放置换行(缺省为80 )
set numwidth 16; -- 设置number类型字段长度为16(缺省为10)
set termout off; -- 禁止显示脚本中命令的执行结果(缺省为on)
set trimout on; -- 去除标准输出每行的行尾空格(缺省为off)
set trimspool on; -- 去除spool输出结果中每行的结尾空格(缺省为off)

sqlplus维护系统变量 也称set变量 利用它可为sqlplus交互建立一个特殊的环境 如:设
 置number数据的显示宽度 设置每页的行数 设置列的宽度等。可用set命令改变这些系统变
 量 也可用show命令列出它们.

5.host命令 在oracle 下直接调用系统命令

6.假脱机

  1)spool 1.txt 开启假脱机 保存到1.txt文件中去

  2)spool off 关闭假脱机状态

  3)spool 1.txt append  继续追加到1.txt 文件中去

时间: 2024-08-27 08:36:19

替代变量的相关文章

oracle中关于替代变量,accpt,绑定变量,字符变量

此文档介绍两个事情,一个是替代变量,另一个就是了解一下硬解析和软解析对于变量来说declare定义的好还是variable定义的好 在oracle 中,对于一个提交的sql语句,存在两种可选的解析过程, 一种叫做硬解析,一种叫做软解析.一个硬解析需要经解析,制定执行路径,优化访问计划等许多的步骤.硬解释不仅仅耗费大量的cpu,更重要的是会占据重要的们闩(latch)资源,严重的影响系统的规模的扩大(即限制了系统的并发行),而且引起的问题不能通过增加内存条和cpu的数量来解决.之所以这样是因为门闩

SQL Fundamentals:Substitution Variables(替代变量)

Substitution Variables(替代变量) 在WHERE子句中,通过使用替代变量来代替精确的值,就可以用不同的值运行同一个查询. Use substitution variables to: Temporarily store values with single-ampersand(&) and double-ampersand(&&) substitution Use substitution variables to supplement the followi

SQL Fundamentals:替代变量(&,&&)以及DEFINE,UNDEFINE,ACCEPT指令

替代变量 利用替代变量可以实现数据操作的交互性.替代变量的操作类似于键盘输入操作. 所谓的替代变量,指的就是在进行查询或更新操作时,某些数据是由用户所输入的,而这些数据前可以使用“&”标记. 替代变量的使用 1.使用“&”定义替代变量 在WHERE子句中使用替代变量 1.直接使用替代变量:&inputsal,这个时候系统会弹出一个框,让你输入替代变量的值 SELECT ename,job,sal,hiredate FROM emp WHERE sal>&inputsa

替代变量-----from cyber

--&变量名,&&变量名简析----------------------------------------------------------- 1 set verify on; 2 select * from tcpn_jodsmapping where productid = '&ProductID' and producteffdate = '&ProductEffdate' 3 ORDER by '&ProductID'; 4 select * f

SQL 基础之order by 排序和代替变量(六)

使用 ORDER BY 子句排序: – ASC:升序,默认 – DESC:降序 ORDER BY 子句在SELECT 语句结尾,可使用列别名: 1.查找工资在7000-10000之间的数字并去重,升序排序 select distinct salary  from employees where salary  between 7000 and 10000 order by salary; 2.查找名字.部门并按照入职日期进行升序 select last_name,department_id,hi

SQL*Plus中替换变量与定义变量

替换变量 SQL*Plus中的替换变量又叫替代变量,它一般用来临时存储相关数据:在SQL语句之间传递值.一般使用&或&&前缀来指定替换变量. 关于使用替换变量,一般是利用其创建通用的脚本或达到和用户交换目的.如下所示: 例如,我需要查看表的相关信息,如果不使用替换变量,每次查询我都要修改脚本.非常不便,如果使用替换变量,我们可以将下面脚本存放在tab.sql脚本中,每次运行时,只需要输入替换变量的值就可以了. COL LOGGING FOR A7;   COL OWNER FOR

Shell特殊扩展变量的实践

博主名:李常明 博客地址:http://keep88.blog.51cto.com 此笔记出自老男孩书籍:跟老男孩学linux运维  shell编程实战 特殊扩展变量 1.${parameter:-word}功能实践 ${parameter:-word}的作用是如果parameter变量值为空或未赋值,则会返回word字符串替代变量的值 例如: [[email protected] ~]# echo $test    #>==   此时test变量未赋值 [[email protected] ~

PL/SQL 02 声明变量 declare

语法:identifier [CONSTANT] datatype [NOT NULL] [:= | DEFAULT expr] identifier:用于指定变量或常量的名称.CONSTANT:用于指定常量.当定义常量时,必须指定它的初始值,并且其数值不能变.datatype:用于指定变量或常量的数据类型.NOT NULL:用于强制初始化变量(不能为NULL).当指定 NOT NULL 选项时,必须要为变量提供数值.:= 用于为变量和常量指定初始值.DEFAULT:用于为常量和变量指定初始值.

自定义IDEA编辑模板变量 (Edit Template Variables )

annotated("annotation qname") 注释("注释属性") 创建带有指定位置的注释的类型符号.例如,在迭代组中查看活动模板. arrayvariable() 建议适用于当前范围的所有数组变量.例如,在迭代组中查看活动模板. anonymoussuper() 提出一种科特林级对象表达类型. сamelcase(字符串) 返回作为参数传递的字符串,转换为骆驼格.例如,我的文本文件/我的文档/ my_text_file将转换为mytextfile.