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 小时前
什么是OLTP ,MySQL是如何支持OLTP的?
数据库·后端·mysql
pen-ai6 小时前
【数据工程】14. Stream Data Processing
数据库·oracle
倔强的石头1066 小时前
【金仓数据库】ksql 指南(三) —— 创建与管理表空间和模式
数据库·金仓数据库
金仓拾光集6 小时前
__金仓数据库平替MongoDB:银行存款系统国产化实践__
数据库·mongodb
流烟默6 小时前
MongoDB入门指南基础篇
数据库·mongodb
金仓拾光集6 小时前
_金仓数据库平替MongoDB实战:制造业生产进度管理的国产化升级之路
数据库·mongodb
熊文豪7 小时前
时序数据库选型指南:从大数据视角看高效存储与分析
大数据·数据库·时序数据库
Lisonseekpan7 小时前
为什么要避免使用 `SELECT *`?
java·数据库·后端·sql·mysql·oracle
Wilson Chen7 小时前
深入理解 MySQL 事务与锁机制:从 ACID 到 Next-Key Lock 的实证之旅
java·数据库·mysql
Fency咖啡8 小时前
Spring进阶 - Spring事务理论+实战,一文吃透事务
java·数据库·spring