当我使用IF语句时,我有以下查询无效。当我只运行select语句时,它会给我我想要的结果。
我应该在此查询中更改哪些内容?
我愿意接受其他建议,例如使用' 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;
谢谢。
答案 0 :(得分: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;