在 SQL 中调用动态函数名
- 作者: 衕憶晩安
- 来源: 51数据库
- 2022-11-16
问题描述
是否可以在 SQL 中调用具有动态名称的函数?
Is it possible to call a function with a dynamic name in SQL?
例如:
SELECT functionid, (SELECT results FROM dbo.Function_*functionid*) AS results FROM List_of_Functions
这将为表 List_of_Functions 中的每一行调用不同的函数.
This would call a different function for every row in the table List_of_Functions.
还是我的想法都错了?
推荐答案
您将需要构建(输入或基于您的表动态构建)SQL 语句,如:
You will need to build (either type it in, or build it dynamically based on your table) a SQL statement like:
SELECT
functionid
,CASE functionid
WHEN 1 THEN dbo.Function_1()
WHEN 2 THEN dbo.Function_2()
WHEN 3 THEN dbo.Function_3()
END AS results
FROM List_of_Functions
与其构建所有这些函数,不如构建一个函数,然后传入一个函数可以用来区分处理的值,这不是更好吗?喜欢:
Instead of building all those functions, wouldn't it be better to build one function, and pass in a value that the function can use to differentiate the processing? like:
SELECT
functionid
,dbo.Function(functionid) AS results
FROM List_of_Functions_Parameters
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
