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)//

相关推荐
知识分享小能手1 小时前
Redis入门学习教程,从入门到精通,Redis 概述:知识点详解(1)
数据库·redis·学习
**蓝桉**3 小时前
mysql二进制部署
mysql
xixihaha13243 小时前
将Python Web应用部署到服务器(Docker + Nginx)
jvm·数据库·python
夕除3 小时前
Mysql--07
数据库·mysql
数据最前线3 小时前
5个瞬间,盘点国产数据库的2025年
数据库
jiankeljx3 小时前
Redis-配置文件
数据库·redis·oracle
xixihaha13243 小时前
Python游戏中的碰撞检测实现
jvm·数据库·python
Schengshuo3 小时前
SQL 中 COUNT 的用法详解
数据库·sql
顶点多余3 小时前
Mysql--后端与前端关系
数据库·mysql
mygljx3 小时前
【MySQL 的 ONLY_FULL_GROUP_BY 模式】
android·数据库·mysql