ROW_COUNT函数解决了人大金仓数据库KingbaseES 执行语句影响的数据行数计数问题

ROW_COUNT函数解决了金仓数据库KingbaseES执行语句影响的数据行数计数问题

关键字

ROW_COUNT、影响行数、mysql、计数

问题描述

应用开发端直接通过调用函数方式获取某条语句影响的数据行数。

问题分析

缺少简单易用的函数接口。

解决方案

使用ROW_COUNT函数获取上一条语句影响的数据行数。注:该函数仅在KES MySQL模式支持。

sql 复制代码
drop table if exists test_t1,test_t2;

create table test_t1(id int,name varchar(20));

insert into test_t1 values(1,'t1'),(2,'t2'),(3,'t3'),(4,'t4'),(5,'t5'),(6,'t6');

create table test_t2(id int primary key,name varchar(20));

insert into test_t2 select * from test_t1;

--插入数据,键值不冲突,返回影响行数1

replace into test_t2 values(7, 't7'); select row_count();

--插入数据,键值冲突,返回影响行数2(先删除原数据,再插入新数据)

replace into test_t2 values(7, 't7'); select row_count();

--查询数据,返回影响行数为-1(查询语句不影响数据,默认返回-1)

select * from test_t1 where id=7;select row_count();

--删除语句,返回影响行数7

delete from test_t2;select row_count();

参考资料

《KingbaseES SQL语言参考手册》

相关推荐
TechTrek15 分钟前
Spring Boot 4.0正式发布了
java·spring boot·后端·spring boot 4.0
飞梦工作室35 分钟前
企业级 Spring Boot 邮件系统开发指南:从基础到高可用架构设计
java·spring boot·后端
haiyu柠檬37 分钟前
在Spring Boot中实现Azure的SSO+VUE3前端配置
java·spring boot·后端
q***72191 小时前
springBoot 和springCloud 版本对应关系
spring boot·后端·spring cloud
百***81271 小时前
【SpringBoot】SpringBoot中分页插件(PageHelper)的使用
java·spring boot·后端
百***86461 小时前
SpringBoot中自定义Starter
java·spring boot·后端
q***07141 小时前
VScode 开发 Springboot 程序
java·spring boot·后端
q***46521 小时前
Spring中使用Async进行异步功能开发实战-以大文件上传为例
java·后端·spring
q***9942 小时前
Redis的Spring配置
数据库·redis·spring
S***y3962 小时前
MySQL视频
数据库·mysql