Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to get the 3rd column(i.e all the data along with the
column name)in a table?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between sql, mysql and sql server?

1013


What is %type in pl sql?

924


What is clustered index in sql?

1001


How many types of cursors are available in pl/sql?

1042


What is left inner join in sql?

985


What is cascade in sql?

914


What is normalisation in sql?

1003


What is sql partition function?

1117


Explian rowid, rownum? What are the psoducolumns we have?

945


differentiate between float and double. : Sql dba

989


How do you modify a table in sql?

1062


how to decrement dates by 1 in mysql? : Sql dba

968


What is the example of procedure?

874


how tsql statements can be written and submitted to the database engine? : Transact sql

922


Is natural join same as inner join?

870