2017-03-23 123 views
0

我有以下使用BTEQ執行Teradata存儲過程的shell腳本。存儲過程返回一個名爲BATCH_KEY的varchar。您能否解釋如何:在Teradata BTEQ腳本中捕獲存儲過程輸出

捕獲存儲過程的輸出在BTEQ腳本中?將輸出傳遞給shell腳本?讓shell腳本自己返回輸出值?

echo "Check if number of parameters is correct" 
if [ "$#" -ne 4 ]; then 
    echo "You must enter exactly 4 command line arguments" 
    exit 0 
fi 

echo "Call bash profile" 
source ~/.bash_profile 

echo "Setting parameters value for the stored procedure" 
in_P_BATCH_OWNER=$1 
in_P_ACTION=$2 
in_P_START_DATETIME=$3 
in_P_END_DATETIME=$4 

echo "Logging into Teradata" 
Server=server 
LoginId=user 
Password=password 
DbName=db 

echo "Calling stored procedure" 
bteq<<EOF 
.logon ${Server}/${LoginId},${Password}; 
CALL $DbName.SP_AUDIT_BATCH('$in_P_BATCH_OWNER', '$in_P_ACTION', '$in_P_START_DATETIME', '$in_P_END_DATETIME'); 
.logoff; 
.quit; 
EOF 

if [ $? == 0 ] 
then 
    echo "Script executed sucessfully" 
    exit 1 
else 
    echo "Script executed with failure" 
    exit 0 
fi 

回答

0

這裏是解決方案,發現感謝我真棒團隊成員:)

echo "Check if number of parameters is correct" 
if [ "$#" -ne 4 ]; then 
    echo "You must enter exactly 4 command line arguments" 
    exit 1 
fi 

echo "Call bash profile" 
source ~/.bash_profile 

echo "Setting parameters value for the stored procedure" 
in_P_BATCH_OWNER=$1 
in_P_ACTION=$2 
in_P_START_DATETIME=$3 
in_P_END_DATETIME=$4 

echo "Logging into Teradata" 
Server=server 
LoginId=user 
Password=password 
DbName=db 

echo "Calling stored procedure" 
bteq<<EOF 
.logon ${Server}/${LoginId},${Password}; 
.export file=/opt/scripts/data_quality/batch_key.txt; 
CALL $DbName.SP_AUDIT_BATCH('$in_P_BATCH_OWNER', '$in_P_ACTION', '$in_P_START_DATETIME', '$in_P_END_DATETIME'); 
.export reset; 
.logoff; 
.quit; 
EOF 

if [ $? == 0 ] 
then 
    echo "BTEQ script executed sucessfully" 
    out_P_BATCH_KEY=`tail -1 /opt/scripts/data_quality/batch_key.txt` 
    echo "BATCH_KEY=$out_P_BATCH_KEY" 
    rm -f /opt/scripts/data_quality/batch_key.txt 
    exit $out_P_BATCH_KEY 
else 
    echo "BTEQ Script executed with failure" 
    exit 1 
fi