2014-10-16 43 views
0

我有一個過程在需要爲select語句1設置d_x的地方,d_y對於select語句2,d_z對於select語句3.我怎麼能修改以下程序以實現...如何爲存儲過程中的相同NOT FOUND SQL EXCEPTION設置變量值

CREATE PROCEDURE A() 
    BEGIN 
     DECLARE d_a INT; 
     DECLARE d_b INT; 
     DECLARE d_c INT; 
     --- 
     -- 
     - 
     DECLARE CONTINUE HANDLER FOR NOT FOUND 
     BEGIN 
      SET d_x = 1; 
      SET d_y = 2; 
      SET d_z = 3; 
     END; 

     SELECT aa INTO d_x FROM TEST1; 
     SELECT bb INTO d_y FROM TEST2; 
     SELECT cc INTO d_z FROM TEST3; 
    END 
+0

我腦海中的一個解決方案是創建子程序來實現這一點。是否有可能通過單一程序來實現。 – 2014-10-16 15:40:32

回答

0

我發現我的問題的一個解決方案。和可能的答案。但是如果還有其他方法,請定義。

CREATE PROCEDURE A() 
    BEGIN 
     DECLARE d_a INT; 
     DECLARE d_b INT; 
     DECLARE d_c INT; 
     --- 
     -- 
     - 

     BEGIN 
     DECLARE CONTINUE HANDLER FOR NOT FOUND 
     BEGIN 
      SET d_x = 1; 
     END; 
     SELECT aa INTO d_x FROM TEST1; 
     END; 
     BEGIN 
     DECLARE CONTINUE HANDLER FOR NOT FOUND 
     BEGIN 
      SET d_y = 2; 
     END; 
     SELECT bb INTO d_y FROM TEST2; 
     END; 
      BEGIN 
     DECLARE CONTINUE HANDLER FOR NOT FOUND 
     BEGIN 
      SET d_y = 2; 
     END; 
     SELECT cc INTO d_z FROM TEST3; 
     END; 
    END 
相關問題