PERL : Bind 2D array to SQL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PERL : Bind 2D array to SQL
# 1  
Old 01-10-2011
PERL : Bind 2D array to SQL

Hi,
I am in the need of doing a bulk insert via :

SQL - INSERT INTO <table> (SELECT..)
OR
PLSQL Block - FORALL i IN 1 .. count INSERT INTO <table>(arrayname(i))

I have a 2D array in my perl code which has the rows to be bulk inserted.

Is there a way to bind the 2D array to the SQL or the PLSQL block ???

I tried execute_array() but it seems it can be used for a 1D array and not for a 2D one.

Thanks.
sinpeak
# 2  
Old 01-10-2011
Are we in Oracle? I am a bit rusty.

I remember casting java arrays as tables and doing insert into target-matching-staging-table select * from array-table.

You may have to be per-column explicit:
Code:
FORALL i IN 1 .. count insert into table_name ( column_a, column_b, ... ) values ( array[i][1], array[i][2], ... );

# 3  
Old 01-10-2011
Quote:
Originally Posted by sinpeak
...
Is there a way to bind the 2D array to the SQL or the PLSQL block ???
I tried execute_array() but it seems it can be used for a 1D array and not for a 2D one.
...
There is no support for binding two-dimensional arrays in DBD::Oracle. The best you could do is - use $sth->bind_param_array to bind an array reference and then use $sth->execute_array.

Support for passing collections or object types isn't there as well. You can pass them out from a function or procedure, but you cannot pass them in.

Depending on the details of your problem, you may be better off using SQL*Loader to load your data.

tyler_durden

Last edited by durden_tyler; 01-11-2011 at 12:59 AM..
# 4  
Old 01-11-2011
Oracle can map files as external tables, which is another easy and high bandwidth path in.

I am not sure it is legal with sqlloader (some tools like flat files too much), but one slick direction to to popen() sqlloader and write to the pipe. The Oracle page is not specific about its pipe intolerance!
# 5  
Old 01-13-2011
Thanks to all for your replies. It helps.
sinpeak
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using unix array in sql

Hi all, I have declared an array in unix as below. #!/bin/ksh arr=() for i in {0..4} do arr=$i; done. i want to insert these array variables into the oracle table.can you guys please help me in doing this. my code is as below. value=`sqlplus -s fos/fos << EOF begin for j in... (10 Replies)
Discussion started by: Mukta
10 Replies

2. Shell Programming and Scripting

Pass perl array to SQL oracle

Hello, Could someone please suggest if there is a way to pass an perl array(pass @v_array) to SQL as in below eg : #!/usr/bin/perl @v_array = (1,2,4,5,6,8); $db_userid = 'ni71/ni711'; $bufTPO = qx{ sqlplus -s << EOF $db_userid set verify off set feedback off set... (1 Reply)
Discussion started by: arunshankar.c
1 Replies

3. UNIX and Linux Applications

SQL database call into Multidimensional Array using Perl Script

#!/usr/local/bin/perl use DBI; use File::Copy; use Time::Local; use Data::Dumper; -Comments Describing what I'm doing-------------- -I'm pulling information from a database that has an ID and Name. They are separated by a space and I'm trying to load them into a multidimensional array so as... (3 Replies)
Discussion started by: eazyeddie22
3 Replies

4. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

5. Shell Programming and Scripting

Array in Perl - Detect several file to be in one array

Hi everyone I have one question about using array in perl. let say I have several log file in one folder.. example test1.log test2.log test3.log and the list goes on.. how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies

6. Shell Programming and Scripting

Need help on bind param function in perl

Hi, I want to know what exactly bind paameter does? what exactly bind_param( 1, $siteName ) means? what 1 means? In some examples the bind_param is set like this: bind_param( 2, $siteName1 ) bind_param( 3, $siteName2 ) $sth = $dbh->prepare( " SELECT name,... (1 Reply)
Discussion started by: vanitham
1 Replies

7. Shell Programming and Scripting

PERL : SQL array bind issue while grouping

Hi, I have an array of strings. Each string has 4 comma separated values. I am binding this array to a SQL where I am required to do an INSERT after grouping. The binding is done as : $insertADWSth->bind_param_array(1,A_CONSTANT_STRING);... (1 Reply)
Discussion started by: sinpeak
1 Replies

8. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

9. UNIX for Advanced & Expert Users

sql variable as array index

hi folks i am facing problom while trying to access sql variable as array index ina unix shell script....script goes as below.. #!/bin/ksh MAX=3 for elem in alpha beeta gaama do arr=$elem ((x=x+1)) Done SQL_SERVER='servername' /apps/sun5/utils/sqsh -S $SQL_SERVER -U user -P pwd -b -h... (1 Reply)
Discussion started by: sudheer157
1 Replies

10. Shell Programming and Scripting

Perl DBI - Bind Parameters Problem

I have a SQL statement that includes a UNION that I can't get to work when I bind the parameters. (I am binding the parameters to prevent SQL injection.) Does anybody have any suggestion on how I can use a SQL statement that includes a UNION and bind the params? Code would be something like... (1 Reply)
Discussion started by: mh53j_fe
1 Replies
Login or Register to Ask a Question