dbTalk Databases Forums  

oracle RowType issue

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss oracle RowType issue in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
FB
 
Posts: n/a

Default oracle RowType issue - 01-20-2010 , 09:10 AM






Hi All,
Im new to Oracle.
I have a Rowtype and i want to Loop through that Rowtype without
mentioning the Column name.

My code as below :


declare
empRowType Emp%ROWTYPE;
begin
SELECT * INTO empRowType FROM Emp
WHERE Emp_id = 101 ;


for x in ( select column_name from user_tab_columns where
table_name = 'Emp')
loop
i:=i+1;
y:= x.column_name;
z:= 'empRowType.'|| x.column_name;
dbms_output.put_line (z);
end loop;
end


Steps :


1) First Im declaring a RowType of Employee table.
2) Assigning value to RowType by making a select statement.
3) I want to get all the column name value printed so im selecting
the
column names of the table by using USER_TAB_COLUMNS table and running
a for loop.
4) Im concatenating RowTypeName.Column name (ex: z:= 'empRowType.'||
x.column_name
5) Print the Value


I get a O/P as String as :


empRowType.Emp_ID
empRowType.Emp_Name
empRowType.Emp_Department


but i want the O/P as


"101"
"John Peter"
"Marketing Department"


Pls someone help. This is a sample i have created to put in this
website. I cannot use RowType column to meet the requirement.


Thanks in advance,


FB

Reply With Quote
  #2  
Old   
Shakespeare
 
Posts: n/a

Default Re: oracle RowType issue - 01-20-2010 , 11:11 AM






Op 20-1-2010 16:10, FB schreef:
Quote:
Hi All,
Im new to Oracle.
I have a Rowtype and i want to Loop through that Rowtype without
mentioning the Column name.

My code as below :


declare
empRowType Emp%ROWTYPE;
begin
SELECT * INTO empRowType FROM Emp
WHERE Emp_id = 101 ;


for x in ( select column_name from user_tab_columns where
table_name = 'Emp')
loop
i:=i+1;
y:= x.column_name;
z:= 'empRowType.'|| x.column_name;
dbms_output.put_line (z);
end loop;
end


Steps :


1) First Im declaring a RowType of Employee table.
2) Assigning value to RowType by making a select statement.
3) I want to get all the column name value printed so im selecting
the
column names of the table by using USER_TAB_COLUMNS table and running
a for loop.
4) Im concatenating RowTypeName.Column name (ex: z:= 'empRowType.'||
x.column_name
5) Print the Value


I get a O/P as String as :


empRowType.Emp_ID
empRowType.Emp_Name
empRowType.Emp_Department


but i want the O/P as


"101"
"John Peter"
"Marketing Department"


Pls someone help. This is a sample i have created to put in this
website. I cannot use RowType column to meet the requirement.


Thanks in advance,


FB

With your output, create a sql statement and use dynamic SQL (look for
execute immediate) to run your query. z is a string, not a variable name.

Shakespeare

Reply With Quote
  #3  
Old   
ddf
 
Posts: n/a

Default Re: oracle RowType issue - 01-20-2010 , 01:53 PM



On Jan 20, 10:10*am, FB <franklinbr... (AT) gmail (DOT) com> wrote:
Quote:
Hi All,
Im new to Oracle.
I have a Rowtype and i want to Loop through that Rowtype without
mentioning the Column name.

My code as below :

declare
* empRowType * *Emp%ROWTYPE;
begin
SELECT ** INTO empRowType FROM Emp
* * * * WHERE * Emp_id *= 101 * *;

* * * *for x in ( select column_name from user_tab_columns where
table_name = 'Emp')
* * * *loop
* * * * * * * * * *i:=i+1;
* * * * * * * * * *y:= x.column_name;
* * * * * * * * * *z:= 'empRowType.'|| x.column_name;
* * * * * * * * * *dbms_output.put_line (z);
* * * *end loop;
end

Steps :

1) First Im declaring a RowType of Employee table.
2) Assigning value to RowType by making a select statement.
3) I want to get all the column name value printed so im selecting
the
column names of the table by using USER_TAB_COLUMNS table and running
a for loop.
4) Im concatenating RowTypeName.Column name (ex: *z:= 'empRowType.'||
x.column_name
5) Print the Value

I get a O/P as String as :

empRowType.Emp_ID
empRowType.Emp_Name
empRowType.Emp_Department

but i want the O/P as

"101"
"John Peter"
"Marketing Department"

Pls someone help. This is a sample i have created to put in this
website. I cannot use RowType column to meet the requirement.

Thanks in advance,

FB
What, exactly, is your requirement? It has been mentioned that you
are creating a string, not a column reference for the declared type,
which explains your current output. Using execute immediate may not
work as that involves a context switch and once that happens the SQL
session created to execute your dynamic statement has no 'knowledge'
of empRowType, much less its contents.

Knowing your 'marching orders' will help us tremendously in assisting
you.


David Fitzjarrell

Reply With Quote
  #4  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: oracle RowType issue - 01-20-2010 , 02:57 PM



FB wrote:
Quote:
Hi All,
Im new to Oracle.
I have a Rowtype and i want to Loop through that Rowtype without
mentioning the Column name.

My code as below :


declare
empRowType Emp%ROWTYPE;
begin
SELECT * INTO empRowType FROM Emp
WHERE Emp_id = 101 ;


for x in ( select column_name from user_tab_columns where
table_name = 'Emp')
loop
i:=i+1;
y:= x.column_name;
z:= 'empRowType.'|| x.column_name;
dbms_output.put_line (z);
end loop;
end


Steps :


1) First Im declaring a RowType of Employee table.
2) Assigning value to RowType by making a select statement.
3) I want to get all the column name value printed so im selecting
the
column names of the table by using USER_TAB_COLUMNS table and running
a for loop.
4) Im concatenating RowTypeName.Column name (ex: z:= 'empRowType.'||
x.column_name
5) Print the Value


I get a O/P as String as :


empRowType.Emp_ID
empRowType.Emp_Name
empRowType.Emp_Department


but i want the O/P as


"101"
"John Peter"
"Marketing Department"


Pls someone help. This is a sample i have created to put in this
website. I cannot use RowType column to meet the requirement.


Thanks in advance,


FB

You will have to use another programming language that allows enumerating the columns.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.