oracle|存储过程|数据|数据库
项目结束了,想把自己写的存储过程导出保存一份就写了这么一个简单的脚本,拿出来给大家共享一下。其实很简单,主要用到user_procedures、user_source两个视图,大家一看就知道了。
好像网上搜到的一些都不够全面,而且零零散散,如果觉得好的话就支持一下吧,'
#! /usr/bin/ksh
. ~/.profile
beginTime=` date +%Y年%m月%d日%H时%M分%S秒 `
bindir=~/work/common
prodir=~/work/common/procedure
#连接数据库(带参数-S)
ORA_S()
{
~/cfg/dbetl_S
}
#连接数据库(不带参数)
ORA()
{
~/cfg/dbetl
}
#获得存储过程名称
getProcedureName()
{
ORA_S <<! >${bindir}/procedure.lst
set heading off;
SET FEEDBACK OFF;
set pagesize 0 ;
set wrap off;
set echo off;
set term off;
set linesize 1000;
set trimspool on;
select object_name from user_procedures;
exit
!
}
#导出存储过程代码
exportProcedureSource()
{
ORA_S <<! >${prodir}/${procedure_name}.sql
set serveroutput on;
set heading off;
SET FEEDBACK OFF;
set pagesize 0 ;
set wrap off;
set echo off;
set term off;
set linesize 1000;
set trimspool on;
select text from user_source a where a.name = '${procedure_name}' order by a.line;
exit
!
}
##################### mian ##########################
getProcedureName
mkdir prodir
while read procedure_name
do
exportProcedureSource
done<${bindir}/procedure.lst
echo "begin at ${beginTime}"
echo "end at ` date +%Y年%m月%d日%H时%M分%S秒 `"