sqlplus example

本文介绍了一个使用SQL Plus编写的Shell脚本,该脚本能够创建并运行一个SQL日志文件,其中包括通过PL/SQL块生成的日志条目以及直接通过SQL命令插入的数据。此脚本演示了如何设置输出环境、定义文件名、使用spool命令来捕获输出以及如何使用prompt命令进行注释。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

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/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值