问题
I am having problem regarding to scan a value in a pl/sql procedure. When I have execute the procedure, it ignores the a:='&a';.
Procedure Body
create or replace PROCEDURE Testing
IS
a VARCHAR2(3);
BEGIN
DBMS_OUTPUT.PUT_LINE('Enter a : ');
a:='&a';
END Testing;
Procedure Calling
SET SERVEROUTPUT ON;
cl scr;
Execute Testing;
Output
PL/SQL procedure successfully completed.
Enter a :
Can anybody help me, please!?
回答1:
In SQL*Plus we have the prompt and accept syntax, but there is no direct way to make PL/SQL interactive without using PHP, Apex, Java, Scripting. I am giving you example of scripting.
e.g. In Windows batch, following code will help.
1) Code for the Testing procedure is same what you have
create or replace PROCEDURE Testing (arg varchar2)
IS
a VARCHAR2(3);
BEGIN
a:=arg;
DBMS_OUTPUT.PUT_LINE('Value of a : '||a);
END
2) test.bat
sqlplus nd211/nd211 @Testing.sql te1
sqlplus nd211/nd211 @Testing.sql te4
3) Testing.sql
set serveroutput on
exec Testing('&1');
exit;
Testing; /
4) Sample output
Value of a : te1
PL/SQL procedure successfully completed.
Value of a : te4
PL/SQL procedure successfully completed.
来源:https://stackoverflow.com/questions/33329972/how-read-a-value-in-pl-sql-procedure