是否可以在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?
由于
答案 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;