MYSQL从字段值中选择函数?

MYSQL从字段值中选择函数?,mysql,sql,Mysql,Sql,我有一个表格,其数据如下: id | function 1 | current_date 2 | UUID() 3 | RAND() 表的结构如下所示 id int,函数varchar(50) 查询:从func_表中选择* 我预期的结果是 id | function 1 | 2020-08-24 2 | 70d6cffc-ae01-11ea-80ca-c11529136ae3630 3 | 0.982584554752 提前感谢。您可以使

我有一个表格,其数据如下:

id | function
1  | current_date       
2  | UUID()       
3  | RAND()
表的结构如下所示

id int,函数varchar(50)

查询:从func_表中选择*
我预期的结果是

id | function
1  | 2020-08-24
2  | 70d6cffc-ae01-11ea-80ca-c11529136ae3630       
3  | 0.982584554752

提前感谢。

您可以使用一个巨大的
案例
表达式:

select (case when function = 'current_date' then cast(current_date as char)
             when function = 'uuid()' then cast(uuid as char)
             when function = 'rand()' then cast(rand as char)
        end) as value

如果您确实想要直接计算函数,那么您的数据模型可能有问题。SQL不直接支持此类功能。

您可以使用一个巨大的
大小写
表达式:

select (case when function = 'current_date' then cast(current_date as char)
             when function = 'uuid()' then cast(uuid as char)
             when function = 'rand()' then cast(rand as char)
        end) as value

如果您确实想要直接计算函数,那么您的数据模型可能有问题。SQL不直接支持这种功能。

请参阅关于
PREPARE
关于
PREPARE
这很好,但我的表中没有多少函数,所以这不是一种简单的方法。无论如何,谢谢你的支持,这很好,但是我的表中没有多少函数,所以这不是一个简单的方法。无论如何,谢谢你的支持