By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,156 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,156 IT Pros & Developers. It's quick & easy.

doubt in arrays used in function

priyan
P: 54
hai all,
If anybody know please help me to how to use array in a function and how to return a integer array from a function

thanks in advance
priyan.
Sep 11 '07 #1
Share this Question
Share on Google+
5 Replies


amitpatel66
Expert 100+
P: 2,367
hai all,
If anybody know please help me to how to use array in a function and how to return a integer array from a function

thanks in advance
priyan.
Check out below code. I have used ARRAY of CHARACTER. U can reqrite it to INTEGER as required:

Step:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 1. CREATE OR REPLACE TYPE arr_typ AS VARRAY(20) OF VARCHAR2(20);
  3.  
  4. 2.  CREATE OR REPLACE FUNCTION ret_arr(arr_type arr_typ) RETURN arr_typ AS
  5. ar_typ arr_typ;
  6. BEGIN
  7. FOR I IN arr_type.FIRST..arr_type.LAST LOOP
  8. DBMS_OUTPUT.PUT_LINE(arr_type(i));
  9. SELECT item BULK COLLECT INTO ar_typ FROM a where type=arr_type(i);
  10. END LOOP;
  11. RETURN ar_typ;
  12. END ret_arr;
  13. /
  14.  
Sep 11 '07 #2

priyan
P: 54
Check out below code. I have used ARRAY of CHARACTER. U can reqrite it to INTEGER as required:

Step:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 1. CREATE OR REPLACE TYPE arr_typ AS VARRAY(20) OF VARCHAR2(20);
  3.  
  4. 2.  CREATE OR REPLACE FUNCTION ret_arr(arr_type arr_typ) RETURN arr_typ AS
  5. ar_typ arr_typ;
  6. BEGIN
  7. FOR I IN arr_type.FIRST..arr_type.LAST LOOP
  8. DBMS_OUTPUT.PUT_LINE(arr_type(i));
  9. SELECT item BULK COLLECT INTO ar_typ FROM a where type=arr_type(i);
  10. END LOOP;
  11. RETURN ar_typ;
  12. END ret_arr;
  13. /
  14.  
Hi amitpatel,
I can't understand the above program please give me another example in postgresql please i think it is in oracle pl/sql please help me .

thanks in advance
priyan
Sep 12 '07 #3

amitpatel66
Expert 100+
P: 2,367
Hi amitpatel,
I can't understand the above program please give me another example in postgresql please i think it is in oracle pl/sql please help me .

thanks in advance
priyan
Hi Priyan,

Yes the above code is ORACLE PLSQL. This gives you a logic of how u can write a function with ARRAYS as input parameter and as RETURN value as well.The syntax might differ in POSTGRESQL but the concept will be the s
Sep 12 '07 #4

priyan
P: 54
Hi Priyan,

Yes the above code is ORACLE PLSQL. This gives you a logic of how u can write a function with ARRAYS as input parameter and as RETURN value as well.The syntax might differ in POSTGRESQL but the concept will be the s

hello amitpatel
Please give me a sample function in postgresql it will be very useful for me. Please do me the help...
Sep 12 '07 #5

priyan
P: 54
hello amitpatel
Please give me a sample function in postgresql it will be very useful for me. Please do me the help...

Please give me examples.......
Sep 19 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.