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

相关推荐
balmtv3 分钟前
Linux(CentOS)安装 MySQL
linux·mysql·centos
huangliang070337 分钟前
postgresql 日志中文乱码
数据库·postgresql
oioihoii2 小时前
从“功能实现”到“深度优化”:金仓数据库连接条件下推技术的演进之路
数据库·oracle
二狗mao2 小时前
整理了索引几道面试热题的简答
mysql
胡图图不糊涂^_^2 小时前
MySQL学习笔记——增删改查操作
数据库·笔记·增删改查
6+h2 小时前
【MySQL】事务隔离与MVCC详解
数据库·mysql
luom01022 小时前
【MySQL 的数据目录】
数据库·mysql·adb
搜佛说2 小时前
sfsDb 所代表的“融合型”数据库将为未来的一个重要方向
数据库·物联网·边缘计算·时序数据库·iot
相信神话20212 小时前
第零章:新手的第一课:正确认知游戏开发
大数据·数据库·算法·2d游戏编程·godot4·2d游戏开发
深蓝轨迹3 小时前
乐观锁 vs 悲观锁 含面试模板
java·spring boot·笔记·后端·学习·mysql·面试