GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 132 of 241    Print  
Hi, How do we display the column values of a table using cursors without knowing the column names inside the loop?

  
Total Answers and Comments: 9 Last Update: November 14, 2007     Asked by: Surendran 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: rampratap409
 

I do not think so.  You can not retrive the values from a cursor with OUT KNOWING THE COLUMN NAME.  You can not have (same name)/ (No Name)  for all in a family.



Above answer was rated as good by the following members:
kperumal75
October 20, 2006 09:00:14   #1  
rampratap409 Member Since: September 2006   Contribution: 111    

RE: Hi, How do we display the column values of a table...

I do not think so. You can not retrive the values from a cursor with OUT KNOWING THE COLUMN NAME. You can not have (same name)/ (No Name) for all in a family.


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
October 22, 2006 12:45:18   #2  
Gopal        

RE: Hi, How do we display the column values of a table...
Declare a variable using PL/SQL ROWTPE ( l_Record EMP ROWTYPE)In the cursor you can say .. cursor cursorname is select * from emp..Open cursor; loop .. fetch cursorname into l_Record.. Display the values from l_Record using dbms_output.put_line.Close the loop and cursor
 
Is this answer useful? Yes | No
October 23, 2006 06:11:07   #3  
rampratap409 Member Since: September 2006   Contribution: 111    

RE: Hi, How do we display the column values of a table...

Hi Gopal

Can u give a example please .


 
Is this answer useful? Yes | No
November 02, 2006 07:21:41   #4  
Sanjib        

RE: Hi, How do we display the column values of a table...
Please provide an example.
 
Is this answer useful? Yes | No
November 02, 2006 10:22:40   #5  
rampratap409 Member Since: September 2006   Contribution: 111    

RE: Hi, How do we display the column values of a table...

You can not retrive the values from a cursor with OUT KNOWING THE COLUMN NAME


 
Is this answer useful? Yes | No
November 06, 2006 01:42:41   #6  
Sachin Vaidya        

RE: Hi, How do we display the column values of a table...
I Don't think so If you are trying to populate the data using Records then also you should know name of the columns from the table or select query of the cursor.
 
Is this answer useful? Yes | No
November 11, 2006 00:26:13   #7  
Raghavendra Jha Member Since: November 2006   Contribution: 2    

RE: Hi, How do we display the column values of a table...

No.its not possible to fetch column value from a cursor without knowing the column name there is nothing to do with cursor cursor is nothing but explicitly created memory area to fetch record using sql query itself..and its not possible to retrieve any value without knowing column name if it is not like that plz expalin with an example..


 
Is this answer useful? Yes | No
November 13, 2006 14:54:10   #8  
Naresh Dantu        

RE: Hi, How do we display the column values of a table...

You Can. Below is the example.

DECLARE

CURSOR cr_data

IS

SELECT ROWID a.*

FROM fnd_user a where rownum < 10;

l_table_name VARCHAR2(2000) : 'FND_USER';

-- IMP--This table name should be same as your from table in the above cursor

l_value VARCHAR2 (2000);

l_str VARCHAR2 (2000);

CURSOR column_names (p_table_name VARCHAR2)

IS

SELECT *

FROM all_tab_columns

WHERE table_name p_table_name;

-- You can use order by clause here if you want.

BEGIN

FOR cr_rec IN cr_data

LOOP

-- We should pass the same Table Name

FOR cr_columc_rec IN column_names (l_table_name)

LOOP

l_str :

'Select '

|| cr_columc_rec.column_name

|| ' from '||l_table_name||' where rowid '||chr(39)

|| cr_rec.ROWID||chr(39);

DBMS_OUTPUT.put_line ('Query is ' || l_str);

EXECUTE IMMEDIATE l_str

INTO l_value;

DBMS_OUTPUT.put_line ( 'Column is '

|| cr_columc_rec.column_name

|| ' and Value is '

|| l_value

);

END LOOP;

END LOOP;

END;


 
Is this answer useful? Yes | No
November 14, 2007 07:13:38   #9  
sankar        

RE: Hi, How do we display the column values of a table...
We have prdefined table 'col'. from this table we can find the column names dynamically.

For ex.

select cname from col where col 1 and tname 'emp'

then you will get first clomun name of emp table; ex. for in 1..2 loop select cname into cname1 from col where col i and tname 'emp';

cursor ec is select cname1 from emp;

end loop;

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape