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

相关推荐
E***U94520 小时前
MySQL自然语言处理应用
数据库·mysql
计算机毕业设计小途20 小时前
计算机毕业设计推荐:基于SpringBoot的水产养殖管理系统【Java+spring boot+MySQL、Java项目、Java毕设、Java项目定制定做】
java·spring boot·mysql
洛_尘21 小时前
MySQL 2:库的操作
数据库·mysql
码农101号21 小时前
Linux - 达梦数据库的安装
数据库
l1t1 天前
使用DuckDB SQL求解Advent of Code 2024第9题 磁盘碎片整理
数据库·sql·算法·duckdb·advent of code
光之梦1 天前
《openGauss全密态与防篡改账本数据库:云上数据安全与可信的新范式》
mysql
Z***u6591 天前
MySQL物联网开发
数据库·mysql
Wang's Blog1 天前
MongoDB小课堂: 容器化部署与操作综合指南
数据库·mongodb
IT小哥哥呀1 天前
从零到NoSQL:一个动手的MongoDB教程(无需安装!)
数据库·mongodb·nosql·教程·初学者
J***79391 天前
MySQL语音识别案例
数据库·mysql·语音识别