shell oracle(sqlplus spool)

本文介绍了一个bash脚本如何引入环境变量、执行系统命令并进行数据查询、导出,包括读取配置文件、获取当前日期、创建目录、使用SQL查询数据库等关键步骤。

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

#!/bin/bash

#测试环境变量的引入
if [ -f /usr/local/tdneusoft/ORACLE_bill.profile ];then
    . /usr/local/tdneusoft/ORACLE_bill.profile
fi

#引入系统环境变量
if [ -f/usr/local/tdneusoft/Runtime_32bit.profile ];then
    . /usr/local/tdneusoft/Runtime_64bit.profile
fi

#引入用户的环境变量
sys=`uname`
if [ "$sys" == "Linux" ];then
    if [ -f~/.bash_profile ];then
        . ~/.bash_profile
    fi
else
    if [ -f~/.profile ];then
        . ~/.profile
    fi
fi

#加载环境变量

export RUN_DIR


#加载配置文件

. $RUN_DIR/etc/test_etc.ini


#取yyyymmdd格式的年月日

yyyymmdd=`date "+%Y%m%d"`

#创建文件存放目录
if [ ! -d $RUN_DIR/data/test ];then
    mkdir -p $RUN_DIR/data/test
fi


sqlplus -s $USERNAME/$PASSWD@$SID<<! > /dev/null

set echo off;
set feedback off;
set heading off;
set trimspool on;
set termout off;
set newpage 0;
set num 18;
set pagesize 0;
set linesize 3000;

spool $RUN_DIR/data/test/testfile_${yyyymmdd}.txt

select to_char(operate_date, 'yyyymmdd')
||'|'||
count(operate_date)
||'|'||
sum(pay_fee)*100
from bf_ppc_pay_fee_t
where operate_date < sysdate and operate_date > (sysdate - 2) and to_char(operate_date, 'yyyymmdd') = to_char(sysdate - 1, 'yyyymmdd') group by to_char(operate_date, 'yyyymmdd');

select flow_number
||'|'||
to_char(date, 'yyyymmddhh24miss')
||'|'||
fee*100
from test_table
where date < sysdate and date > (sysdate - 2) and to_char(date, 'yyyymmdd') = to_char(sysdate - 1, 'yyyymmdd');

spool off;

exit
!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值