在teradata中的sql语句中使用string执行immediate

时间:2014-07-02 02:25:34

标签: sql teradata dynamic-sql execute-immediate

我在Teradata中使用execute immediate时遇到了问题。

SET str_sql = 'UPDATE TABLE
                    SET COLA = 0';
EXECUTE IMMEDIATE str_sql;

上面的代码工作正常。

SET str_sql = 'UPDATE TABLE
                    SET COLA = 0,
                        COLB = ''test''';
EXECUTE IMMEDIATE str_sql;

上面带有字符串的代码返回错误。

以下是错误消息:

Executed as Single statement.  Failed [3706 : 42000] Table:Syntax error: expected   something between a string or a Unicode character literal and the word 'test'. 
Elapsed time = 00:00:00.212 

STATEMENT 1: CALL  failed. 

任何人都知道如何在sql中使用String调用execute immediate? 谢谢!

Frank Liu

1 个答案:

答案 0 :(得分:0)

问题可能出在报价上。而不是这个

SET str_sql = 'UPDATE TABLE
                SET COLA = 0,
                    COLB = ''test''';
EXECUTE IMMEDIATE str_sql;

使用双引号。

SET str_sql = 'UPDATE TABLE
                SET COLA = 0,
                    COLB = 'test'';
EXECUTE IMMEDIATE str_sql;