我有一个下面的函数,该函数从存储过程中调用,以拆分逗号分隔的字符串并作为表返回。这是DB2。 我试图在MYSQL中实现相同的功能。但是MYSQL无法返回表。我需要编写一个存储过程以返回表。调用SP。下面是代码。请帮助我转换为一个将表返回到调用方SP的SP。
呼叫SP:
DELETE
FROM RAO_FINANCIAL_DETAILS_TRACTN
WHERE FINANCIAL_DETAIL_ID IN
(
SELECT
FINANCIAL_DETAIL_ID
FROM RAO_FINANCIAL_DETAILS
WHERE CUSTOMER_ID IN
(
SELECT
STRING_VALUE
FROM TABLE(FN_RAO_SPLIT(@inputParam,',')) AS TEST
)
)
;
称为函数:
`
CREATE FUNCTION FN_RAO_SPLIT
(
STRINGTOSPLIT VARCHAR(2000), DELIMITER VARCHAR(10)
)
RETURNS TABLE
(
ROW_NUMBER INTEGER, STRING_VALUE VARCHAR(250), STRING_POSITION INTEGER
)
NO EXTERNAL ACTION
BEGIN ATOMIC
RETURN WITH RECORDS
(
ROW_NUMBER, STRING_VALUE, STRING_POSITION
)
AS
(
VALUES
(
1,
VARCHAR(SUBSTR(STRINGTOSPLIT, 1,DECODE(INSTR(STRINGTOSPLIT, DELIMITER, 1), 0, LENGTH(STRINGTOSPLIT),INSTR(STRINGTOSPLIT, DELIMITER, 1) - 1)),255)
,
INSTR(STRINGTOSPLIT, DELIMITER, 1) + LENGTH(DELIMITER)
)
UNION
ALL
SELECT
ROW_NUMBER + 1,
VARCHAR(SUBSTR(STRINGTOSPLIT, STRING_POSITION,
DECODE(INSTR(STRINGTOSPLIT, DELIMITER, STRING_POSITION),
0,
LENGTH(STRINGTOSPLIT) - STRING_POSITION + 1,
INSTR(STRINGTOSPLIT, DELIMITER, STRING_POSITION) - STRING_POSITION)),
255),
INSTR(STRINGTOSPLIT, DELIMITER, STRING_POSITION) + LENGTH(DELIMITER)
FROM RECORDS
WHERE ROW_NUMBER < 30000
AND STRING_POSITION > LENGTH(DELIMITER)
)
SELECT
ROW_NUMBER, STRING_VALUE, STRING_POSITION
FROM RECORDS
;--
END
;`