I am trying to figure out an assignment. The text is:
Write a stored function which will return the course id that the course name contain a given parameter pattern string. You must use LIKE for the pattern match. Please refer to Courses table.
If a character such as Z is entered, and it is not in the courses name should display: No record found
If the input is blank: Please input a valid string
If the input is NULL: Please input a valid string
And if the input is J: CPS1231, CPS2231
Courses table
cid | name
--------+------------------
CPS1231 | Java1
CPS2231 | Java2
CPS2232 | Data Structure
Here's what I have so far:
CREATE FUNCTION `Work` ()
RETURNS INTEGER
BEGIN
declare msg varchar(20) default '';
if ((name is null) or (name='')) then
select "Please input a valid string" as message;
else
select group_concat(name) into msg from dreamhome.Courses where name like '%,_name%';
elseif ((msg='') or (msg is null)) then
select group_concat(" is not in the system") as message;
else
select distinct cid from dreamhome.Courses;
end if;
end if;
I'm not sure where to go from here.