0

It is not very clear to me if I can use a select-from statement as a condition for an IF STATEMENT For example

IF(SELECT quantity
  FROM warehouse)>(SELECT quantity
                  FROM warehouse2) then ecc

Can I do something like that?

Aur
  • 43
  • 4

2 Answers2

4

I think you should using the variable for them.

DECLARE 
    V_quantity_WH1 NUMBER;
    V_quantity_WH2 NUMBER;
BEGIN
    --Sum qty 1 --------------
    SELECT SUM(quantity) INTO V_quantity_WH1 FROM warehouse;

    --Sum qty 2 --------------
    SELECT SUM(quantity) INTO V_quantity_WH2 FROM warehouse2;

    --Compare qty1 and qty2 ----------------
    IF (V_quantity_WH1 > V_quantity_WH2) THEN
        ......;
    END IF; 
END;
Hung Le
  • 141
  • 9
  • Agree. This is clearer for people to parse. Inlining a select statement makes little or no sense to me. I can't see how it would benefit anyone. – Dom G May 18 '20 at 16:52
0

It is impossible. The select ... expression is a pointer, IF expects a boolean expression: IF *boolean_expression* THEN *statement* END IF;

vnskv
  • 61
  • 5