Home » SQL & PL/SQL » SQL & PL/SQL » how to dynamically access members of record structure
how to dynamically access members of record structure [message #207122] Mon, 04 December 2006 03:58 Go to next message
tosanu
Messages: 7
Registered: December 2006
Location: INDIA
Junior Member
hi all..

i have a record structure like this...

create or replace type rec1 is record (
m1 varchar2(50);
m2 varchar2(50);
.
.
.
.
m50 varchar2(50);
);

and i need to compare each member of the record with a value like this...

....
r1 rec1;

....
if r1.m1 = 'abc' or r1.m2 = 'abc' or .... then
flag = 1;
end if;
....

instead of hardcoding each member of the record structure, is there any other way to access it dynamically,
may be inside a loop.. ?

thanks in advance

sanu


Re: how to dynamically access members of record structure [message #207151 is a reply to message #207122] Mon, 04 December 2006 05:47 Go to previous messageGo to next message
michael_bialik
Messages: 611
Registered: July 2006
Senior Member
Why don't you define VARRAY type:

CREATE -- OR REPLACE
TYPE REC1 IS VARRAY(50) OF VARCHAR2(50);

and use it inside the loop?

Re: how to dynamically access members of record structure [message #207168 is a reply to message #207151] Mon, 04 December 2006 06:57 Go to previous messageGo to next message
tosanu
Messages: 7
Registered: December 2006
Location: INDIA
Junior Member


sorry... a small correction in requirement..
the record structure members are with different data types...
i need to compare the values and also need to assign values in it...

Re: how to dynamically access members of record structure [message #207178 is a reply to message #207168] Mon, 04 December 2006 07:33 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
So, basically these variables have nothing in common. They should not even share the same name, because obviously they serve different purposes. (otherwise the datatype would match).
Being lazy is good, being too lazy result in baaaad code.
Re: how to dynamically access members of record structure [message #207183 is a reply to message #207122] Mon, 04 December 2006 08:47 Go to previous messageGo to next message
tosanu
Messages: 7
Registered: December 2006
Location: INDIA
Junior Member
actually these varibles are attributes of a customer entity... we have a profile in which has the rec structure member names as well as its default value...And the comparisons and assignments i mentioned are intented to load the default values to these members if it is not specified...

if the profile loading is not done dynamically, it has to be done in a member wise manner and it will be difficult to maintain the code in future..



[Updated on: Mon, 04 December 2006 08:47]

Report message to a moderator

Re: how to dynamically access members of record structure [message #207319 is a reply to message #207122] Tue, 05 December 2006 00:59 Go to previous messageGo to next message
michael_bialik
Messages: 611
Registered: July 2006
Senior Member
So, as Frank wrote there is nothing common there:
1. You have to define each column with different data type,
name, initial vale, etc.
2. You have to compare each column with differentvalues.

My question si: what is dynamic here?

Michael
icon5.gif  Re: how to dynamically access members of record structure [message #211210 is a reply to message #207319] Wed, 27 December 2006 04:07 Go to previous message
filipe.silva
Messages: 3
Registered: December 2006
Junior Member
I suppose that the aim of the question is to access a record type elements dynamically and he used an example case.

The question would be like: can I access my record type elements via a dinamic way similar to varray access?

I think that if that can be solved would be using the anydata and anydataset.
Previous Topic: How to send only delta records from table to flat file?
Next Topic: about ETL
Goto Forum:
  


Current Time: Fri Dec 09 09:40:43 CST 2016

Total time taken to generate the page: 0.10268 seconds