Re: Canonical list of reserved words/columns?

From: Jonathan Gennick <jonathan_at_gennick.com>
Date: Tue, 22 Feb 2000 16:28:37 GMT
Message-ID: <38b7ac88.6252360_at_netnews.worldnet.att.net>


On Tue, 22 Feb 2000 03:04:08 GMT, sargasm_at_my-deja.com wrote:

>Hi. I am trying to write a function which programatically determines
>whether a given column name (e.g. SIZE) is reserved/illegal. This is
>for a table creation tool.

This is an interesting question! And I think I have a novel solution. Column aliases need to conform to the same naming rules as column names, so try a select from dual, and alias the dummy column with the name that you are testing. If the select succeeds, the name is legitimate. For example:

SQL> SELECT dummy from dual;

D
-
X

The dual table has one column named dummy. Now, say you have to check to see if GROUP is a valid column name:

SQL> SELECT dummy group FROM dual;
SELECT dummy group FROM dual

             *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

GROUP is not valid, because you received an error. What about GROUPNO?

SQL> select dummy groupno from dual;

G
-
X

GROUPNO is a valid column name.

The good part about this solution is that you don't have to attempt a table creation in order to check the validity of the name. A select from dual should entail very little overhead.

Jonathan



jonathan_at_gennick.com
http://gennick.com
Brighten the Corner Where You Are Received on Tue Feb 22 2000 - 17:28:37 CET

Original text of this message