我在表'事件'中使用了一个列'标题'。此列包含一些信息。在此信息中,三个字符表示区域。这三个字符通常在('on',':')之后找到。我想执行一个函数(mysql),该函数允许:1)如果从'Title'列中取出的三个字符(位于'on'之后)是(kef或bej或jen),那么结果将存储在列'test'在同一个表中。 2)如果第一个没有实现,则取出位于':'之后的三个字符,并存储在同一个表中的'test1'列中。 有我使用的代码:
WITH CTE AS (
SELECT c.ChallanNo, c.REFERENCENO , c.STEPNO FROM CHALLAN c
INNER JOIN CURRENTREPORT cr
on c.REFERENCENO = cr.REFERENCENO
WHERE RECEIVEDDATE IN (SELECT MIN(RECEIVEDDATE)
FROM CHALLAN cn
GROUP BY (STEPNO))
)
UPDATE CURRENTREPORT SET WORK1 = ch.STEPNO FROM CURRENTREPORT c INNER JOIN cte ch
on c.referenceNo = ch.referenceNo
并且我使用了查询:
delimiter |
CREATE FUNCTION METTER5 (s VARCHAR(2000)) RETURNS VARCHAR(10000)
DETERMINISTIC
BEGIN
DECLARE open INT;
DECLARE close INT;
DECLARE someLimit INT;
DECLARE str VARCHAR(2000);
DECLARE str1 VARCHAR(2000);
DECLARE str2 VARCHAR(2000);
DECLARE str3 VARCHAR(2000);
DECLARE toFind VARCHAR(2000);
DECLARE co VARCHAR(2000);
SET co='';
SET open = 1;
SET close = 1;
SET toFind = s ;
SET someLimit =100;
SET str='';
SET str1='';
SET str2='';
/* SET tofind=concat(tofind,'sur','');*/
SET str =substring(trim(substring_index(s,'sur',-1)),1,3);
SET str1 =substring(trim(substring_index(s,'du',-1)),1,3);
SET str2 =substring(trim(substring_index(s,':',-1)),1,3);
IF (str in ('ZAG','TUN','TOZ','TAT','SOS','SIL','SFX','SBO','RNC','BAR','BEJ','BIZ','BSC','GAB','GAF','JEN','KAI','KAS','KEB','KEF','MAH','MED','MON','NAB')) =1 THEN set co = str ;
ELSE IF ((str not in ('ZAG','TUN','TOZ','TAT','SOS','SIL','SFX','SBO','RNC','BAR','BEJ','BIZ','BSC','GAB','GAF','JEN','KAI','KAS','KEB','KEF','MAH','MED','MON','NAB')) and (str1 in ('ZAG','TUN','TOZ','TAT','SOS','SIL','SFX','SBO','RNC','BAR','BEJ','BIZ','BSC','GAB','GAF','JEN','KAI','KAS','KEB','KEF','MAH','MED','MON','NAB')))=1 THEN set co = str1 ;
ELSE IF ((str1 not in ('ZAG','TUN','TOZ','TAT','SOS','SIL','SFX','SBO','RNC','BAR','BEJ','BIZ','BSC','GAB','GAF','JEN','KAI','KAS','KEB','KEF','MAH','MED','MON','NAB'))and (str2 in ('ZAG','TUN','TOZ','TAT','SOS','SIL','SFX','SBO','RNC','BAR','BEJ','BIZ','BSC','GAB','GAF','JEN','KAI','KAS','KEB','KEF','MAH','MED','MON','NAB')))=1 THEN SET co = str2 ;
ELSE set co = '1' ;
END IF;
END IF;
END IF;
return co;
END |
delimiter;
但是在运行之后,出现了问题:“字段列表”中的未知列'描述'
感谢。