Skip to Main Content
  • Questions
  • Usage of type records and assigning values from single varchar2

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Prakash.

Asked: November 29, 2018 - 8:09 pm UTC

Last updated: November 30, 2018 - 9:03 am UTC

Version: 11g

Viewed 1000+ times

You Asked

I have a type record defined, using heroine utl function i want to read the line of data from a file and put the data into type record. Type record has got multiple variables declared under it.

and Connor said...

You are a little on detail, but let's say you read a line from the varchar2 that looks like:

CONNORMCDONALD

To add this to a record which is:

record MY_REC is
(  fname varchar2(20),
   lname varchar2(20)
)


it would look something like

declare
record MY_REC is
(  fname varchar2(20),
   lname varchar2(20)
)

l_rec my_rec;
begin
  l_rec.fname := substr(file_line,1,6);   -- CONNOR
  l_rec.lname := substr(file_line,7);     -- MCDONALD (rest of line
end;


Plenty of examples on this site of how to *parse* a single line into multiple fields (eg comma separated etc) if you need do that as well


Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library