1

I am looking for a small and simple query that works on Oracle and SQL Server.

It is used as a test query to check the connection.

For SQL Server we used SELECT 1, but in Oracle it would have to be SELECT 1 FROM DUAL.

What we plan to use now is SELECT COUNT(*) FROM (sometable) but any ideas for an even simpler query are appreciated.

4
  • Two questions: where are you running this query from, and is the schema the same in Oracle and SQL Server? Commented Aug 22, 2014 at 8:34
  • An application server is running the query. I can not guarantee that the schema is (or will allways be) exactly the same but i have some tables with the same schema on both. I do not care for the result of the query, it just may not give an error. Commented Aug 22, 2014 at 8:38
  • 1
    Given the clarification on Oracle's behaviour my answer clearly doesn't work for you but I'll leave it up as it will work for other RDBMSs. Is there no way you can check your connection in the code that will send this query? At the least check which RDBMS it's trying to connect to and change the query it sends accordingly? Commented Aug 22, 2014 at 8:50
  • The application server doesnt offer this feature. I would have to change the test query every time i change the source from MSSQL (later use) to Oracle (test environment). I know that they should be equal, but this is not possible in my case. As i said, we have a test query - the question is just if there is an even more simple one. Commented Aug 22, 2014 at 9:13

4 Answers 4

2

One simple option is to add a view to SQL Server called DUAL that just returns 1, that way you can have a simple query that works the same in both environments:

SELECT 1 FROM DUAL
Sign up to request clarification or add additional context in comments.

Comments

0

If returning data from relations isn't important then:

SELECT 'Hello world';

will rely on a connection as much as anything else. Your RDBMS should return 'Hello world'. Tested on SQL server and PostgreSQL (don't have access to Oracle).

2 Comments

Oracle doesn't support a SELECT without a FROM. It would have to be FROM DUAL for Oracle
Thanks Jaloopa, I've added a comment to the question to reflect this.
0

As long as you write query in ANSI standard. It can be executed in all the RDMS.

May be you can try this query....

select ColumnName from TableName where 1=2

BTW, the DBProvider shld have come property to state of DB connectivity... which DB provider does ur application uses?

1 Comment

Whilst this does require both schemas to share at least one table name, I think this is what @AsconX implied they were already doing.
0

Does it need to be a query? You could create a simple stored procedure with the same name in both databases, that just returns a constant, and execute it from the application server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.