1. 程式人生 > >用指令碼呼叫Oracle儲存過程

用指令碼呼叫Oracle儲存過程

先準備好一個sql指令碼demo.sql

set serveroutput on
declare
  v_name dept.dname%type;
begin
select dname into v_name from dept where deptno=&1;
dbms_output.put_line('department name is: '||v_name);
end;
/
exit;

然後在終端下執行:

sqlplus "scott/[email protected]" @demo.sql 20

返回:

SQL*Plus: Release 9.2.0.4.0 - Production on Thu Oct 17 21:37:28 2013


Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.




Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production


old   4: select dname into v_name from dept where deptno=&1;
new   4: select dname into v_name from dept where deptno=20;
department name is: RESEARCH


PL/SQL procedure successfully completed.


Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

注意:我們可以給指令碼傳引數,在指令碼中用&1,&2這樣的引數