Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2049
  • Last Modified:

array in stored procedure

Can i declare an array of varchar in a stored procedure or use a structure but calling the structure fields using their position in the structure instead of the name?
0
DaniPro
Asked:
DaniPro
  • 2
1 Solution
 
slightwv (䄆 Netminder) Commented:
To answer the first part:  Yes

declare
      type arrType is table of varchar2(50);
      myarr arrType;
begin
      myarr := arrType('a','b');
      dbms_output.put_line('First: ' || myarr(1));
      dbms_output.put_line('Second: ' || myarr(2));
end;
/


I'm not clear what you are asking on the second part.
0
 
DaniProAuthor Commented:
Thank's for your replay, but i need to valorize my array with the field number.
Can i use a syntax like this?
myarr(1) := 'a'
myarr(2) := 'b'
0
 
slightwv (䄆 Netminder) Commented:
You will first need to initialize the array.  If you don't know the limit at runtime, you can extend it as needed:

declare
      type arrType is table of varchar2(50);
      myarr arrType;
begin

      myarr := arrType(null);
      myarr(1) := 'a';
      myarr.extend(1);
      myarr(2) := 'b';

      dbms_output.put_line('First: ' || myarr(1));
      dbms_output.put_line('Second: ' || myarr(2));
end;
/
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now