Call dynamic function name in SQL(在 SQL 中调用动态函数名)
问题描述
是否可以在 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
这篇关于在 SQL 中调用动态函数名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 SQL 中调用动态函数名
基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
