user1564173
user1564173

Reputation: 31

How can I show the column name in lower case?

Table structure:

SQL>DESCRIBE tipsdb;

 Name                       Null?               Type
 ----------------------------------------- -------- ----------------------------
 USERNAME                                           CHAR(20)

 MAC                                                CHAR(20)

 PASSWORD                                           CHAR(50)

SQL>

Complete table output:

SQL> select * from tipsdb;


USERNAME
------------------------------------------------------------

MAC

------------------------------------------------------------

PASSWORD
--------------------------------------------------------------------------------

arun

aabbccddeeff

whopee

Current output:

SQL> select PASSWORD as user_password from tipsdb;

USER_PASSWORD

--------------------------------------------------------------------------------
whopee

Expected output:

SQL> select PASSWORD as user_password from tipsdb;

user_password
----------------------
whopee

In the above query I want the user_password column to be displayed in lower case instead of upper case.

Upvotes: 0

Views: 6550

Answers (1)

Alex Poole
Alex Poole

Reputation: 191560

You can use the SQL*Plus column command to override the default heading:

SQL> column username heading "username"
SQL> column password heading "password"
SQL> select username, mac, password from tipsdb

You don't have to enclose the desired heading in double-quotes to specify the case to use, but I think it's a bit clearer that it's intentional; and you do need the quotes if your heading has multiple words.

There is much more about formatting columns in the SQL*Plus User Guide and Reference.

If your query specifies an alias for the column name then you need to refer to that alias in the column command.

But you can also make the alias itself lower-case, by enclosing that in double quotes, making it a quoted identifier:

SQL> select PASSWORD as "user_password" from tipsdb;

And because it's quoted you could use a space instead of an underscore it you wanted to:

SQL> select PASSWORD as "user password" from tipsdb;

You then don't need a column heading setting. Referring to a quoted identifier is generally a pain as they have to quoted and have exactly the same everywhere, but purely for display like this is can be useful.

Upvotes: 5

Related Questions