James
James

Reputation: 1456

Oracle how to select column with custom name

i'm working in complex select query and i want to select column names with some specific format, but oracle give me only capital letter.

select no_constat as noFolder from cef_constat;

oracle gives me :

**nofolder**
value
value
value

i want the column name like this noFolder

i want the 'F' in capital letter

do you have any idea how to achieve this ?

Upvotes: 1

Views: 3186

Answers (2)

MT0
MT0

Reputation: 167981

Oracle databases are, by default, case sensitive; however, they will also, by default, convert everything to upper-case so that the case sensitivity is abstracted from you, the user.

This is useful so you can do:

SELECT no_constat FROM cef_constat;
SELECT NO_CONSTAT FROM CEF_CONSTAT;
SELECT No_Constat FROM Cef_Constat;
SELECT No_CoNsTaT FROM CeF_CoNsTaT;

and they all give the same result but the database will apply its default behaviour and convert the identifiers to upper case.

However, if you use double quotes then oracle will respect your use of case. In your example, you need to have a case-sensitive alias for the column name (and the column name and table name can have any case):

SELECT no_constat as "noFolder" FROM cef_constat;
SELECT NO_CONSTAT as "noFolder" FROM CEF_CONSTAT;
SELECT No_Constat as "noFolder" FROM Cef_Constat;
SELECT No_CoNsTaT as "noFolder" FROM CeF_CoNsTaT;

or you could even force case-sensitivity (via double-quotes) on all the identifiers, in which case you need to use the exact case used stored in the data dictionary, which is upper case, for the table and column names:

SELECT "NO_CONSTAT" as "noFolder" FROM "CEF_CONSTAT";

Upvotes: 2

mkuligowski
mkuligowski

Reputation: 1594

Try this:

select nofolder as "noFolder" from your_table;

This works, because quoted identifier are not folded to uppercase.

Details are available in the manual

Upvotes: 5

Related Questions