Oracle database - check Database status

I plan to use query "SELECT STATUS from V$INSTANCE" to get database status. Expected results are "STARTED", "MOUNTED" and "OPEN".
The Monitoring tool I use expects a single digit status.
Can anyone suggest a method of converting the returned STATUS into a single digit.

Thanks in advance.

Des KellySystems EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve WalesSenior Database AdministratorCommented:
Something like:

select decode(status, "STARTED", 0, "MOUNTED", 1, "OPEN", 2, 3) as dbstatus from V$INSTANCE;

Change the values as you see fit but this would set:

Started: 0
Mounted: 1
Open: 2
Unknown / Unexpected value: 3

I'd probably want to have OPEN as 0, all things considered, but I presented them in the order you did :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gerwin Jansen, EE MVETopic Advisor Commented:
Alternative using CASE:

  (CASE status
    ELSE -1
  END ) dbstatus
FROM v$instance;

I would suggest to take a negative (like -1) number for other / error statuses.
Des KellySystems EngineerAuthor Commented:
Hi Steve - perfect - exactly what I need.

Thanks Gerwin your contribution woulsd also work.


Gerwin Jansen, EE MVETopic Advisor Commented:
@itfocus - The solution you've chosen now does not work because of the double quotes, where my solution is working.

So you've either adapted the first solution or used mine? ;)
Steve WalesSenior Database AdministratorCommented:
The joy of typing a quick answer, I hadn't even noticed the double quotes, good catch :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.