开发者

Oracle SQL Input Issue

I need to write a script that will prompt a database user in SQL+ to type in the name of a stored procedure and then that stored procedure's code will be displayed.

This will give me the prompt:

accept spinput prom开发者_如何学Cpt “Enter Stored Procedure Name:”

Then I can type in the stored procedure name.

Then if I run this code, the stored procedure code will be displayed.

select text from user_source
where type = 'PROCEDURE'
and name = ‘&spinput’;

How do I combine that all into a script that just asks for the input and runs the rest? What is the best way to do this?

Thanks!


Perhaps I'm missing something, but aren't you almost there? Can't you just combine your two statements into one file, along with some formatting commands in say, prc.sql:

set feedback off
set heading off
set verify off
accept spinput prompt "Enter Stored Procedure Name:"
select text from user_source
where type = 'PROCEDURE'
and name = UPPER('&spinput');
exit

Then run the following:

sqlplus -s user/pw @prc.sql

Your procedure text will be output to the screen.

I modified your query slightly to translate user input to upper case, since most of the time stored procedure names will be in upper case in the database. This means the user can type text without regard to case and the procedure will be found.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜