Pergunta

Trying to get something like the following pseudo code to work with PL/SQL Developer but not having any luck. Imagine I have a table with columns a-e.

Declare
    name      varchar(100);
    address   varchar(100);
Begin

    If column a = 'Y'
        name = column b;
        address = column c;
    else
        name = column d;
        name = column e;
End

Any help would be greatly appreciated!

Foi útil?

Solução

I don't see the need for PL/SQL, plain SQL will do just as well

select case
         when column_a = 'Y' then colum_b 
         else colum_d 
       end as name,
       case
          when column_a = 'Y then colum_d
          else column_e
       end as address
from the_table;

Encapsulating that in a view is probably a good idea

Outras dicas

Try

Select 
case when columnA = 'Y' then columnB else columnD end into name,
case when columnA = 'Y' then columnD else columnE end into address
From Table
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top