Re: Column name mod causing problem

From: Thomas J Kyte <tkyte_at_us.oracle.com>
Date: 1995/10/20
Message-ID: <466u7c$kbe_at_inet-nntp-gw-1.us.oracle.com>#1/1


rife_at_aarlo.moffitt.usf.edu (Mike Rife) wrote:

>In article <462rea$dki_at_earth.vais.net>, dci_at_sun.vais.net (Dynamic Computing) says:
>>
>>I am writing a Pro*c program to fetch some data from an existing table,
>>but the table has a column name - mod. When I use EXEC SQL SELECT mod,
>>field2 from MYTABLE, the precompiler is confused and thinks the field
>>name - mod is the oracle function mod and gives a syntax error. Can
>>anyone give me some ideas how I can get around this without altering the
>>column name in the table. Thanks a lot in advance.
>>
>>Janie
>>dci_at_vais.net
>>
 

>MOD is a reserved word. One way to get around this is to create a view
>of the table which changes the name of the MOD column. Then reference the
>view in your Pro*C code SELECT statement. I have ran into this with
>columns named TYPE.
 

> create view MYTABLE_VIEW as
> select mod mod_new_name, field2
> from MYTABLE;
 

>Then in Pro*C:
 

> EXEC SQL SELECT mod_new_name, field2 from MYTABLE_VIEW;
 

>Hope that helps.

Another way to do this without a view is to:

SELECT "MOD", field2 from MYTABLE

Quoted identifiers allow you to use any 32 characters to name things. You can:

create table "My Table With Blanks"

(  "FROM"   int,
   "WHERE"  int, 
   "SELECT" int 

)

and then:

select "SELECT", "FROM", "WHERE"
from "My Table With Blanks"
/

Case matters in quoted identifiers BTW. "My Table With Blanks" is case sensitive. As is "FROM" or "SELECT".

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government Received on Fri Oct 20 1995 - 00:00:00 CET

Original text of this message