File aa.sh :
-----------------------------------------------------------------------------------------------------------------------------------
sqlplus -s username/password@DBname <<!!!
set echo off
set verify off
set serveroutput on size 100000
column fname new_value fname noprint
SELECT 'mylog_' || to_char(sysdate, 'yymmdd_sssss') ||'.log' fname FROM dual;
spool &fname
begin
dbms_output.put_line('===========================================');
dbms_output.put_line('First insert: inserted &fname
');
dbms_output.put_line('===========================================');
end;
/
prompt ===========================================
prompt Second insert just using SQL
prompt ===========================================
spool off
----------------------------------------------------------------------------------------------------------------------------------
running as below :
-----------------------------------------------------------------------------------
[username@servername dxy]$ ./sqltest.sh
===========================================
First insert: inserted mylog_100909_41579.log
===========================================
PL/SQL procedure successfully completed.
===========================================
Second insert just using SQL
===========================================
--------------------------------------------------------------------------------------
NOTES:
1. column fname1 new_value fname2 noprint
fname1 : define a nuew column
fname2 : is the holder of fnam21
can use it like : & finame2 (as showed in the above &fname )
2.note the usage of spool and prompt
Reference:
http://www.orafaq.com/forum/t/37241/2/