jeudi 3 mars 2016

IF and ELSIF in the PL/SQL

I have this code that I write, but the problem is that I cannot use the ELSEIF statement in there and I don't know why, and Oracle Developer doesn't let me to execute it.

Is anyone able to help me with this please ?

DECLARE
  CURSOR p_cursor IS
    SELECT PRODUCT_NAME, PRICE
      FROM PRODUCT
  ORDER BY PRICE ;
  p_row p_cursor%ROWTYPE ;
  p_name VARCHAR2(30) ;
  p_price NUMBER ;
BEGIN
  dbms_output.put_line(RPAD('Product Name', 25, ' ') || 'Price Status');
  dbms_output.put_line(RPAD('-', 24, '-') || RPAD(' -', 14, '-'));
  FOR p_row IN p_cursor
    LOOP
    p_name := p_row.PRODUCT_NAME;
    p_price := p_row.PRICE ;

    IF p_price < 5  THEN
      dbms_output.put_line(RPAD(p_name, 25, ' ') || ' Low');
    END IF;
    IF p_price > 5 AND p_price < 20 THEN
      dbms_output.put_line(RPAD(p_name, 25, ' ') || ' Medium');
    END IF;
    IF p_price > 20 THEN
      dbms_output.put_line(RPAD(p_name, 25, ' ') || ' High');
    END IF;

  END LOOP;
END;

I want to have something like this

IF p_price < 5  THEN
  dbms_output.put_line(RPAD(p_name, 25, ' ') || ' Low');
ELSEIF p_price > 5 AND p_price < 20 THEN
  dbms_output.put_line(RPAD(p_name, 25, ' ') || ' Medium');
ELSE
  dbms_output.put_line(RPAD(p_name, 25, ' ') || ' High');
END IF;

Aucun commentaire:

Enregistrer un commentaire