Teradata BTEQ:IF 条件,使用运行时实际参数验证 SP 编译并导出 DDL

Teradata BTEQ : IF conditon , Validate SP compilation with runtime actual parameters & export DDL

BTEQ 相关问题 - 我正在像这样通过 BTEQ 编制 SP 列表

.compile file=sp1 ; 
.IF ERRORCODE <> 0 THEN .GOTO SQLERROR;
 compile file=sp2 ; 
.IF ERRORCODE <> 0 THEN .GOTO SQLERROR;
.logoff
 .quit

.LABEL  SQLERROR

  .logoff ;

  .quit ;

我有以下关于这些的问题

为什么 IF 没有锻炼?


这里即使Col1,Col2有问题e.g.而不是 Col1 我会把 Co l1 放在 SP 将编译。可以理解的是,存储过程调用的 运行 时间结果在编译时不会被评估。这导致无法检测到生成的 replace view DDL 中的任何类型的错误。有什么办法可以让 replace view 在 SP 编译时进行验证?

    sel foo_
        bar, foobar,Col.
        tb from db.tb 
    foo_bar is split across multiple lines .
# std BTEQ options are used. The \n is because I am echoing  all this to file
.SET ECHOREQ OFF \n
.set width 500
.set titledashes off \n
.set format off \n
.set rtitle '' \n
.export report file="$ph" \n
 show procedure $db.$tb ; \n
.export  reset ;  \n

Q1:BTEQ 简单地忽略了 DBMS 返回的任何 error/warning(不知道为什么)。如果你想在任何 error/warning 之后停止,你可以简单地使用 ACTIVITYCOUNT 而不是 ERRORCODE:

.compile file=sp1 ; 
.IF ACTIVITYCOUNT > 0 THEN .GOTO SQLERROR;

如果你想忽略警告,我不知道不先删除 SP 的可靠方法:

DROP PROCEDURE whatever;
.compile file=sp1 ; -- creates SP whatever
HELP PROCEDURE whatever ATTR;
.IF ERRORCODE = 5495 THEN .GOTO SQLERROR; -- 5495 = SP doesn't exist

Q2:无法验证动态 SQL,顾名思义,它是动态的,在实际提交之前对 DBMS 是未知的。

Q3:限定名称中句号周围的空格不会导致错误,db . td 很乐意被解析器接受。

foo_bar 不应跨行拆分,除非行太宽,只需使用 .set width 30000;

增加最大长度