sqlplus 執行指令檔時如何傳參數

來源:互聯網
上載者:User

d:\test.sql指令碼如下:

  1. select &1 from &2;  
  2. exit;   

執行時這樣傳參數:sqlplus "scott/tiger@test" @d:\test.sql sysdate dual

注意:參數必須用&[1-9]表示,不然傳不進去,會提示讓手動輸入參數

  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

  1. delete scott.emp where no=&1  or deptno=&2;  
  2. commit;  

執行時,就必須傳2個參數:

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


小竅門: 這時用procedure就可以不用傳多個相同的參數,則只用傳1個參數:

d:\test3.sql

  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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.