Search code examples
sqldatabaseoracle-databaseodbctop-n

How to determine what type of database - Old legacy corporate database


I have access to a legacy corporate database that I can connect to via Microsoft's ODBC for Oracle driver through Visual Studio 2010. Can I query the database to determine what type and version the database is?

Also, will the Microsoft ODBC for Oracle driver ONLY connect to Oracle servers, or will it connect to others as well?

At this point all I need is a "Top-N" query but haven't been able to get it to work. Here are a few simple queries I've tried, all give syntax errors.

SELECT     X_DATETIME_INSERT, X_USERID_INSERT, DB_ACC, ROW_ID, ACD_ACCIDENT_NO, GROUP_ROW_ID, NAME, ADDRESS_1, ADDRESS_2, ADDRESS_3, ADDRESS_4, 
                  PHONE, INJURY, DELETE_ROW
FROM         EMSDBA.ACD_VICTIM
WHERE rownum <= 100;

SELECT     TOP 100 X_DATETIME_INSERT, X_USERID_INSERT, DB_ACC, ROW_ID, ACD_ACCIDENT_NO, GROUP_ROW_ID, NAME, ADDRESS_1, ADDRESS_2, ADDRESS_3, ADDRESS_4, 
                  PHONE, INJURY, DELETE_ROW
FROM         EMSDBA.ACD_VICTIM

SELECT     X_DATETIME_INSERT, X_USERID_INSERT, DB_ACC, ROW_ID, ACD_ACCIDENT_NO, GROUP_ROW_ID, NAME, ADDRESS_1, ADDRESS_2, ADDRESS_3, ADDRESS_4, 
                  PHONE, INJURY, DELETE_ROW
FROM         EMSDBA.ACD_VICTIM
LIMIT 100

Solution

  • For top-n, remember that rownum is calculated BEFORE any ordering, so you need to push the ordering down into a subquery. For example, to get the first 100 ordered by x_datetime you can:

       SELECT *
       FROM (SELECT  X_DATETIME_INSERT, X_USERID_INSERT
                    , DB_ACC, ROW_ID, ACD_ACCIDENT_NO
                    , GROUP_ROW_ID, NAME, ADDRESS_1
                    , ADDRESS_2, ADDRESS_3, ADDRESS_4, 
                      PHONE, INJURY, DELETE_ROW
             FROM         EMSDBA.ACD_VICTIM
             ORDER BY x_datetime)
    WHERE rownum <= 100;