How read a value in pl/sql procedure?

左心房为你撑大大i 提交于 2020-06-28 10:36:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!