昔、MySQLで初めて作った、ユーザー定義関数です。
言語を付け足していけば、拡張できます。RETURNS の CHARSET は必要に応じて変更してください。
CREATE DEFINER=`root`@`localhost` FUNCTION `fc_dofwtxt`(
`idx` tinyint,
`langcd` varchar(4)
)
RETURNS varchar(20) CHARSET sjis
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT '言語指定曜日文字列スカラー関数'
begin
declare res varchar(12);
if (langcd = 'jp') THEN
select
case (idx)
when 2 then '月'
when 3 then '火'
when 4 then '水'
when 5 then '木'
when 6 then '金'
when 7 then '土'
when 1 then '日'
end as restxt into res;
END IF;
if (langcd = 'jpp') THEN
select
case (idx)
when 2 then '(月)'
when 3 then '(火)'
when 4 then '(水)'
when 5 then '(木)'
when 6 then '(金)'
when 7 then '(土)'
when 1 then '(日)'
end as restxt into res;
END IF;
if (langcd = 'ens') THEN
select
case (idx)
when 2 then 'Mon'
when 3 then 'Tue'
when 4 then 'Wed'
when 5 then 'Thu'
when 6 then 'Fri'
when 7 then 'Sat'
when 1 then 'Sun'
end as restxt into res;
END IF;
if (langcd = 'cnp') THEN
select
case (idx)
when 2 then '(星期一)'
when 3 then '(星期二)'
when 4 then '(星期三)'
when 5 then '(星期四)'
when 6 then '(星期五)'
when 7 then '(星期六)'
when 1 then '(星期天)'
end as restxt into res;
END IF;
return res;
end