0

I originally wrote a query to generate a result when the OBJECT_NUMBER was greater than a specific value. A change in the requirements for the query now require checking if the OBJECT_NUMBER is one of several hundred specific values. So, I generated the following query to accomplish that task. However, I recognized that having a list of several hundred OR statements might be slight unoptimized.

    SELECT
      OBJECT.OBJECT_NUMBER as "OBJECT NUMBER",
      SUM(OBSERVATON_PACKET.OBS_COUNT) as "OBSERVATION SUM",
      UNKNOWN_PACKET.OBS_COUNT,
      COUNT(UNKNOWN_PACKET.OBS_COUNT) AS "OBSERVATION COUNT",
      OBJECT.NOMINAL_SIZE_CALC AS "NOMINAL SIZE",
      DATA_SET.J2000TIME
    FROM
      DATA_SET,
      OBJECT,
      OBSERVATION_PACKET
    WHERE
      (DATA_SET.OBJECT_UID = OBJECT.OBJECT_UID)
      AND (
        UNKNOWN_PACKET.OBJECT_UID = OBJECT.OBJECT_UID
      )
      AND (
        OBJECT.OBJECT_NUMBER = 800100669
        OR OBJECT.OBJECT_NUMBER = 800101348
        OR OBJECT.OBJECT_NUMBER = 800102764
        OR OBJECT.OBJECT_NUMBER = 800134835
      )
      AND (DATA_SET.J2000TIME >= 735264061)
      AND (OBSERVATION_PACKET.OB_COUNT >= 3)
      AND OBJECT.NOMINAL_SIZE_CALC BETWEEN 0.02
      AND 0.50
    GROUP BY
      OBJECT.OBJECT_NUMBER,
      UNKNOWN_PACKET.OBS_COUNT,
      DATA_SET.J2000TIME,
      OBJECT.NOMINAL_SIZE_CALC

So I came up with the following modifications to the query:

    SELECT
      OBJECT.OBJECT_NUMBER AS "OBJECT NUMBER",
      SUM(UNKNOWN_PACKET.OBS_COUNT) AS "Observation Sum",
      UNKNOWN_PACKET.OBS_COUNT,
      COUNT(UNKNOWN_PACKET.OBS_COUNT) AS "Observation Count",
      OBJECT.NOMINAL_SIZE_CALC AS "Calculated Nominal SIZE",
      DATA_SET.J2000TIME AS "J2000 Epoch Time"
    FROM
      DATA_SET
      INNER JOIN UNKNOWN_PACKET ON DATA_SET.OBJECT_UID = UNKNOWN_PACKET.OBJECT_UID
      INNER JOIN(
        SELECT
          OBJECT_UID,
          OBJECT_NUMBER,
          NOMINAL_SIZE_CALC
        FROM
          OBJECT
        WHERE
          OBJECT_NUMBER IN(
            800100669,
            800101348,
            800102764,
            800134835
          )
      ) AS OBJECT ON DATA_SET.OBJECT_UID = OBJECT.OBJECT_UID
    WHERE
      DATA_SET.J2000TIME >= 735264061
      AND OBJECT.NOMINAL_SIZE_CALC BETWEEN 0.02 AND 0.50
      AND COUNT(OBSERVATION_PACKET.OBS_COUNT) >= 3
    GROUP BY
      OBJECT.OBJECT_NUMBER,
      UNKNOWN_PACKET.OBS_COUNT,
      DATA_SET.J2000TIME,
      OBJECT.NOMINAL_SIZE_CALC
    ORDER BY
      OBJECT.OBJECT_NUMBER

However, the query fails to execute, and only throws a "missing keyword" on the same line as "AS OBJECT ON DATA_SET.OBJECT_UID = OBJECT.OBJECT_UID" specifically after the word "AS".

I honestly don't know what is wrong with the new query. I have ran the query through a syntax checker. However, when I run the query with Oracle SQL Developer while connected to the database, the query fails and provides absolutely zero details other than a missing keyword was detected.

SQL Developer does indicate the error is ORA-00905. However, my ability to reach out to the Oracle website, while on the system with the database does not exist.

  • Just remove the `AS` - it is not allowed for table aliases. – Alex Poole Aug 30 '23 at 21:36
  • @AlexPoole - It appears that based on my additional research after the fact, Oracle 10g might have introduced a relevant change, but I know understand the reason the suggested fixed by SQL Developer involved using "AS OF". I was so focused on thinking I was missing something I didn't think to verify "AS" was even a valid keyword. – Space Guy 2024 Aug 30 '23 at 23:08

0 Answers0