Why doesn't Oracle tell you WHICH table or view does not exist?

前端 未结 8 1169
时光取名叫无心
时光取名叫无心 2021-01-31 13:43

If you\'ve used Oracle, you\'ve probably gotten the helpful message \"ORA-00942: Table or view does not exist\". Is there a legitimate technical reason the message doesn\'t incl

8条回答
  •  孤街浪徒
    2021-01-31 14:25

    I've never had a problem with interpreting Oracle error messages. Part of the reason is that every interactive tool I've seen for developing SQL for Oracle helpfully points to the location the query went wrong. That includes SQL*Plus, as others have noted, and the Perl DBI module:

    $ exec_sql.pl 'select * from daul'
    DBD::Oracle::db prepare failed: ORA-00942: table or view does not exist (DBD ERROR: error possibly near <*> indicator at char 14 in 'select * from <*>daul') [for Statement "select * from daul"] at exec_sql.pl line 68.
    

    Well, that is a bit hard to read since it's all squished on one line. But a GUI tool would be able to point to the token where Oracle started having problems with the query. And given a bit of work on a parser, you could write a tool to pick out the offending table.

    To answer the underlying question, Oracle errors don't seem to be designed to work the way you expect. As far as I can tell, none of the the error messages in Oracle support variable text. Instead, Oracle returns two bits of information: an error number and a location where the error occurs. If you have proper tools, it's pretty easy to diagnose an error with those pieces of data. It can be argued that Oracle's system is nicer to tool creators than one which provides variable amounts of diagnostic data depending on the error. Imagine having to write a custom parser for all of Oracle's error messages (including future errors) to highlight the offending location.

    Sometimes including the table name would be misleading. Just knowing where things went wrong can be a huge help:

    SQL> select * from where dummy = 'X';
    select * from where dummy = 'X'
                  *
    ERROR at line 1:
    ORA-00903: invalid table name
    

    As for why Oracle chose to do thing this way, I have some speculations:

    1. IBM used this style of error message for System R, which Larry Ellison, Bob Miner and Ed Oates copied to build Oracle V2. (Backward compatibility.)

    2. Error number and location are the smallest possible representation of diagnostic information. (Parsimony.)

    3. As I indicated above, to simplify the creation of tools that connect to Oracle. (Interoperability.)

    In any case, I don't think you need to be a DBA to figure out which table doesn't exist. You just need to use the proper tools. (And adjust your expectations, I suppose.)

提交回复
热议问题