How to pass parameters when sqlplus executes a script file

Source: Internet
Author: User

D: \ test. SQL script:

  1. Select& 1From& 2;
  2. Exit;

Run the following command to pass the parameter: sqlplus "scott/tiger @ test" @ d: \ test. SQL sysdate dual

Note: The parameter must be represented by & [1-9]. Otherwise, you will be prompted to manually enter the parameter.

  1. C: \> sqlplus"Scott/tiger @ test"@ D: \ test. SQL sysdate dual
  2. D: \> sqlplus"Scott/tiger @ test"@ D: \ test. SQL sysdate dual
  3. SQL * Plus: Release 11.2.0.1.0 ProductionOnTuesday November 1 21:59:00 2011
  4. Copyright (c) 1982,201 0, Oracle.AllRights reserved.
  5. Connect:
  6. OracleDatabase11g Enterprise Edition Release 11.2.0.1.0-Production
  7. WithThe Partitioning, OLAP, Data MiningAnd RealApplication Testing options
  8. Original Value 1:Select& 1From& 2
  9. New value 1:SelectSysdateFromDual
  10. SYSDATE
  11. --------------
  12. September 11-11
  13. From OracleDatabase11g Enterprise Edition Release 11.2.0.1.0-Production
  14. WithThe Partitioning, OLAP, Data MiningAnd RealApplication Testing options disconnected
  15. Open
  16. D: \>

If the same value is used repeatedly in the script, IF & 1 = & 2:

D: \ tes2. SQL

  1. DeleteScott. empWhere No= & 1OrDeptno = & 2;
  2. Commit;

During execution, two parameters must be passed:

  1. Sqlplus"Scott/tiger @ test"@ D: \ test2. SQL 10 10


TIPS: If procedure is used, you do not need to pass multiple identical parameters, but only one parameter is required:

D: \ test3. SQL

  1. Declare
  2. Var_no number: = & 1;
  3. Begin
  4. DeleteScott. empWhere No= Var_noOrDeptno = var_no;
  5. Commit;
  6. End;

Sqlplus "scott/tiger @ test" @ d: \ test3. SQL 10

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.