Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

oracle - How to call the filename of running SQL script?

I'm trying to run a series of script files but I would like for each script file to print its filename, for reporting.

So, the intent is to call each SQL file from a general script:

@SQL_File_1;
@SQL_File_2;
@SQL_File_n;

But I need each SQL to print it's results, so I need each to print:

DBMS_OUTPUT.PUT_LINE({Filename} || ' updated ' || {Number of records});

How to retrieve the filename? Can it be easily done?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are running SQL*Plus, then it can be done as per the comment but only if you've set APPINFO, eg

SQL> select module from v$session where sid = sys_context('USERENV','SID');

MODULE
----------------------------------------------------------------
SQL*Plus

SQL> host cat x:empmyfile.sql
select module from v$session where sid = sys_context('USERENV','SID');
SQL> @x:empmyfile.sql

MODULE
----------------------------------------------------------------
SQL*Plus

SQL> SET APPINFO ON
SQL> @x:empmyfile.sql

MODULE
----------------------------------------------------------------
01@ x:empmyfile.sql

That will also work with SQLcl.

I haven't used TOAD for a while but I think it also supports appinfo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...