AllExperts > Oracle 
Search      
Oracle
Volunteer
Answers to thousands of questions
 Home · More Oracle Questions · Answer Library  · Encyclopedia ·
More Oracle Answers
Question Library

Ask a question about Oracle
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Suchitra Joshi
Expertise
I can answer questions regarding SQL, PL/SQL, Procedures, Functions, Triggers, SQL Loader, Oracle Forms, Oracle Reports, and some basic dba and performance tuning activities.

Experience
15+ years of Oracle PL/SQL Development

Education/Credentials
B.Sc (Electronics), Diploma in Computer Applications (DCA)

Awards and Honors
OCP - SQL and PL/SQL
Brainbench certifications in Oracle Administration, PL/SQL, Developer 2000

 
   

You are here:  Experts > Computing/Technology > Oracle > Oracle > Pass a Unix array variable to PL/SQL

Oracle - Pass a Unix array variable to PL/SQL


Expert: Suchitra Joshi - 9/25/2009

Question
HI Suchitra,

Is there any way by which we can store a list of file names in an array variable in unix and pass it to pl/sql procedure as an 'IN' parameter, so that we can loop through the array and access the file names inside the pl/sql procedure.

If yes, please provide the syntax.

Thanks in advance. Prompt response would be highly appreciated due to urgency in the requirement.

Siddharth

Answer
Hi Siddharth,

According to my knowledge we cannot pass unix array to PL/SQL procedure.

But here is an alternative -

1) Create a temporary table 'unixfiles' with column 'filename'.
2) Loop through the unix filenames and insert them in this table ($user is database user and $passwd is database password).

 eg.

    for filename in `find . -name '*'`
    do
       sqlplus -s $user/$passwd << _EOF
       insert into unixfiles values ($filename);
       commit;
       _EOF

    done

3) Now in the oracle procedure first create an associative array and assign these filenames, so that you can use this collection in your procedure further.

 eg.
     
 declare
    type t_file is table of varchar2(50)
       index by pls_integer;
    l_filename t_file;
 begin
    select *
    bulk collect into l_filename
    from unixfiles;

    for idx in l_filename.first .. l_filename.last
    loop
       dbms_output.put_line(l_filename(idx));
    end loop;
 exception
   when others then
    dbms_output.put_line(sqlerrm);
    rollback;
 end ;
 /

  
Hope this helps.

Regards

Suchitra

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.