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

相关推荐
haixingtianxinghai20 分钟前
Redis的定期删除和惰性删除
数据库·redis·缓存
资深web全栈开发21 分钟前
PostgreSQL Schema 最佳实践:架构师的命名与组织艺术
数据库·postgresql
麦聪聊数据1 小时前
利用实时数据管道与 SQL2API 重构企业自动化审计架构
数据库·sql·低代码
麦聪聊数据1 小时前
重构开放生态:利用 QuickAPI 跨越遗留系统与敏捷交付的工程实践
数据库·sql·低代码·restful
百结2146 小时前
Mysql数据库操作
数据库·mysql·oracle
keep one's resolveY6 小时前
时区问题解决
数据库
Leinwin6 小时前
OpenClaw 多 Agent 协作框架的并发限制与企业化规避方案痛点直击
java·运维·数据库
qq_417695057 小时前
机器学习与人工智能
jvm·数据库·python
漫随流水7 小时前
旅游推荐系统(view.py)
前端·数据库·python·旅游
ego.iblacat7 小时前
MySQL 服务基础
数据库·mysql