创建存储过程

查询语句

DDL

CREATE TABLE student (
    id INT PRIMARY KEY AUTO_INCREMENT,
    createDate DATE NOT NULL,
    phone VARCHAR(20) NOT NULL,
    age INT NOT NULL,
    sex ENUM('男', '女') NOT NULL,
    introduce TEXT NOT NULL,
    userName VARCHAR(50) NOT NULL
);

DML

INSERT INTO student (createDate, phone, age, sex, introduce, userName) 
VALUES ('2023-10-23', '13800138000', 20, '男', '青春如风,潇洒自如,才情出众,犹如明月照大江。', '张三');
INSERT INTO student (createDate, phone, age, sex, introduce, userName) 
VALUES ('2023-10-22', '13900139000', 22, '女', '才华横溢,智慧如海,温文尔雅,宛如春风拂面。', '李四');
INSERT INTO student (createDate, phone, age, sex, introduce, userName) 
VALUES ('2023-10-21', '13700137000', 21, '男', '风华正茂,英姿飒爽,志向远大,犹如苍鹰击长空。', '王五');
INSERT INTO student (createDate, phone, age, sex, introduce, userName) 
VALUES ('2023-10-20', '13600136000', 23, '女', '气质如兰,清新脱俗,才情横溢,好似瑶台降玉女。', '赵六');
INSERT INTO student (createDate, phone, age, sex, introduce, userName) 
VALUES ('2023-10-19', '13500135000', 24, '男', '风华绝代,英俊潇洒,才华横溢,犹如龙行天下,气势磅礴。', '孙七');
INSERT INTO student (createDate, phone, age, sex, introduce, userName) 
VALUES ('2023-10-18', '13400134000', 25, '男', '黄猿豪杰,风华绝代,金戈铁马,气吞万里如虎。智慧如海,深不可测,才情横溢,犹如璀璨星辰耀乾坤。', '黄猿');
INSERT INTO student (createDate, phone, age, sex, introduce, userName) 
VALUES ('2023-10-17', '13300133000', 22, '女', '才貌双全,温婉如玉,气质非凡,犹如仙女下凡尘。', '周八');

存储过程

编写一个存储过程get_student_introduce,该存储过程会查询并返回名为【黄猿】的学生的简介信息
DELIMITER //

CREATE PROCEDURE get_student_introduce()
BEGIN
    -- 声明变量来存储查询结果
    DECLARE student_introduce TEXT;

    -- 查询userName为'黄猿'的学生的introduce字段,并将结果赋值给变量
    SELECT introduce INTO student_introduce FROM student WHERE userName = '黄猿';

    -- 输出结果
    SELECT student_introduce AS '黄猿的简介';
END //

DELIMITER ;
之后刷新函数页面 函数页面出现语句 
调用存储过程加在存储过程语句最后面然后运行
CALL get_student_introduce();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值