gpt4 book ai didi

mySql 函数不返回任何内容

转载 作者:行者123 更新时间:2023-11-29 13:28:54 25 4
gpt4 key购买 nike

我正在创建这个应该返回随机字符串的函数:

create function createRandomString() returns Text
return concat(
char(round(rand()*25)),
char(round(rand()*25)),
char(round(rand()*25)),
char(round(rand()*25)),
char(round(rand()*25)),
char(round(rand()*25)),
char(round(rand()*25)),
char(round(rand()*25))
);

由于某种原因,这个函数没有返回任何内容......我不知道为什么......

当我在选择中使用完全相同的 concat() 时 - 它有效。

最佳答案

问题是您返回 0 到 25 之间的数值,这些数值不是放入字符串中的正常字符。添加 65 以从“A”开始:

create function createRandomString() returns Text
return concat(
char(round(rand()*25+65)),
char(round(rand()*25+65)),
char(round(rand()*25+65)),
char(round(rand()*25+65)),
char(round(rand()*25+65)),
char(round(rand()*25+65)),
char(round(rand()*25+65)),
char(round(rand()*25+65))
);

您可能还想阅读 ASCII 编码,以便更好地了解自己在做什么。

关于mySql 函数不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19755957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com