带有绑定变量的Teradata动态SQL?

时间:2018-05-08 16:34:30

标签: sql teradata teradata-sql-assistant

是否可以在Teradata动态SQL语句中使用绑定变量?我无法在任何地方找到一个例子。我想做这样的事情:

DECLARE SQLString VARCHAR(1000)
SET SQLString = 'SELECT * FROM MyTable WHERE ColumnA = :variable1';

EXECUTE IMMEDIATE SQLString; --Can I pass something here for variable1 or do I have to concatenate and not use a bind variable?

由于

1 个答案:

答案 0 :(得分:2)

带有绑定变量的DML语句通常会多次执行,因此当您使用EXECUTE IMMEDIATE时没有绑定变量,您必须使用EXECUTE/PREPARE

DECLARE SQLstring VARCHAR(1000);
SET SQLstring = 'update MyTable SET ColumnA = ? where columnB = ?'; -- ? identify bind variables
PREPARE S1 FROM SQLstring;
EXECUTE S1 USING variable1, variable2;

请参阅Stored Procedure manual