MySQL表操作—存储

建表:

mysql> create table sch(

-> id int primary key,

-> name varchar(50) not null,

-> glass varchar(50) not null

-> );

Query OK, 0 rows affected (0.01 sec)

插入数据:

mysql> insert into sch (id,name,glass) values (1,'zhizhuo','glass 1');

Query OK, 1 row affected (0.00 sec)

mysql> insert into sch (id,name,glass) values (2,'haodong','glass 2');

Query OK, 1 row affected (0.00 sec)

1、创建一个可以统计表格内记录条数的存储函数 ,函数名为count_sch()

mysql> set global log_bin_trust_function_creators = 1; #关闭binlog日志

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> \d @

mysql> create function count_sch()

-> returns int

-> begin

-> declare c int default 0;

-> select count(*) into c from sch;

-> return c;

-> end@

Query OK, 0 rows affected (0.02 sec)

mysql> select count_sch()@

2、创建一个存储过程avg_sai,有3个参数,分别是deptno,job,接收平均工资,功能查询emp表dept为30,job为销售员的平均工资

mysql> \d //

mysql> create procedure avg_sal(in deptno int, in job varchar(50),out s double)

-> begin

-> select avg(salary) into s from employees where department_id=deptno and job_id=job;

-> select s;

-> end //

Query OK, 0 rows affected (0.00 sec)

mysql> call avg_sal (90,'AD_VP',@s)//

相关推荐
老纪的技术唠嗑局6 分钟前
分库分表MyCat 架构迁移 OceanBase | 百丽核心财务系统迁移经验总结与问题汇总
数据库·架构·oceanbase
IT教程资源C1 小时前
(N_158)基于微信小程序学生社团管理系统
mysql·vue3·前后端分离·社团小程序·springboot社团小程序
xrkhy6 小时前
微服务之ShardingSphere
数据库·微服务·oracle
JIngJaneIL6 小时前
停车场管理|停车预约管理|基于Springboot的停车场管理系统设计与实现(源码+数据库+文档)
java·数据库·spring boot·后端·论文·毕设·停车场管理系统
煎蛋学姐6 小时前
SSM儿童福利院管理系统ys9w2d07(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·ssm 框架·儿童福利院管理系统
sg_knight6 小时前
MySQL 空间索引(SPATIAL)详解:地理位置数据的高效查询利器
数据库·mysql·database·索引·关系型数据库·空间索引·spatial
梦子yumeko8 小时前
第五章Langchain4j之基于内存和redis实现聊天持久化
数据库·redis·缓存
IndulgeCui9 小时前
【金仓数据库产品体验官】KSQL Developer Linux版安装使用体验
linux·运维·数据库
苹果醋39 小时前
element-ui源码阅读-样式
java·运维·spring boot·mysql·nginx
一马平川的大草原9 小时前
基于n8n实现数据库多表数据同步
数据库·数据同步·dify·n8n