Error using Case and Select in PL-SQL

Asked

Viewed 111 times

1

I have this code:

DECLARE
BEGIN

  SELECT p.categoria(
    CASE 
      WHEN p.categoria = 'A' THEN DBMS_OUTPUT.PUT_LINE('A')
      ELSE 2000 END
  )    
  FROM PRODUTO_TESTE2 p;

END;

Error message:

Bug report - ORA-06550: line 6, column 47: PL/SQL: ORA-00904: : invalid Identifier ORA-06550: line 4, column 3: PL/SQL: SQL Statement Ignored 06550. 00000 - "line %s, column %s: n%s" *Cause: Usually a PL/SQL Compilation error. *Action:

Structure of the Products Table

inserir a descrição da imagem aqui

1 answer

6


Try to run your select this way:

DECLARE
BEGIN

  SELECT p.categoria,
    CASE WHEN p.categoria = 'A' THEN DBMS_OUTPUT.PUT_LINE('A')
    ELSE 2000 END   
  FROM PRODUTO_TESTE2 p;

END;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.