一、DDL与DML
CREATE TABLE student (id INT PRIMARY KEY AUTO_INCREMENT,createDate DATETIME NOT NULL,userName VARCHAR(255) NOT NULL,phone VARCHAR(20) NOT NULL,age INT NOT NULL,sex ENUM('男', '女') NOT NULL,introduce TEXT
);
INSERT INTO student (createDate, userName, phone, age, sex, introduce)
VALUES (NOW(), '邹靖钊', '13800138000', 20, '男', '邹生靖钊,风华绝代,仪表堂堂。才情横溢,品行高洁,实乃人中龙凤也。');
INSERT INTO student (createDate, userName, phone, age, sex, introduce)
VALUES (NOW(), '张三', '13900139000', 22, '男', '张三公子,英俊潇洒,气宇轩昂。才情出众,志向远大,必成大器。');INSERT INTO student (createDate, userName, phone, age, sex, introduce)
VALUES (NOW(), '李四', '13700137000', 19, '女', '李四姑娘,婉约秀丽,温文尔雅。才思敏捷,慧心巧思,令人赞叹不已。');INSERT INTO student (createDate, userName, phone, age, sex, introduce)
VALUES (NOW(), '王五', '13600136000', 21, '男', '王五壮士,英勇威武,气概不凡。学富五车,胸怀壮志,必能成就一番伟业。');INSERT INTO student (createDate, userName, phone, age, sex, introduce)
VALUES (NOW(), '赵六', '13500135000', 23, '女', '赵六娘子,端庄娴雅,仪态万方。才情出众,品德高尚,堪称女中豪杰。');INSERT INTO student (createDate, userName, phone, age, sex, introduce)
VALUES (NOW(), '孙七', '13400134000', 20, '男', '孙七少年,英俊潇洒,风度翩翩。才情横溢,志向高远,未来可期。');
二、创建存储过程
-- 创建存储过程get_student_introduce,用于查询指定userName的学生的introduce信息
DELIMITER //
CREATE PROCEDURE get_student_introduce(IN p_userName VARCHAR(50))
BEGIN-- 声明变量用于存储查询结果DECLARE v_introduce TEXT;-- 查询指定userName的学生的introduce信息SELECT introduce INTO v_introduce FROM student WHERE userName = p_userName;-- 如果找到了匹配的记录,则输出其introduce信息IF v_introduce IS NOT NULL THENSELECT v_introduce;ELSE-- 如果没有找到匹配的记录,则输出提示信息SELECT '没有找到指定学生的简介信息';END IF;
END //
DELIMITER ;CALL get_student_introduce('邹靖钊');