oracle 带参数查看?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3084516/
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
view with parameters?
提问by noo
Do I suppose correctly that it is not possible to create view with parameters?
我是否正确地认为无法创建带有参数的视图?
I've got a query with sub-query and in its where clause I need to specify parameter. Specifying where clause of view would not help. I would like to call simple view with parameters instead of the sending to the database complicated sql query. How would it be possible to do this?
我有一个带有子查询的查询,在它的 where 子句中我需要指定参数。指定视图的 where 子句无济于事。我想用参数调用简单视图,而不是发送到数据库复杂的 sql 查询。怎么可能做到这一点?
N.
N。
采纳答案by Kendrick
You should be able to use a table-valued function.
您应该能够使用表值函数。
回答by Rob van Wijk
You mention "specifying where clause of view would not help". Why not? My advice is to just create a view without the parameters, and use a "select * from view where [your predicates with your parameters]".
您提到“指定 where 视图子句无济于事”。为什么不?我的建议是只创建一个没有参数的视图,并使用“select * from view where [your predicates with your parameters]”。
If you really want to continue with parametrized views, then you can use application contexts in your where clause. You can read about them here in the documentation: http://download.oracle.com/docs/cd/E11882_01/network.112/e10574/app_context.htm#DBSEG011
如果您真的想继续使用参数化视图,那么您可以在 where 子句中使用应用程序上下文。您可以在文档中阅读有关它们的信息:http: //download.oracle.com/docs/cd/E11882_01/network.112/e10574/app_context.htm#DBSEG011
And hereis an example.
而这里就是一个例子。
Regards, Rob.
问候,罗伯。
回答by Rosen Nikolov
Try this: in your code:
试试这个:在你的代码中:
` ....
RDB$SET_CONTEXT('USER_SESSION', 'VARNAME','VALUE');
SELECT * FROM VIEW VIEWNAME;
...`
in your view definition:
在您的视图定义中:
SELECT * FROM TABLENAME
WHERE FIELDNAME=RDB$GET_CONTEXT('USER_SESSION', 'VARNAME');
that is.
那是。