查询语句
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();