SQL 如何编写批处理 (*.bat) 脚本以使用 BTEQ 执行 Teradata 查询?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8179291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:18:51  来源:igfitidea点击:

How to write batch (*.bat) script to execute Teradata query using BTEQ?

sqlbatch-fileteradata

提问by manuel

Below is the content of my script.bat :

以下是我的 script.bat 的内容:

@echo off

cd C:\Program Files\Teradata\Client.0\bin

bteq .LOGON server/username,password;

select date;

.LOGOFF

@echo off goto end

:end @echo exit

I have no problem with the logon, but it seems that bteq can't read my query statement:

我登录没有问题,但是似乎bteq无法读取我的查询语句:

select date;

选择日期;

It keeps prompting for input. Can anyone help me to get bteq to read and execute the query statement?

它不断提示输入。谁能帮我让 bteq 读取和执行查询语句?

I've tried the solutions online about input and output file:

我已经在线尝试了有关输入和输出文件的解决方案:

bteq <myscript.txt> mylog.log

but it didn't work either.

但它也不起作用。

回答by Micha? Powaga

You are going to need two files, one is a batch and the other one are the commands.

您将需要两个文件,一个是批处理文件,另一个是命令。

Batch file:

批处理文件:

echo off
cd C:\bteq_directory\
bteq < c:\commands.txt > c:\output.txt 2>&1
@echo off goto end
:end @echo exit

Commands:

命令:

.LOGON server/username,password
select date;
.LOGOFF

EDIT:

编辑:

Removed semicolon after .LOGON...

后去掉分号 .LOGON...

回答by Benjamin James

This is a bit late, but here is what I've found:

这有点晚了,但这是我发现的:

I save my BTEQ script in a file called BTScript.txt:

我将 BTEQ 脚本保存在一个名为 BTScript.txt 的文件中:

.LOGON <servername>/<username>,<password>;
.SET WIDTH 20000;
.SET separator '|';
.EXPORT FILE = C:\TEMP\testBTEQ.txt;
SELECT top 10 * ATABLENAME;
.LOGOFF
.EXIT

The setting of width is needed to prevent the data being truncated, it will not go to 20000 chars if the record isnt that long.

需要设置宽度来防止数据被截断,如果记录不是那么长,它不会达到 20000 个字符。

To run this I execute (my pc is set up to allow me to double click on the file in windows explorer to do this) on a .bat file the content of which are:

为了运行它,我在一个 .bat 文件上执行(我的电脑设置为允许我双击 Windows 资源管理器中的文件来执行此操作),其内容是:

echo off
bteq < C:\temp\BTScript.txt > c:\temp\bteqscriptout.txt 2>&1
@echo off goto end
:end @echo exit

The second file referred to here will contain the output from BTEQ.

这里提到的第二个文件将包含 BTEQ 的输出。