sqlplus执行脚本文件时如何传参数

 

sqlplus执行脚本文件时如何传参数

分类: ORACLE

d:\test.sql脚本如下:

[sql]  view plain copy
  1. select &1 from &2;  
  2. exit;   


执行时这样传参数:sqlplus "scott/tiger@test" @d:\test.sql sysdate dual

注意:参数必须用&[1-9]表示,不然传不进去,会提示让手动输入参数

[sql]  view plain copy
  1. C:\>sqlplus "scott/tiger@test" @d:\test.sql sysdate dual  
  2.   
  3. D:\>sqlplus "scott/tiger@test" @d:\test.sql sysdate dual  
  4.   
  5. SQL*Plus: Release 11.2.0.1.0 Production on 星期二 11月 1 21:59:00 2011  
  6.   
  7. Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
  8.   
  9.   
  10. 连接到:  
  11. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production  
  12. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  13.   
  14. 原值    1: select &1 from &2  
  15. 新值    1: select sysdate from dual  
  16.   
  17. SYSDATE  
  18. --------------  
  19. 01-11月-11  
  20.   
  21. 从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production  
  22. With the Partitioning, OLAP, Data Mining and Real Application Testing options 断  
  23. 开  
  24.   
  25. D:\>  


 

如果脚本中有重复用到相同的值,如果&1=&2:

d:\tes2.sql

[sql]  view plain copy
  1. delete scott.emp where no=&1  or deptno=&2;  
  2. commit;  


执行时,就必须传2个参数:

[sql]  view plain copy
  1. sqlplus "scott/tiger@test" @d:\test2.sql 10 10  


小窍门: 这时用procedure就可以不用传多个相同的参数,则只用传1个参数:

d:\test3.sql

[sql]  view plain copy
  1. declare  
  2.     var_no number:=&1;  
  3. begin  
  4.     delete scott.emp where no=var_no or deptno=var_no;  
  5.     commit;  
  6. end;  


sqlplus "scott/tiger@test" @d:\test3.sql 10

版权声明:本文为博主原创文章,未经博主允许不得转载。

 


参考: sqlplus @脚本 百度
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值