Return ColumnNames in lowercase. [message #526600] |
Tue, 11 October 2011 17:18  |
 |
aucrun
Messages: 114 Registered: February 2011
|
Senior Member |
|
|
Hi,
I wonder if there is any way to return the columns of an select with its letters lowercase?
I have a piece of code that creates an script wich returns an SQL result to be confronted with some templates.
My template have the columnnames in lowercase and because It is case sensitive the Uppercase returned by Oracle, it fails me.
Is there any way?
Thanks!
|
|
|
|
|
|
|
Re: Return ColumnNames in lowercase. [message #526732 is a reply to message #526649] |
Wed, 12 October 2011 14:01  |
 |
Barbara Boehmer
Messages: 9106 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
When you create the table, or rename a column, you can preserve the case by enclosing it within double quotation marks. However, this is generally regarded as a bad practice, since it will require you to use the double quotes any time that you refer to the column. Referring to the column without the quotes will raise an error. Please see the demonstration below.
SCOTT@orcl_11gR2> create table person
2 ("name" varchar2(15),
3 "id" number)
4 /
Table created.
SCOTT@orcl_11gR2> insert into person ("name", "id")
2 values ('John Doe', 1)
3 /
1 row created.
SCOTT@orcl_11gR2> select * from person
2 /
name id
--------------- ----------
John Doe 1
1 row selected.
SCOTT@orcl_11gR2> select "name", "id" from person
2 /
name id
--------------- ----------
John Doe 1
1 row selected.
SCOTT@orcl_11gR2> select name from person
2 /
select name from person
*
ERROR at line 1:
ORA-00904: "NAME": invalid identifier
SCOTT@orcl_11gR2> select id from person
2 /
select id from person
*
ERROR at line 1:
ORA-00904: "ID": invalid identifier
SCOTT@orcl_11gR2> alter table person rename column "name" to "Name"
2 /
Table altered.
SCOTT@orcl_11gR2> select * from person
2 /
Name id
--------------- ----------
John Doe 1
1 row selected.
SCOTT@orcl_11gR2>
|
|
|