手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

SQL*Plus 执行脚本时传递参数(@script_name var1,var2)

[日期:2013-03-06] 来源:Linux社区  作者:robinson [字体:大 中 小]

5、使用new_value子句

SQL> col ename new_value v_name  -->new_value的实质是将得到的结果赋值给v_name以便后续调用
SQL> select ename from emp where empno=7788;

ENAME
----------
SCOTT

SQL> select ename,job,sal from emp where ename='&v_name';
old  1: select ename,job,sal from emp where ename='&v_name'
new  1: select ename,job,sal from emp where ename='SCOTT'

ENAME      JOB              SAL
---------- --------- ----------
SCOTT      ANALYST        3000

--交互式方式使用new_value                      --Author : Robinson Cheng
--下面的脚本是从awrrpti.sql摘取部分片段来展示    --Blog : http://www.linuxidc.com
[Oracle@linux1 ~]$ more temp.sql
prompt
prompt Specify the Report Type
prompt ~~~~~~~~~~~~~~~~~~~~~~~
prompt Would you like an HTML report, or a plain text report?
prompt Enter 'html' for an HTML report, or 'text' for plain text
prompt  Defaults to 'html'

column report_type new_value report_type;    -->这个地方定义的new_value是关键
set heading off;
select 'Type Specified: ',lower(nvl('&&report_type','html')) report_type from dual;
set heading on;
prompt "Variable report_type value is :&report_type"

SQL> @temp.sql  -->执行时出现交互提示

Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plain text report?
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Enter value for report_type: html
old  1: select 'Type Specified: ',lower(nvl('&&report_type','html')) report_type from dual
new  1: select 'Type Specified: ',lower(nvl('html','html')) report_type from dual

Type Specified:  html

"Variable report_type value is :html"  -->变量的值传递给了report_type

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款