Welcome 微信登录

首页 / 数据库 / MySQL / 替代变量与SQL*Plus环境设置

1.SQL与PL/SQL代码终止符    SQL代码以";"来表示代码的终止    PL/SQL代码以"."来表示代码的终止,以"/"表示代码的执行        scott@ORCL> select * from emp where empno=7788;            EMPNO ENAME      JOB              MGR HIREDATE       SAL     COMM   DEPTNO        ---------- ---------- --------- ---------- --------- ---------- ---------- ----------              7788 SCOTT      ANALYST       7566 19-APR-87     3100                    20         scott@ORCL> declare v_ename varchar2(10);          2  begin          3  select ename into v_ename from emp where empno=7788;          4  dbms_output.put_line("Employee Name: "||v_ename);          5  exception          6      when no_data_found then          7      dbms_output.put_line("There is no employee");          8  end;          9  .        scott@ORCL> /        Employee Name: SCOTT         PL/SQL procedure successfully completed.     2.替代变量       &变量名、&&变量名    执行时,如果&变量名,没有赋值的话,会提示输入变量值         scott@ORCL> select * from emp where empno=&no;        Enter value for no: 7788        old 1: select * from emp where empno=&no        new 1: select * from emp where empno=7788            EMPNO ENAME      JOB              MGR HIREDATE       SAL     COMM   DEPTNO        ---------- ---------- --------- ---------- --------- ---------- ---------- ----------              7788 SCOTT      ANALYST       7566 19-APR-87     3100                    20         scott@ORCL> save /u01/bk/scripts/select_empno.sql        Created file /u01/bk/scripts/select_empno.sql        scott@ORCL> @/u01/bk/scripts/select_empno.sql        Enter value for no: 7788        old 1: select * from emp where empno=&no        new 1: select * from emp where empno=7788            EMPNO ENAME      JOB              MGR HIREDATE       SAL     COMM   DEPTNO        ---------- ---------- --------- ---------- --------- ---------- ---------- ----------              7788 SCOTT      ANALYST       7566 19-APR-87     3100                    20     set verify 的使用                scott@ORCL> set verify off --使用set verify off来关闭替代变量使用时的提示,即执行SQL语句前不显示使用的变量值        scott@ORCL> @/u01/bk/scripts/select_empno.sql        Enter value for no: 7788            EMPNO ENAME      JOB              MGR HIREDATE       SAL     COMM   DEPTNO        ---------- ---------- --------- ---------- --------- ---------- ---------- ----------              7788 SCOTT      ANALYST       7566 19-APR-87     3100                    20        对于字符型和日期型数据,替代变量要加单引号( " " ),将变量括起来        select * from emp where job="&job"     &&  对输入变量的再次引用,同时会保存变量的值        scott@ORCL> set serveroutput on;        scott@ORCL> begin          2  dbms_output.put_line("The num is "||&&num); --使用双&&保存了变量num的值          3  dbms_output.put_line("The second num is "||&num);  --因此第二次输出变量num也是          4  end;          5  /        Enter value for num: 10        The num is 10        The second num is 10       替代变量的设置        set define character    --修改缺省的替代变量符号为其他符号,但不能使用数字和空格        set define on         --启用替代变量        set define off          --关闭替代变量               scott@ORCL> set define off        scott@ORCL> @/u01/bk/scripts/select_empno.sql        SP2-0552: Bind variable "NO" not declared.
  • 1
  • 2
  • 下一页
SQL*Plus 执行脚本时传递参数(@script_name var1,var2)Data Guard日志传输优化------网络传输优化实践相关资讯      SQL*PLUS 
  • Oracle基础介绍及常用相关SQL*PLUS  (03月11日)
  • Linux 下如何 sql*plus 实现上下键  (01/21/2014 14:03:29)
  • SQL*Plus copy 命令处理大批量数据  (05/02/2013 17:43:20)
  • 在sql*plus中如何查看一些命令的用  (02/19/2015 15:50:02)
  • SQL*Plus break与compute的简单用  (05/02/2013 17:48:07)
  • SQL*PLus 帮助手册(SP2-0171)  (04/26/2013 08:29:38)
本文评论 查看全部评论 (0)
表情: 姓名: 字数

<