我将如何使用 IF 和 ELSE 语句来定义基于“深度整数”运行多少存储过程?(例如,如果用户使用 1 作为深度周长,则只处理第一部分)
--#SET TERMINATOR /
CREATE PROCEDURE STOREP2(IN str_in VARCHAR(1), IN depth INTEGER )
LANGUAGE SQL MODIFIES SQL DATA
DYNAMIC RESULT SETS 1
CRSUBJ: BEGIN
DECLARE C1 CURSOR WITH RETURN FOR
SELECT T1.COLUMN1, T1.COLUMN2 FROM TABLE1 AS T1 WHERE T1.COLUMN1=str_in
UNION
SELECT T2.COLUMN1, T2.COLUMN2 FROM TABLE1 AS T1, TABLE1 AS T2 WHERE T1.COLUMN1=str_in AND T2.COLUMN1=T1.COLUMN2
UNION
SELECT T3.COLUMN1, T3.COLUMN2 FROM TABLE1 AS T1, TABLE1 AS T2, TABLE1 AS T3 WHERE T1.COLUMN1=str_in AND T2.COLUMN1=T1.COLUMN2 AND T3.COLUMN1=T2.COLUMN2
UNION
SELECT T4.COLUMN1, T4.COLUMN2 FROM TABLE1 AS T1, TABLE1 AS T2, TABLE1 AS T3, TABLE1 AS T4 WHERE T1.COLUMN1=str_in AND T2.COLUMN1=T1.COLUMN2 AND T3.COLUMN1=T2.COLUMN2 AND T4.COLUMN1=T3.COLUMN2;
OPEN C1;
RETURN;
END CRSUBJ/
谢谢 :)