MySQL表操作—存储

编程入门 行业动态 更新时间:2024-10-26 08:26:09

MySQL表<a href=https://www.elefans.com/category/jswz/34/1770947.html style=操作—存储"/>

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

更多推荐

MySQL表操作—存储

本文发布于:2023-12-06 05:47:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1666633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!