Delphi - View with parameter

血红的双手。 提交于 2019-12-25 08:24:56

问题


I have the following View:

CREATE OR ALTER VIEW "ButtonGroup_ButtonNames_view"("ButtonName")
AS
select "ButtonName"
from   "ButtonGroupName_ButtonName"
where  "ButtonGroupName_ButtonName"."ButtonGroupName" = ':lButtonGroupName'

The ':lButtonGroupName' is suppoused to work as a parameter, so at runtime I can set a value to it.

When I run the application, I get the parameter name not found error. I guess this is not the correct way to declare a parameter inside a view. Is it possible anyway?

Thanks.


回答1:


That's now how views work. You can provide parameters on the select query you use to fetch results from a view, but the view itself cannot have any parameters. There's no facility for passing parameters to a view that aren't already part of the query.

There wouldn't really be any optimization from such a "parameterized view" anyway. The database engine couldn't prefetch results because it won't know the parameter value until you do the query. Knowing that a certain column is parameterized, the database engine could make an index on that column, but you can just as easily index the column in the underlying table. The query against the view will use the same indices as a query against the table would.



来源:https://stackoverflow.com/questions/41285510/delphi-view-with-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!