指令碼:線上重定義,從普通表到分割槽表,redefinition_table.sh
使用方法:
redefinition_table.sh -o 普通表 -i 分割槽表 -u 表所在的使用者名稱 -f 使用哪個方式重定義:[rowid|pk] -a 動作[redefine] -c oracle連線字串:ora_name/ora_pass@tnsname
-c 如果連線本地資料庫可以不指定,預設為/ as sysdba
-f 提供rowid或者pk兩個值,預設為pk
-a 表示需要執行那個動作,重定義還是終止定義。預設:redefine
redefinition_table.sh -o 普通表 -i 分割槽表 -u 表所在的使用者名稱 -f 使用哪個方式重定義:[rowid|pk] -a 動作[redefine] -c oracle連線字串:ora_name/ora_pass@tnsname
-c 如果連線本地資料庫可以不指定,預設為/ as sysdba
-f 提供rowid或者pk兩個值,預設為pk
-a 表示需要執行那個動作,重定義還是終止定義。預設:redefine
點選(此處)摺疊或開啟
-
#!/bin/bash
-
#by raysuen
-
#version 2.0
-
-
-
[ -e ~/.profile ] && . ~/.profile
-
[ -e ~/.bash_profile ] && . ~/.bash_profile
-
-
-
###################################################
-
#The function is check that the User exists in the database.
-
###################################################
-
CheckUser(){
-
sqlplus -s /nolog<<-RAY
-
set termout off;
-
set echo off;
-
set feedback off;
-
set verify off;
-
set heading off;
-
conn $2
-
select username from dba_users where username='$1';
-
RAY
-
}
-
-
-
###################################################
-
#The function is check that the table exists in the database.
-
###################################################
-
-
CheckTable(){
-
sqlplus -s /nolog<<-RAY
-
set termout off;
-
set echo off;
-
set feedback off;
-
set verify off;
-
set heading off;
-
conn $3
-
select table_name from dba_tables where owner='$1' and table_name='$2';
-
RAY
-
}
-
-
###################################################
-
#The function is check that can redefinition table.
-
###################################################
-
CanRedef(){
-
sqlplus -s /nolog<<-RAY
-
conn $1
-
set termout off;
-
set echo off;
-
set verify off;
-
set heading off;
-
$2
-
RAY
-
}
-
-
###################################################
-
#The function that redefinition table
-
###################################################
-
redefinitionTable(){
-
sqlplus -s /nolog<<-RAY
-
conn $4
-
set termout off;
-
set echo off;
-
set verify off;
-
set heading off;
-
alter session force parallel dml;
-
alter session force parallel query;
-
$5
-
DECLARE
-
num_errors PLS_INTEGER;
-
BEGIN
-
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('$1', '$2','$3',
-
DBMS_REDEFINITION.CONS_ORIG_PARAMS, TRUE, TRUE, TRUE, TRUE, num_errors);
-
END;
-
/
-
exec dbms_redefinition.sync_interim_table(uname => '$1',orig_table => '$2',int_table => '$3');
-
exec dbms_redefinition.finish_redef_table(uname => '$1',orig_table => '$2',int_table => '$3');
-
RAY
-
}
-
-
###################################################
-
#The function that abort table
-
###################################################
-
AbortTable(){
-
sqlplus -s /nolog<<-RAY
-
conn $4
-
set termout off;
-
set echo off;
-
set verify off;
-
set heading off;
-
DBMS_REDEFINITION.ABORT_REDEF_TABLE($1,$2,$3)
-
RAY
-
}
-
-
-
###################################################
-
#Checkt to chennect oracle
-
###################################################
-
CheckConnect(){
-
sqlplus /nolog<<-RAY
-
conn $1
-
RAY
-
}
-
-
-
-
###################################################
-
#The function for help
-
###################################################
-
-
func_help(){
-
echo "Example:"
-
echo " redefinition_table.sh -o origins_table -i interlayer_table -u user_name -f option_flag -a action -c ora_user/ora_passwd@tnsname"
-
echo "Value:"
-
echo " -c default value [/ as sysdba]"
-
echo " -f to use the way which redefine table."
-
echo " value: rowid/pk,default value: PK."
-
echo " -a specify a action which you want to do,default: redefine"
-
-
}
-
-
-
-
###################################################
-
#Entrance of the script
-
###################################################
-
-
###################################################
-
#get parameter
-
###################################################
-
if [ $# -lt 1 ];then
-
echo "no parameters"
-
exit 99
-
else
-
while (($#>=1))
-
do
-
#echo $#
-
if [ $1 == "-o" ];then #-o origins
-
shift
-
orig_table=`echo $1 | tr [a-z] [A-Z]`
-
shift
-
elif [ $1 == "-i" ];then #-i interlayer
-
shift
-
int_table=`echo $1 | tr [a-z] [A-Z]`
-
shift
-
elif [ $1 == "-u" ];then
-
shift
-
user_name=`echo $1 | tr [a-z] [A-Z]`
-
shift
-
elif [ $1 == "-c" ];then #conect string include ora_username/ora_pwd@tns_name
-
shift
-
oraConStr=`echo $1`
-
shift
-
elif [ $1 == "-f" ];then #option_flag default: dbms_redefinition.cons_use_pk. values: rowid/PK
-
shift
-
option_flag=`echo $1 | tr [a-z] [A-Z]`
-
shift
-
elif [ $1 == "-a" ];then #action, the value must be redifine/abort. default: redifine
-
shift
-
action=`echo $1 | tr [a-z] [A-Z]`
-
shift
-
elif [ $1 == "-h" ];then
-
func_help
-
exit 0
-
else
-
echo "Please enter right parameter!"
-
echo "-h,you can use the parameter to get help!"
-
exit 99
-
fi
-
done
-
fi
-
-
#echo $orig_table
-
#echo $int_table
-
#echo $user_name
-
-
###################################################
-
#Check that the value of orig_table
-
###################################################
-
if [ ! ${orig_table} ];then
-
echo "-o must be specified!"
-
exit 1
-
fi
-
###################################################
-
#Check that the value of int_table
-
###################################################
-
if [ ! ${int_table} ];then
-
echo "-i must be specified!"
-
exit 2
-
fi
-
###################################################
-
#Check that the value of user_name
-
###################################################
-
if [ ! ${user_name} ];then
-
echo "-u must be specified!"
-
exit 3
-
fi
-
-
###################################################
-
#Check whether is successful to connecting oracle
-
###################################################
-
[ ! ${oraConStr} ]&& oraConStr=' / as sysdba'
-
-
CheckConnect "${oraConStr}" | grep "Connected" > /dev/null 2>&1
-
if [ $? -ne 0 ];then
-
echo "it is fail to connect oracle using input connection string!"
-
exit 4
-
fi
-
-
###################################################
-
#Check whether the input user exists in the database.
-
###################################################
-
if [ ! `CheckUser ${user_name} ${oraConStr} | sed 's/\n//g'` ];then
-
echo "User:("${user_name}") dose not exists in database!"
-
exit 5s
-
fi
-
-
###################################################
-
#Check whether the input table exists in the database.
-
###################################################
-
if [ ! `CheckTable ${user_name} ${orig_table} ${oraConStr} | sed 's/\n//g'` ];then
-
echo "Table:("${orig_table}") dose not exists in database!"
-
exit 6
-
fi
-
if [ ! `CheckTable ${user_name} ${int_table} ${oraConStr} | sed 's/\n//g'` ];then
-
echo "Table:("${int_table}") dose not exists in database!"
-
exit 7
-
fi
-
-
-
###################################################
-
#Check the value of action be specified
-
###################################################
-
[ ! ${action} ] && action="REDEFINE"
-
-
###################################################
-
#Check whether can redefinition table.
-
###################################################
-
if [ ${action} == 'REDEFINE' ];then
-
if [ ! ${option_flag} ];then
-
option_flag="PK"
-
canRedStr="exec dbms_redefinition.can_redef_table(""'"$user_name"'"",""'"$orig_table"'"");"
-
startRedStr="exec DBMS_REDEFINITION.start_redef_table(uname => '"$user_name"',orig_table => '"$orig_table"',int_table => '"${int_table}"');"
-
elif [ ${option_flag} == "PK" ];then
-
canRedStr="exec dbms_redefinition.can_redef_table(""'"$user_name"'"",""'"$orig_table"'"");"
-
startRedStr="exec DBMS_REDEFINITION.start_redef_table(uname => '"$user_name"',orig_table => '"$orig_table"',int_table => '"${int_table}"');"
-
elif [ ${option_flag} == "ROWID" ];then
-
canRedStr="exec dbms_redefinition.can_redef_table(""'"$user_name"'"",""'"$orig_table"',dbms_redefinition.cons_use_rowid);"
-
startRedStr="exec DBMS_REDEFINITION.start_redef_table(uname => '"$user_name"',orig_table => '"$orig_table"',int_table => '"${int_table}"',options_flag => dbms_redefinition.cons_use_rowid);"
-
else
-
echo "you must specify value for -f,only rowid/pk."
-
exit 8
-
fi
-
-
if [ `CanRedef ${oraConStr} "${canRedStr}" | grep "successfully" | wc -l` -eq 0 ];then
-
echo ${orig_table}" can not redefine using "${option_flag}
-
exit 9
-
fi
-
###################################################
-
#begin to redefinit table
-
###################################################
-
redefinitionTable ${user_name} ${orig_table} ${int_table} "${oraConStr}" "${startRedStr}"
-
elif [ ${action} == 'ABORT' ];then
-
AbortTable ${user_name} ${orig_table} ${int_table} "${oraConStr}"
-
else
-
echo "The value of action only use [redefine|abort]."
-
exit 10
-
fi
-
-
-
-
###################################################
-
#core code
-
###################################################
-
#exec dbms_redefinition.can_redef_table('$1', '$2');
-
#exec DBMS_REDEFINITION.start_redef_table(uname => '$1',orig_table => '$2',int_table => '$3');
-
#DECLARE
-
# num_errors PLS_INTEGER;
-
#BEGIN
-
# DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('$1', '$2','$3',
-
# DBMS_REDEFINITION.CONS_ORIG_PARAMS, TRUE, TRUE, TRUE, TRUE, num_errors);
-
#END;
-
#/
-
#exec dbms_redefinition.sync_interim_table(uname => '$1',orig_table => '$2',int_table => '$3');
- #exec dbms_redefinition.finish_redef_table(uname => '$1',orig_table => '$2',int_table => '$3');
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28572479/viewspace-2151678/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 線上重定義與普通表改為分割槽表
- 線上重定義方式將普通表修改為分割槽表
- oracle 線上重新定義,普通表改變分割槽表,分割槽表可以更改型別、分割槽欄位等Oracle型別
- 線上重定義的操作步驟__普通錶轉換為分割槽表的實驗案例
- PG的非分割槽表線上轉分割槽表
- oracle 普通表-分割槽表改造流程Oracle
- LightDB 22.4 新特性之相容Oracle線上轉換普通表為分割槽表Oracle
- MySQL線上轉分割槽表(以及TiDB)MySqlTiDB
- oracle分割槽表和分割槽表exchangeOracle
- oracle分割槽表和非分割槽表exchangeOracle
- 實現MySQL表結構自動分割槽指令碼MySql指令碼
- 在oracle 9i下線上重定義表Oracle
- PostgreSQL分割槽表、繼承表記錄去重方法SQL繼承
- Oracle 12C新特性-線上把非分割槽錶轉為分割槽表Oracle
- 壓縮錶轉非壓縮表(線上重定義)
- 【MYSQL】 分割槽表MySql
- oracle 分割槽表move和包含分割槽表的lob moveOracle
- 移動分割槽表和分割槽索引的表空間索引
- PostgreSQL/LightDB 分割槽表之分割槽裁剪SQL
- Oracle分割槽表基礎運維-07增加分割槽(3列表分割槽)Oracle運維
- Oracle分割槽表基礎運維-04列表分割槽Oracle運維
- MySQL 分割槽表探索MySql
- 分割槽表-實戰
- 非分割槽錶轉換成分割槽表
- [oracle] expdp 匯出分割槽表的分割槽Oracle
- oracle將表配置為分割槽表Oracle
- Oracle分割槽表基礎運維-06分割槽表索引Oracle運維索引
- Oracle分割槽表基礎運維-01分割槽表分類Oracle運維
- SQL SERVER之分割槽表SQLServer
- ORACLE分割槽表梳理系列Oracle
- Spark操作Hive分割槽表SparkHive
- OceaBase 分割槽表建立技巧
- Mysql表分割槽實現MySql
- mysql 進行表分割槽MySql
- Mysql表分割槽實操MySql
- PostgreSQL:傳統分割槽表SQL
- PostgreSQL:內建分割槽表SQL
- Oracle 12.2之後ALTER TABLE .. MODIFY轉換非分割槽表為分割槽表Oracle