我正在开发Oracle to TD迁移项目。在那里,我必须从Teradata SP编写一个外部文件,该文件是从bteq(通过unix中的ksh)调用的。我想过从bteq本身写一个文件,但问题是,我有很多变量,我不能在bteq中使用。请帮帮我。
先谢谢,
答案 0 :(得分:0)
正确编写调用BTEQ的KSH脚本可以包含UNIX环境变量。以下是我过去如何做到这一点的简单示例。我相信您可以将示例扩展为甚至包括在要执行的SQL语句中解析环境变量。
#!/usr/bin/ksh
###############################################################################
SHELL_NAME=`basename $0`
PRG_NAME=`basename ${SHELL_NAME} .ksh`
BTQLOG=${PRG_NAME}.log
BTQOUT=${PRG_NAME}.out
LOGON=${PRG_NAME}.con
#
CREATEUS='create_user.spl'
#
if [[ ! -e ${CREATEUS} ]]; then
echo "FAILED: Missing ${CREATEUS} - Place ${CREATEUS} in same location as ${SHELL_NAME}"
return 1
fi
#
bteq <<EOBTQ > ${BTQLOG} 2>&1
.run file=${LOGON};
.SET WIDTH 255;
/*
|| CREATE_USER Stored Procedure - This procedure is intended to be used by the individual SECADMIN user(s) to create databases
*/
.LABEL CREATE_USER_PROC
SELECT 'X' (TITLE '')
FROM DBC.TablesV
WHERE DatabaseName = 'SECADMIN'
AND TableName = 'CREATE_USER'
--AND TableKind = 'P'
;
.IF ACTIVITYCOUNT > 0 THEN .GOTO CREATE_ROLE_PROC;
.IF ERRORCODE > 0 THEN .QUIT ERRORCODE;
.COMPILE FILE = '${CREATEUS}';
.IF ERRORCODE > 0 THEN .QUIT ERRORCODE;
.LABEL EXIT_BTEQ
.QUIT ERRORLEVEL;
EOBTQ
#
STATUS=$?
#
if (( ${STATUS} != 0))
then
echo "FAILED: ${SHELL_NAME} completed with non-zero returne code - Check ${BTQLOG} for details"
else
echo "SUCCSSS: ${SHELL_NAME} - Check ${BTQLOG} for details"
fi
#
return ${STATUS}