Home » SQL & PL/SQL » SQL & PL/SQL » Query table with multi part column names (11g)
Query table with multi part column names [message #652705] Thu, 16 June 2016 14:52 Go to next message
bobghw
Messages: 34
Registered: July 2012
Member
Hi I have imported data from a spreadsheet where the column names are multi part i.e. 'ordering organisation','referrer name'

how do I reference theses multi part column names?
Re: Query table with multi part column names [message #652707 is a reply to message #652705] Thu, 16 June 2016 14:55 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Do you mean something like this -
orclz>
orclz> create table "silly name"("multi part" varchar2(10));

Table created.

orclz> insert into "silly name" values('something');

1 row created.

orclz> select "multi part" from "silly name";

multi part
----------
something

orclz>
Re: Query table with multi part column names [message #652708 is a reply to message #652707] Thu, 16 June 2016 15:02 Go to previous messageGo to next message
bobghw
Messages: 34
Registered: July 2012
Member
yes column names made up 2 or 3 words.

how do I reference these columns in a select statement?

select 'silly name', 'silly name 2' from table
Re: Query table with multi part column names [message #652709 is a reply to message #652708] Thu, 16 June 2016 15:05 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
how do I reference these columns in a select statement?


Is this not what John showed you?

Re: Query table with multi part column names [message #652711 is a reply to message #652709] Thu, 16 June 2016 15:07 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
You can lead some folks to knowledge, but you can not make them think!
Re: Query table with multi part column names [message #652713 is a reply to message #652711] Thu, 16 June 2016 15:16 Go to previous messageGo to next message
bobghw
Messages: 34
Registered: July 2012
Member
Thanks John.
Re: Query table with multi part column names [message #652714 is a reply to message #652713] Thu, 16 June 2016 15:21 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
You can create a table with imbedded spaces in the table and table name but it is NOT a good pratice. If you need them to be descriptive then I would do the following

create table "silly name"("multi part" varchar2(10));

INSTEAD DO

create table silly_name(multi_part varchar2(10));

With the first table every command would have to be surrounded by double quotes and the case would have to be exact

for example the following would work

select "multi part"
from "silly name";

however the following would fail

select "Multi Part"
from "silly name";

with the second table the following would work fine

select multi_part
from silly_name;

select Multi_Part
from silly_name;

select multi_part
from SILLY_name;



[Updated on: Thu, 16 June 2016 15:23]

Report message to a moderator

Previous Topic: Calculating values from two different tables by using SQL command.
Next Topic: What is the use of %ROWTYPE and %TYPE in PL/SQL?
Goto Forum:
  


Current Time: Fri Apr 26 09:02:53 CDT 2024