Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Get column name from its ordinal position in table?
create table tabela (field1 number, field2 char, field3 long);
select table_name,column_name,column_id from user_tab_columns where table_name='TABELA';
TABLE_NAME COLUMN_NAME COLUMN_ID ------------------------------ ------------------------------ --------- TABELA FIELD1 1 TABELA FIELD2 2 TABELA FIELD3 3 ---------------------------------------------------------------------------- ----------------------------
cursor c1 is
select column_name from user_tab_columns
where table_name=tablename and column_id=column_number;
cur_val c1%rowtype;
return_value varchar2(255);
begin
for cur_val in c1 loop
return_value:=cur_val.column_name;
end loop;
return return_value;
END myfunction;
/
show errors
SQL> select myfunction('TABELA',2) from dual;
MYFUNCTION('TABELA',2)
MYFUNCTION('TABELA',1)
MYFUNCTION('TABELA',3)
_______________-----------------------_______________
Hope this help
(try to find bugs -EX: UPPER() function not stated)
Jorge Meirim
Tim Romano escreveu na mensagem <37207DDD.D46DD308_at_ot.com>...
>Is it possible to write a function that can figure out the name of
>a column if the column's ordinal position is known? If so, I would
>be grateful if someone could point me toward the right system
>table/view(s).
>
>ColumnName = MyFunction(TableName, ColumnPosition)
>
>TIA,
>Tim
>
>
>
>
>
>
>
>
>
Received on Fri Apr 23 1999 - 17:25:57 CDT
![]() |
![]() |