如果数据库中的数据发生更改怎么办,确定性关键字有什么作用?

what if data is changed in database, what does deterministic keyword do?

所以我在 mysql workbench:

中添加了这个存储函数
CREATE FUNCTION `getfullAdd` (id INT unsigned)
RETURNS VARCHAR(160)
CHARACTER SET utf8
COMMENT 'function that returns all addresses with character string when you enter customer number'
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE addfound VARCHAR(160) CHARACTER SET utf8;
SELECT CONCAT_WS(', ', addr01, addr02) INTO addfound FROM dtb_customer WHERE customer_id=id;
RETURN addfound;
END

我对这个 DETERMINISTIC 关键字有点陌生。

上面的函数有什么作用?

如果通过此关键字设置,函数return是否通过相同的参数获得相同的值?

如果客户的地址发生变化,此函数 return 是否会因同一参数而产生不同的结果?

来自手册

"A routine is considered “deterministic” if it always produces the same result for the same input parameters, and “not deterministic” otherwise. "

https://dev.mysql.com/doc/refman/5.7/en/create-procedure.html

所以只要 none 的客户 ID 发生变化,您的函数就是确定性的。