How to get the 3rd column(i.e all the data along with the
column name)in a table?
Answers were Sorted based on User's Feedback
Answer / ramesh
Column Names of a table are stored in the data dictionary
table user_tab_columns along with column_id. By referring
column_id we can display the column name as :
select column_name from user_tab_columns where table_name
= 'EMP' and column_id = 3;
Is This Answer Correct ? | 10 Yes | 6 No |
Answer / p.rajasekar
This is the common solution for any table
Run the following Function and fire the follwoing query
CREATE OR REPLACE FUNCTION fnSpecificcol(p_tablename IN
VARCHAR2,
p_columnid IN number,
P_ROWID IN Varchar2)
RETURN VARCHAR2
AUTHID CURRENT_USER AS
TYPE c_refcur IS REF CURSOR;
lc_str VARCHAR2(4000);
out_char varchar2(50);
lc_colval VARCHAR2(4000);
tmp_strSQL varchar2(400);
c_dummy c_refcur;
l number;
BEGIN
tmp_strSQL := 'select column_name from user_tab_cols a '
||
'where upper(table_name)=' || '''' ||
p_tablename || '''' ||
' and column_id=' || p_columnid;
OPEN c_dummy FOR tmp_strSQL;
LOOP
FETCH c_dummy
INTO lc_colval;
EXIT WHEN c_dummy%NOTFOUND;
lc_str := lc_str || lc_colval;
END LOOP;
CLOSE c_dummy;
tmp_strSQL := '';
tmp_strSQL := 'select ' || lc_str || ' from ' ||
p_tablename ||
' A WHERE A.ROWID=' || '''' || P_ROWID
|| '''';
lc_str := '';
lc_colval := '';
OPEN c_dummy FOR tmp_strSQL;
LOOP
FETCH c_dummy
INTO lc_colval;
EXIT WHEN c_dummy%NOTFOUND;
lc_str := lc_str || lc_colval || CHR(13);
END LOOP;
CLOSE c_dummy;
RETURN SUBSTR(lc_str, 1);
EXCEPTION
WHEN OTHERS THEN
lc_str := SQLERRM;
IF c_dummy%ISOPEN THEN
CLOSE c_dummy;
END IF;
RETURN lc_str;
END;
SELECT fnSpecificcol('Tablename', ColumnNumber,A.ROWID)
from Tablename A
eg
SELECT rowtocol('AA', 1,A.ROWID) from aa A
Is This Answer Correct ? | 2 Yes | 4 No |
When we can declare a column as Unique and Not Null both at the same time. What is the use pf Primary Key then?
2 Answers Accenture, Unisoft Infotech,
Can a composite key be null?
Should I use mbr or gpt?
Does access use sql?
discuss about myisam key cache. : Sql dba
What is not null in sql?
What are different types of queries in sql?
What does select * from mean in sql?
What is full form of rtm?
What is bulk collections?
What does joining a thread mean?
Which one of the following is a reason that an INSERT statement might cause an error instead of executing correctly? 1. The INSERT statement was attempting to insert a record into a view that was created from more than one table. 2. The INSERT statement was attempting to insert a record using a combination of constants and values from an existing table. 3. The INSERT statement was attempting to insert a record with a non-NULL value into a table that has that column defined as NULL. 4. The INSERT statement was attempting to insert a record into a table by selecting a record from that same table. 5. The INSERT statement was attempting to insert a record into a view rather than a table.