Home » SQL & PL/SQL » SQL & PL/SQL » How to query for columns without using column names (TOAD PLSQL)
How to query for columns without using column names [message #586363] Wed, 05 June 2013 09:23 Go to next message
bws93222
Messages: 27
Registered: April 2009
Junior Member
I have limited permissions and am unable to create temp tables.
So I would like to use a cursor to "create" a table of sorts
then access/query it. But this "table"/cursor would have no column names so
how do I refer to the columns? Is there a way to refer to a column
by column number rather than column name in a query:
select column1 from tablename where column2 = 'abc'?

Below is a very rough and simplified code example that I hope gives you some idea
what I am trying to do--if it has errors, please don't focus on them or suggest
other approaches--instead, please understand that the only question I have is:
Is there a way in a query/update/insert to refer to a column by column number rather
than column name?

declare
cursor c1 is
select 'abc', '8-Apr-2013', pk_id from EMPLOYEE where pk_id = '153'
UNION
select '1xyz', '4-10-2013', pk_id from EMPLOYEE where pk_id = '154'

c1_val number;



begin
c1_val := 0;
for c1_val in c1
loop
update EMPLOYEE set EMPLOYEE.DATE = c1.(what?-I want to refer to the date value in the cursor above but it has no column name- I need to refer to column number #2 ) where pk_id = '153'
--- insert into tbl (columns) value (data);

end loop;
end;

[Updated on: Wed, 05 June 2013 09:24]

Report message to a moderator

Re: How to query for columns without using column names [message #586364 is a reply to message #586363] Wed, 05 June 2013 09:39 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Is there a way in a query/update/insert to refer to a column by column number rather than column name?
no, not possible.

as a general rule Oracle rarely requires "temp" tables & problem can be solved using plain SQL (without PL/SQL)

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/


Re: How to query for columns without using column names [message #586367 is a reply to message #586363] Wed, 05 June 2013 10:27 Go to previous messageGo to next message
Michel Cadot
Messages: 68767
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
You can give a name to your constants:

select 'abc' col1, '8-Apr-2013' col2, pk_id from EMPLOYEE where pk_id = '153'
UNION
select '1xyz', '4-10-2013', pk_id from EMPLOYEE where pk_id = '154'


Regards
Michel

[Updated on: Wed, 05 June 2013 10:27]

Report message to a moderator

Re: How to query for columns without using column names [message #586368 is a reply to message #586363] Wed, 05 June 2013 10:28 Go to previous messageGo to next message
Michel Cadot
Messages: 68767
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
I want to refer to the date value in the cursor


There is no date values only strings on your example.

Regards
Michel
Re: How to query for columns without using column names [message #587286 is a reply to message #586363] Thu, 13 June 2013 16:50 Go to previous message
bws93222
Messages: 27
Registered: April 2009
Junior Member
thx--that worked, Michel!

[Updated on: Thu, 13 June 2013 16:51]

Report message to a moderator

Previous Topic: Help in SQL
Next Topic: CONVERSIONS
Goto Forum:
  


Current Time: Sat Aug 23 21:39:38 CDT 2025