- GreatSQL The original content of the community shall not be used without authorization , For reprint, please contact the editor and indicate the source .
MySQL Of function There are various restrictions on creation , The limitations of frequently used statements are as follows :
1、CONTAINS_DYNAMIC_SQL
CREATE function f1() returns int
BEGIN
set @cmd = 'select * from t1';
PREPARE stmt1 FROM @cmd;
EXECUTE IMMEDIATE @cmd;
return 1;
END;SQL Error [1336] [0A000]: Dynamic SQL is not allowed in stored function or trigger
If in function Include when creating PREPARE,EXECUTE, DEALLOCATE, Then these will be judged to include DYNAMIC SQL, These grammars will be rejected . Because the purpose of using stored procedures is to prevent the use of strictly typed data SQL Inject . In this case sql The statement is fixed , It's gone prepare The meaning of using , So there is no need to create such a scenario ..
2、MULTI_RESULTS
CREATE function f1() returns int
BEGIN
select * from tb_tmp;
return 1;
END;SQL Error [1415] [0A000]: Not allowed to return a result set from a function
here select Statement will return multiple lines of results , and function Only one fixed result can be returned , Therefore, this situation is not allowed .
3、HAS_COMMIT_OR_ROLLBACK
CREATE function f1() returns int
BEGIN
commit;
return 1;
END;SQL Error [1422] [HY000]: Explicit or implicit commit is not allowed in stored function or trigger.
Because in procedure Of set x=fi() In the scene of , One set The statement contains begin work and commit work, If f1 Yes commit It will affect the management behind the transaction .
4、 Other situations
In addition to the above, there are other 2 Species will also be rejected : Namely HAS_SQLCOM_RESET、HAS_SQLCOM_FLUSH. Avoid when using .
5、 Additional explanation
stay procedure One of them contains begin and commit In addition to the above mentioned set, also IF, CASE, DECLARE, RETURN, These commands will be set when they are created open_tables=true, And then execute open_and_lock_tables, When the sub command is executed, proceed to rollback perhaps commit operation .
Enjoy GreatSQL :)
Explain profound theories in simple language MGR special column
1.MGR brief introduction | Explain profound theories in simple language MGR
https://mp.weixin.qq.com/s/lb...
2. Group replication technology architecture | Explain profound theories in simple language MGR
https://mp.weixin.qq.com/s/6_...
3. Installation and deployment MGR colony | Explain profound theories in simple language MGR
https://mp.weixin.qq.com/s/Nh...
4. utilize MySQL Shell Installation and deployment MGR colony | Explain profound theories in simple language MGR
https://mp.weixin.qq.com/s/51...
5.MGR Management and maintenance | Explain profound theories in simple language MGR
https://mp.weixin.qq.com/s/D5...
Article recommendation :
MySQL Principle and construction process of master-slave replication
https://mp.weixin.qq.com/s/X2...
MySQL Master slave copy GTID Model is introduced
https://mp.weixin.qq.com/s/9g...
MySQL Semi synchronous master-slave replication (semi-sync replication)
https://mp.weixin.qq.com/s/Bh...
Linux Summary of environmental monitoring tools
https://mp.weixin.qq.com/s/SY...
MySQL Test Run Introduction to testing framework
https://mp.weixin.qq.com/s/JA...
About GreatSQL
GreatSQL It is maintained by Wanli database MySQL Branch , Focus on Improvement MGR Reliability and performance , Support InnoDB Parallel query feature , It is suitable for financial grade applications MySQL Branch version .
Gitee:
https://gitee.com/GreatSQL/Gr...
GitHub:
https://github.com/GreatSQL/G...
Bilibili:
https://space.bilibili.com/13...
WeChat &QQ Group :
Searchable add GreatSQL Community assistant wechat friend , Send verification information “ Add group ” Join in GreatSQL/MGR Exchange wechat group
QQ Group :533341697
Wechat assistant :wanlidbc
This article by the blog one article many sends the platform OpenWrite Release !
![[opencv learning] perspective transformation matrix](/img/6e/7a53b257f6baafe8a3ae21cd0fe340.jpg)


![CS for mobile security [nethunter]](/img/25/ad99256a1eebb09f639e95d00756a5.jpg)




![[Part 7] source code analysis and application details of cyclicbarrier [key]](/img/bc/8ba2b86e599539a29683a63d02f0f7.jpg)
