![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi there, I'm looking for a simple and quick SQL query with no side effect, that runs on most databases (at least Oracle, MySQL and PostgreSQL). I need that to test my database connection. I tried "select 1" but it does not work under Oracle. Any other idea ? -- Hugo |
#3
| |||
| |||
|
|
There is a dummy one row table that exists in any ORACLE database, so for ORACLE you would use select 1 from dual; What table to use on others DBMS products, i do not know. |

#4
| |||
| |||
|
|
I will be quite surprised if SQL specification does not contain a dummy request (like an identity function, or a "nop" instruction). |
#5
| |||
| |||
|
|
Ed Prochak wrote : There is a dummy one row table that exists in any ORACLE database, so for ORACLE you would use select 1 from dual; What table to use on others DBMS products, i do not know. Thanks for the tips, but I already tried that too, and I guess "dual" table it's not ANSI SQL since it does not work for PostgreSQL (but does for MySQL though). |
|
I will be quite surprised if SQL specification does not contain a dummy request (like an identity function, or a "nop" instruction). |
Maybe I just need to RTFM after all ![]() -- Hugo |
#6
| |||
| |||
|
|
Actually it is not surprising. AFAICT, they assumed you know which DBMS product you are connecting to, so once connected, you do not need a WHO AM I feature. |
|
Good luck. Keep us posted on you progress. |
#7
| |||
| |||
|
|
Actually I'm using Hibernate to connect on several different DBMS. So I did post a similar question on hibernate forums, but still waiting for an answer. |
#8
| |||
| |||
|
|
I'm not asking for a "who am i" feature, but just a simple SQL query that allow me to check that I'm actually connecting to something real. |
#9
| |||
| |||
|
|
I suppose the rationale is that if you are just querying constant values, why do you need to use SQL? Just assign a constant value to a variable in your application programming language. |
|
Anyway, you could simulate Oracle's DUAL table in RDBMS products that don't offer that extension (e.g. PostgreSQL, MS SQL Server), by doing this: CREATE TABLE DUAL (DUMMY VARCHAR(1)); INSERT INTO DUAL VALUES ('X'); // insert exactly one row! Then queries "FROM DUAL" will not be errors. |
#10
| |||
| |||
|
|
select expression from dual; # potentialy undefined table select expression; # non-standard SQL |
![]() |
| Thread Tools | |
| Display Modes | |
| |