致梦想

oracle数据库卸数及ddl导出

一.数据库卸数脚本

还是比较明了的,一看就明白。

unloaddevice.sh 

sqlplus atmpbat/atmpbat@inter @"./unloaddevice.sql";

DATE_LOAD_PRE=`date -d "1 day ago" "+%Y%m%d"`;

mv device_all.txt XT0251.device.${DATE_LOAD_PRE}.0000.dat

gzip XT0251.device.${DATE_LOAD_PRE}.0000.dat

unloaddevice.sql

set linesize 200

set pagesize 0

set echo off



set termout off

set heading off



set feedback off

spool device_all.txt

select DEV_CODE||'^A'||DEV_BANKCODE||'^A'||DEV_IPADDRESS||'^A'||DEV_CITYCODE||'^A'||DEV_BRANCHCODE||'^A'||DEV_GYH||'^A'||DEV_YLBH||'^A'||DEV_WXH||'^A'||DEV_ADDRESS||'^A'||DEV_COMMENT||'^A'||DEV_TYPE||'^A'||DEV_ENCRY||'^A'||DEV_VERNUM||'^A'||DEV_PACK||'^A'||DEV_BILLBOXCFG||'^A'||DEV_FTRNFLAG||'^A'||DEV_STATUS||'^A'||DEV_EXPCNT||'^A'||DEV_ANOMCODE||'^A'||DEV_NOWTRANS||'^A'||DEV_FTPPWD||'^A'||DEV_CAPCARD||'^A'||DEV_IDENCODE||'^A'||DEV_BATCH||'^A'||DEV_HSMTYPE||'^A'||DEV_MASTERFLAG||'^A'||DEV_MASTERKEY||'^A'||DEV_PINKEY||'^A'||DEV_MACKEY||'^A'||FOREIGN_FLAG||'^A'||'^A'  from device where DEV_BANKCODE='51082';

spool off

/
exit;

二.ddl导出

坑比较多,首先是sh中sqlplus后面接的用户名和密码,与sql中的schema名要一致,否则无法导出!

如果我们知道表名,怎么知道这张表的schema,即get_ddl第三个参数,

首先要切换到oracle用户,普通用户的话,无法用sysdba登录,显示权限不够!

su - oracle

sqlplus /nolog

conn sys

as sysdba

select username from sys.dba_users;  //查询所有的schema,其实也就是username,二者名字一致!

select table_name from sys.dba_tables where owner=‘schema名’   //查询schema下面表的名字

从而可以找到schema名字下的表名,确立二者的关系!

这里有个坑是,device表是ATMPDBA的,但是你用atmpbat用户登录,也可以查到该表的数据内容,就像上面数据库导数的例子,很奇怪!

gen_flg.sh

sqlplus atmpdba/atmpdba@inter @"./gen_ddl.sql";

DATE_LOAD_PRE=`date -d "1 day ago" "+%Y%m%d"`;

mv device_ddl.txt XT0251.device.${DATE_LOAD_PRE}.0000.flg

gen_ddl.sql

set heading off;

set echo off;

Set pages 999;

set long 90000;


spool device_ddl.txt

select dbms_metadata.get_ddl('TABLE','DEVICE','ATMPDBA') from dual;

spool off

/
exit;

 

posted on 2018-08-29 17:39  致梦想  阅读(5067)  评论(0编辑  收藏  举报

导航