I want to select *, and not have to type out all individual columns, but I also want to include a custom column with a case statement. I tried the following:
select *, (case when PRI_VAL = 1 then 'High' when PRI_VAL = 2 then 'Med' when PRI_VAL = 3 then 'Low' end) as PRIORITY from MYTABLE;
But it is complaining that
ORA-00923: FROM keyword not found where expected
The plus sign is Oracle syntax for an outer join. There isn't a minus operator for joins. An outer join means return all rows from one table. Also return the rows from the outer joined where there's a match on the join key. If there's no matching row, return null.
Introduction to Oracle CASE expression You can use a CASE expression in any statement or clause that accepts a valid expression. For example, you can use the CASE expression in statements such as SELECT , UPDATE , or DELETE , and in clauses like SELECT , WHERE , HAVING , and ORDDER BY .
insert into table table_name ( value1, value 2,value 3) select (value 1,value2 , case value3 when value1 = 'somevalue' &&* value2 = 'somevalue' then 'x' else 'y' End from table_name.
A CASE statement cannot return more than one value, it is a function working on one value.
Add an alias for mytable like this:
select t.*, (case when PRI_VAL = 1 then 'High' when PRI_VAL = 2 then 'Med' when PRI_VAL = 3 then 'Low' end) as PRIORITY from MYTABLE t;
This is not dependent on any specific Oracle version, not sure about other databases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With