Wednesday, 22 May 2013

How to print the name of the SQL script running, while running it?

Let's assume that for debugging purposes, we need to print the name of the SQL script that we are running, and this while running the script, meaning that we will need this info in the spool file.

What we need to do is to add 2 lines at the beginning of the script:


set appinfo on
select sys_context('USERENV', 'MODULE')  as "Running Script" from dual;


Example:


$>cat /tmp/1.sql

set appinfo on
select sys_context('USERENV', 'MODULE')  as "Running Script" from dual;


select * from dual;


$>sqlplus /

SQL*Plus: Release 11.1.0.7.0 - Production on Wed May 22 15:40:48 2013

Copyright (c) 1982, 2008, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> @/tmp/1

Running Script
--------------------------------------------------------------------------------
01@ /tmp/1.sql


D
-
X





No comments:

Post a Comment