2014-01-23 126 views
0

我有以下查詢哪些在我使用IF語句時不起作用。當我只運行select語句時,它給了我想要的結果。Oracle IF聲明

我應該在這個查詢中改變什麼?

我接受其他建議,如使用'CASE'而不是'IF',如果這會更容易!

DECLARE 
operacija VARCHAR2 := 'z'; 
BEGIN 
IF operacija = 'z' THEN 


(select (MIN_QUANT + (50/100) * MIN_QUANT) as MIN_QUANT, 
     (OPT_QUANT + (50/100) * OPT_QUANT) as OPT_QUANT, 
     (MAX_QUANT + (50/100) * MAX_QUANT) as MAX_QUANT 
from my_table 
where PRODUCT_CODE = '01' and CODE = '123' and FLAG = 'C'); 
END IF; 

END; 

謝謝。

回答

2

您必須選擇值代入變量賦值給變量開始塊之後,像

DECLARE 
    operacija  VARCHAR2(200); 
    v_min_quant NUMBER (20, 2); 
    v_opt_quant NUMBER (20, 2); 
    v_max_quant NUMBER (20, 2); 
BEGIN 
    operacija :='z'; 

    IF operacija = 'z' 
    THEN 
     SELECT (MIN_QUANT + (50/100) * MIN_QUANT), 
      (OPT_QUANT + (50/100) * OPT_QUANT), 
      (MAX_QUANT + (50/100) * MAX_QUANT) 
     INTO v_min_quant, v_opt_quant, v_max_quant 
     FROM my_table 
     WHERE PRODUCT_CODE = '01' AND CODE = '123' AND FLAG = 'C'; 
    END IF; 
END; 
+0

大......它的工作:) – Barlet