MySQL之自定义存储函数与流程控制

自定义存储函数与流程控制
1.创建无参数的函数
CREATE FUNCTION f1() RETURNS VARCHAR(30)
##                函数名    返回值类型
  RETURN DATE_FORMAT(NOW(),'%年%m月%日 %H点:%i分:%s秒');

SELECT f1();

2.创造有参数的函数
CREATE FUNCTION f2(num1 SMALLINT UNSIGNED,num2 SMALLINT UNSIGNED) 
  RETURNS FLOAT(10,2) UNSIGNED
## 注意是RETURNS
  RETURN (num1+num2)/2;

SELECT f2(1,5);

#delimiter 修改MySQL的结束符 declare 声明变量 returns定义返回值类型
#判断奇偶性
delimiter $$
CREATE FUNCTION f3(j int )
RETURNS int 
BEGIN 
  DECLARE i int ;
    if i%2=0 THEN
       RETURN 0;
   ELSE 
      RETURN 1;
  end if;
end $$
delimiter;

#判断2个数中的最大的数
BEGIN
  DECLARE k int;
  IF i > j THEN
     set  k=i ;
   ELSE
    set  k=j ;
  end if;
  RETURN k;
end

#给出学生的成绩判断他的评价
delimiter $$
CREATE FUNCTION score1(i int)
RETURNS char(6)
BEGIN
    DECLARE j int ;
    DECLARE cj char(6);
    case FLOOR(j/10)
       when 10 then set cj='优秀';
       when 9 then set cj='优秀';
       when 8 then set cj='良好';
       when 7 then set cj='中等';
       when 6 then set cj='合格';
       else set cj = '不合规';
    end case;
   RETURN cj;
end $$
delimiter;

### 查找与 Spring Boot 3.4.1 兼容的 Spring CloudSpring Cloud Alibaba 版本 对于 Spring Boot 3.4.1 的兼容性,建议使用特定版本Spring CloudSpring Cloud Alibaba 来确保最佳集成效果。 #### Spring Cloud 版本 Spring Boot 3.x 系列通常对应于较新的 Spring Cloud 发布列车版本。具体来说,Spring Boot 3.4.1 应该匹配 Spring Cloud 2022.0.x 或更高版本[^1]。这些发布列车版本提供了对最新特性和改进的支持,并修复了许多已知问题。 #### Spring Cloud Alibaba 版本 为了使 Nacos Discovery 组件正常工作并解决潜在的依赖冲突(如 `snakeyaml`),推荐使用的 Spring Cloud Alibaba 版本应为 2022.0.0 及以上版本[^2]。此版本不仅解决了与 Spring Boot 3.x 的兼容性问题,还引入了一些重要的优化和错误修正。 以下是配置 `pom.xml` 中的相关依赖项示例: ```xml <dependencies> <!-- spring cloud alibaba nacos discovery --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>${spring-cloud-alibaba.version}</version> <exclusions> <exclusion> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> </exclusion> </exclusions> </dependency> <!-- other dependencies --> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>3.4.1</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2022.0.0.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ``` 通过上述设置可以有效管理项目中的依赖关系,从而实现 Spring Boot 3.4.1、Spring CloudSpring Cloud Alibaba 的无缝协作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值