SQL 查询teradata中的用户定义变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25536635/
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
User-Defined variable in query teradata
提问by skmathur
I want to run a similar query at different times changing only one thing in the where clause and the table name that it's pulling from.
我想在不同的时间运行一个类似的查询,只更改 where 子句中的一件事以及它从中提取的表名。
declare ?tablename varchar(100);
set ?tablename = 'some_table_this_time';
declare ?id int;
set ?id = 12
select * from ?tablename
where my_id = ?id
This syntax does not work in teradata. I've used the @variable syntax in other sql programs, but cannot find the correct way in teradata.
此语法在 teradata 中不起作用。我在其他 sql 程序中使用过 @variable 语法,但在 teradata 中找不到正确的方法。
Research:
研究:
http://forums.teradata.com/forum/database/using-parameters-with-queries
http://forums.teradata.com/forum/database/using-parameters-with-queries
回答by Eric Falkenberg
There isn't a direct equivalent to that syntax in Teradata. Check out this blog post by Dieter for an interesting example of how to do something similar though:
Teradata 中没有与该语法直接等效的语法。查看 Dieter 的这篇博客文章,了解如何做类似的事情的有趣示例:
http://developer.teradata.com/blog/dnoeth/2011/03/global-and-session-level-parameters-in-sql
http://developer.teradata.com/blog/dnoeth/2011/03/global-and-session-level-parameters-in-sql