frododot
frododot

Reputation: 127

Is there a way in sqlplus to display a conditional column heading?

Would like to be able to display a conditional column heading, based on the select results, in sql*plus. So in example below, would like to display A_DATE header if value is A, or the begin/end_date column heading otherwise:

SELECT
CASE thingy
    WHEN 'A' THEN TO_CHAR(a_date, 'DD-MON-YYYY') "A_DATE"
    ELSE TO_CHAR(begin_date, 'DD-MON-YYYY')  || ' '  
        || TO_CHAR(end_date, 'DD-MON-YYYY')  "BEGIN_DATE  END_DATE"
END,

Upvotes: 0

Views: 258

Answers (1)

Dan Bracuk
Dan Bracuk

Reputation: 20804

I don't think so. If the query returned more than one row you run the risk of ambiguity. You could return two columns though. Something like this:

select case when my condition is met then myfield else null end "true column"
, case when my my condition is not met then myfield else null end "false column"

Upvotes: 1

Related Questions