IF および ELSE ステートメントを使用して、「深さ INTEGER」に基づいて実行するストアド プロシージャの量を定義するにはどうすればよいですか? (たとえば、ユーザーが深さの境界に 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/
ありがとう :)