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

相关推荐
G***T69118 小时前
PostgreSQL全文搜索教程,中文分词配置
数据库·postgresql·中文分词
星光一影18 小时前
陪诊陪检系统源码,陪诊小程序,陪诊APP,陪诊服务,家政上门系统,居家护理陪护源码
mysql·小程序·uni-app·php
必胜刻18 小时前
MySQL复盘总结
数据库·mysql·oracle
百***794618 小时前
MySQL数据库(SQL分类)
数据库·sql·mysql
weixin_3077791319 小时前
Amazon VPC中Web应用无法连接数据库的安全组配置问题分析与修复
网络·数据库·安全·云计算·aws
q***420519 小时前
开启mysql的binlog日志
数据库·mysql
q***385119 小时前
Spring boot启动原理及相关组件
数据库·spring boot·后端
你不是我我20 小时前
【Java 开发日记】SQL 语句左连接右连接内连接如何使用,区别是什么?
java·javascript·数据库
JELEE.20 小时前
Django中如何重写save()方法
数据库·django
SuperSpinach20 小时前
mysql 报错Authentication method ‘caching_sha2_password‘ is not supported.
数据库·mysql