###不删除用户,导入数据
dd ()
{
sqlplus / as sysdba <<!
set echo off;
set feedback off;
set heading off;
set pagesize 0;
set termout off;
set trimout on;
set trimspool on;
set linesize 3000;
spool ./drop.sql ;
select 'drop table '||owner||'.'||table_name||' purge;' from dba_tables where owner=upper('$1');
select 'drop view '||owner||'.'||view_name||';' from dba_views where owner=upper('$1');
select 'drop procedure '||owner||'.'||OBJECT_NAME||';' from dba_procedures where owner=upper('$1');
spool off
exit
!
grep -v sql drop.sql >d.sql
sqlplus / as sysdba<<!
@d.sql;
@d.sql;
exit
!
}
chk ()
{
sqlplus / as sysdba <<!
set echo off;
set feedback off;
set heading off;
set pagesize 0;
set termout off;
set trimout on;
set trimspool on;
set linesize 3000;
spool chk.txt;
select count(*) from dba_objects where owner=upper('$1');
spool off
exit
!
var=`grep -v -i sql chk.txt`
if [ $var -ne 0 ]
then
echo "$1的对象未删除!"
exit
fi
}
if [ $# -ne 1 ]
then
echo "请输入删除的用户名!"
else
dd $1
chk $1
imp $1/$1 file=$1.dmp fromuser=$1
fi