d:\test.sql指令碼如下:
- select &1 from &2;
- exit;
執行時這樣傳參數:sqlplus "scott/tiger@test" @d:\test.sql sysdate dual
注意:參數必須用&[1-9]表示,不然傳不進去,會提示讓手動輸入參數
- C:\>sqlplus "scott/tiger@test" @d:\test.sql sysdate dual
-
- D:\>sqlplus "scott/tiger@test" @d:\test.sql sysdate dual
-
- SQL*Plus: Release 11.2.0.1.0 Production 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 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
-
- 原值 1: select &1 from &2
- 新值 1: select sysdate from dual
-
- SYSDATE
- --------------
- 01-11月-11
-
- 從 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options 斷
- 開
-
- D:\>
如果指令碼中有重複用到相同的值,如果&1=&2:
d:\tes2.sql
- delete scott.emp where no=&1 or deptno=&2;
- commit;
執行時,就必須傳2個參數:
- sqlplus "scott/tiger@test" @d:\test2.sql 10 10
小竅門: 這時用procedure就可以不用傳多個相同的參數,則只用傳1個參數:
d:\test3.sql
- 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