d:\test.sql脚本如下:
[sql] view plain
select &1 from &2;  
exit;   
执行时这样传参数:sqlplus "scott/tiger@test" @d:\test.sql sysdate al
注意:参数必须用&[1-9]表示,不然传不进去,会提示让手动输入参数
[sql] view plain
C:\>sqlplus "scott/tiger@test" @d:\test.sql sysdate al  
  
D:\>sqlplus "scott/tiger@test" @d:\test.sql sysdate al  
  
SQL*Plus: Release 11.2.0.1.0 Proction on 星期二 11月 1 21:59:00 2011  
  
Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
连接到:  
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Proction  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  
原值    1: select &1 from &2  
新值    1: select sysdate from al  
  
SYSDATE  
--------------  
01-11月-11  
  
从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Proction  
With the Partitioning, OLAP, Data Mining and Real Application Testing options 断  
开  
  
D:\>  
如果脚本中有重复用到相同的值,如果&1=&2:
d:\tes2.sql
[sql] view plain
delete scott.emp where no=&1  or deptno=&2;  
commit;  
执行时,就必须传2个参数:
[sql] view plain
sqlplus "scott/tiger@test" @d:\test2.sql 10 10  
小窍门: 这时用procere就可以不用传多个相同的参数,则只用传1个参数:
d:\test3.sql
[sql] view plain
declare  
    var_no number:=&1;  
begin  
    delete scott.emp where no=var_no or deptno=var_no;  
    commit;  
end;  
sqlplus "scott/tiger@test" @d:\test3.sql 10
B. 如何在windons bat 脚本接受用户输入参数
@echo off&setlocal enabledelayedexpansion&title Copy file folder to local
color 0A
echo
===========Start to data===========
:start
cls
echo.请输入你要拷贝的源文件地址,比如:C:deptshared
set /p input_source=
echo.请输入目的文件地址,如:D:1
set /p input_dist=
if not exist "!input_source!" echo.你输入路径不存在!!&goto :start
if not exist "!input_dist!" echo.你输入路径不存在!!&goto :start
x !input_source! !input_dist! /s/d/y 1>nul 2>nul&&echo 拷贝完成!||echo 拷贝失败!
pause
C. 如何给shell脚本传参数
from:Linux命令行与shell脚本编程大全.第3版
向shell脚本传递数据的最基本方法是使用命令行参数。命令行参数允许在运行脚本时向命令行添加数据。
$ ./addem 10 30
本例向脚本addem传递了两个命令行参数( 10和30)。脚本会通过特殊的变量来处理命令行参数。下面是在shell脚本中使用单个命令行参数的简单例子。
$cattest1.sh
#!/bin/bash
#usingonecommandlineparameter
#
factorial=1
for((number=1;number<=$1;number++))
do
factorial=$[$factorial*$number]
done
echoThefactorialof$1is$factorial
$
$./test1.sh5
Thefactorialof5is120
$
