Search code examples
sqloracle-databasenvl

how to set NVL on SQL with TO_CHAR(MAX)


I trying to set a nvl() with the value OPEN on ->

        select to_char(max(CLOSE_DATE),'dd.mm.yyyy hh24:mi:ss') 

If it is closed is getting the date ('dd.mm.yyyy hh24:mi:ss') otherwise it should display OPEN

Any ideas, where I can put correctly the NVL()?

Solution:

        select nvl (to_char(max(CLOSE_DATE),'dd.mm.yyyy hh24:mi:ss'), 'OPEN')


Solution

  • This?

    select decode(close_date, null, 'OPEN', 
                                    to_char(close_date, 'dd.mm.yyyy hh24:mi:ss'
                 ) result
    from your_table
    

    Or

    select nvl(to_char(close_date, 'dd.mm.yyyy hh24:mi:ss'), 'OPEN') result
    from your_table