在 Teradata BTEQ 脚本中捕获存储过程输出

Capture stored procedure output in Teradata BTEQ script

我有以下 shell 脚本,它们使用 BTEQ 执行 Teradata 存储过程。存储过程 returns 一个名为 BATCH_KEY 的 varchar。您能否解释一下如何:

捕获 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=
in_P_ACTION=
in_P_START_DATETIME=
in_P_END_DATETIME=

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

这是解决方案,感谢我出色的团队成员:)

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=
in_P_ACTION=
in_P_START_DATETIME=
in_P_END_DATETIME=

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