当前位置:网站首页>MySQL function syntax
MySQL function syntax
2022-04-23 02:41:00 【An effort to XX program yuan】
delimiter
stay mysql The role of command line operations : Specify a symbol as a SQL The end of the statement , The default is semicolon . One SQL At the end of the statement, it will execute , and procedure And function Semicolon in , So define procedure And function Before , You need to modify this symbol first . Such as :delimiter //
Variable
A variable called ‘@xxx’ form , No declaration required , Can be used directly , The default value is NULL( but procedure Or local variable names in functions without @, And need to declare , Format :declare Variable name datatype. but procedure Or functions and other structures can also be used directly ’@xxx’ Variable of form , And can be accessed externally )
SET Instructions
Variable assignment
Delete function
drop function if exists fn_name;
Specify the type of function
by function Specify a parameter . DETERMINISTIC, NO SQL and READS SQL DATA It is equivalent to a clear notice MySQL The server function does not modify the data
1 DETERMINISTIC affirmatory
2 NO SQL No, SQl sentence , Of course, it doesn't change the data
3 READS SQL DATA Just read the data , Of course, it doesn't change the data
4 MODIFIES SQL DATA To modify data
5 CONTAINS SQL Contains SQL sentence
Example
delimiter $$
CREATE FUNCTION `fn_cutAppName`(appName varchar(4000)) RETURNS varchar(4000) CHARSET utf8mb4
DETERMINISTIC
begin
DECLARE ret varchar(4000);
case when (appName like '% passport No %' or appName like '% ID number %') then
set @leftindex= LOCATE('(',appName);
if (@leftindex =0) then set @leftindex = LOCATE('(',appName); end if;
if (@leftindex =0) then set @leftindex = LOCATE(' passport No ',appName); end if;
if (@leftindex =0) then set @leftindex = LOCATE(' ID number ',appName); end if;
case when (@leftindex >0) then set ret = trim(left(appName,(@leftindex-1)));
else set ret = appName ;
end case;
else
set ret = appName;
end case;
return (select ret);
end
end $$
Call function
select fn_cutAppName(' Unlimited liability company ');
Reference resources :
https://blog.csdn.net/yuxin6866/article/details/52722913
https://blog.csdn.net/qq_19865749/article/details/68962005
版权声明
本文为[An effort to XX program yuan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230239165662.html
边栏推荐
- JVM运行时数据区(一)
- 基于Scrum进行创新和管理
- 5W of knowledge points
- 高效音乐格式转换工具Music Converter Pro
- Practical combat of industrial defect detection project (II) -- steel surface defect detection based on deep learning framework yolov5
- Program design: l1-49 ladder race, allocation of seats (simulation), Buxiang pill hot
- Step principle of logical regression in machine learning
- Looking for a job, writing a resume to an interview, this set of information is enough!
- How big the program development of single chip microcomputer project can be, it represents your level of knocking code
- 一、序列模型-sequence model
猜你喜欢

The 16th day of sprint to the big factory, noip popularization Group Three Kingdoms game

Renesas electronic MCU RT thread development and Design Competition

工业互联网+危化安全生产综合管理平台怎样建

How to solve the complexity of project document management?

基于Scrum进行创新和管理

一个国产图像分割项目重磅开源!

MySQL JDBC programming

Store consumption SMS notification template

Flink learning (XI) watermark

1、 Sequence model
随机推荐
Lighting LED of IAR embedded development stm32f103c8t6
Talk about current limiting
Understanding process (multithreading primary)
OCR识别PDF文件
MySQL / SQL Server判断表或临时表存在则删除
JVM运行时数据区(一)
Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet
RT_ Thread ask and answer
Class initialization and instance initialization interview questions
JDBC JDBC
[wechat applet] set the bottom menu (tabbar) for the applet
一、序列模型-sequence model
JVM类加载器
This is how the power circuit is designed
WordPress calls the specified page content. 2 get_ children()
电源电路设计原来是这么回事
Rhcsa day 4 operation
国产轻量级看板式Scrum敏捷项目管理工具
RT_Thread自问自答
Probabilistic model of machine learning