Sponsored Content
Top Forums Shell Programming and Scripting PERL : SQL array bind issue while grouping Post 302490185 by sinpeak on Monday 24th of January 2011 07:09:42 AM
Old 01-24-2011
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 :

Code:
$insertADWSth->bind_param_array(1,A_CONSTANT_STRING);
$insertADWSth->bind_param_array(2,B_CONSTANT_STRING); 
$insertADWSth->bind_param_array(3,\@lineRecArray);
 
$insertADWSth->execute_array({ArrayTupleStatus=>\my @tuple_status})

..and the SQL is :

Code:
INSERT INTO ABCD
(A,B,C,D,E,F,G)
(SELECT 
LINE_ARR.A, 
LINE_ARR.B, 
REGEXP_SUBSTR( LINE_ARR.LINE_REC,'[^,]+',1,2),
XYZ.D ,
XYZ.E , 
REGEXP_SUBSTR( LINE_ARR.LINE_REC,'[^,]+',1,3),
SUM(TO_NUMBER(REGEXP_SUBSTR( LINE_ARR.LINE_REC,'[^,]+',1,4))) 
FROM 
(SELECT ? A, ? B, ? LINE_REC FROM DUAL) LINE_ARR,
XYZ
WHERE XYZ.X = REGEXP_SUBSTR( LINE_ARR.LINE_REC,'[^,]+',1,1)
GROUP BY 
LINE_ARR.A, 
LINE_ARR.B, 
REGEXP_SUBSTR( LINE_ARR.LINE_REC,'[^,]+',1,2),
XYZ.D ,
XYZ.E , 
REGEXP_SUBSTR( LINE_ARR.LINE_REC,'[^,]+',1,3))

This gets executed successfully. But the issue is all records are inserted without being grouped. If I replace the arrays with a table having the same data then the grouping goes successful.

Does this mean when an array is bound to the SQL, the SQL is executed once for each element of the array ? and thats why it won't group ?

If yes, then is there a way to achieve such a thing ? where we have the data in an array and we need to group and sum it ?

Thanks
Dhritman

Moderator's Comments:
Mod Comment Please use code tags for listings

Last edited by pludi; 01-24-2011 at 08:30 AM..
sinpeak
 

8 More Discussions You Might Find Interesting

1. Solaris

rpc bind issue

Hi all, I am using Solaris 10 OS on X86 platform. Long back i tried to configure DHCP server on my system but because of rpc-bind, total went in vein.Even now i am unable to access even USB also. When i tried to look for "volfs" service it was offline because one of its dependant... (0 Replies)
Discussion started by: vvpotugunta
0 Replies

2. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: sinpeak
4 Replies

3. Solaris

BIND DNS Server issue on Solaris 10

Hi all, I have some sort of problem with BIND DNS server my environment as follows. bash-3.00# cat /etc/release Solaris 10 6/06 s10s_u2wos_09a SPARC Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. Use is subject to... (3 Replies)
Discussion started by: h@foorsa.biz
3 Replies

4. 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

5. Programming

SQL Grouping SUM

Hello people, I'm scratching my head to find a solution to this query. I have a simple SQL table: data | tot ================== 111201/0000 | 3 111201/0001 | 5 111201/0002 | 7 111201/0003 | 2 ..... 111201/0059 | 1 111201/0100 | 5 111201/0101 | 8 111201/0102 | 6... (7 Replies)
Discussion started by: Lord Spectre
7 Replies

6. 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

7. Shell Programming and Scripting

awk and perl grouping.

Hello folks. After awk, i have decided to start to learn perl, and i need some help. I have following output : 1 a 1 b 2 k 2 f 3 s 3 p Now with awk i get desired output by issuing : awk ' { a = a FS $2 } END { for ( i in a) print i,a }' input 1 a b 2 k f 3 s p Can... (1 Reply)
Discussion started by: Peasant
1 Replies

8. Shell Programming and Scripting

Grouping array elements - possible?

I have a script which takes backup of some configuration files on my server. It does that by using an array which contains the complete path to the files to backup. It copys the files to a pre defined dir. Each "program" has it's own folder, ex. apache.conf is being copied to /predefined... (7 Replies)
Discussion started by: dnn
7 Replies
DBIx::Class::SQLMaker(3)				User Contributed Perl Documentation				  DBIx::Class::SQLMaker(3)

NAME
DBIx::Class::SQLMaker - An SQL::Abstract-based SQL maker class DESCRIPTION
This module is a subclass of SQL::Abstract and includes a number of DBIC-specific workarounds, not yet suitable for inclusion into the SQL::Abstract core. It also provides all (and more than) the functionality of SQL::Abstract::Limit, see DBIx::Class::SQLMaker::LimitDialects for more info. Currently the enhancements to SQL::Abstract are: o Support for "JOIN" statements (via extended "table/from" support) o Support of functions in "SELECT" lists o "GROUP BY"/"HAVING" support (via extensions to the order_by parameter) o Support of "...FOR UPDATE" type of select statement modifiers o The "-ident" operator o The "-value" operator OPERATORS
-ident Used to explicitly specify an SQL identifier. Takes a plain string as value which is then invariably treated as a column name (and is being properly quoted if quoting has been requested). Most useful for comparison of two columns: my %where = ( priority => { '<', 2 }, requestor => { -ident => 'submitter' } ); which results in: $stmt = 'WHERE "priority" < ? AND "requestor" = "submitter"'; @bind = ('2'); -value The -value operator signals that the argument to the right is a raw bind value. It will be passed straight to DBI, without invoking any of the SQL::Abstract condition-parsing logic. This allows you to, for example, pass an array as a column value for databases that support array datatypes, e.g.: my %where = ( array => { -value => [1, 2, 3] } ); which results in: $stmt = 'WHERE array = ?'; @bind = ([1, 2, 3]); AUTHORS
See "CONTRIBUTORS" in DBIx::Class. LICENSE
You may distribute this code under the same terms as Perl itself. perl v5.12.5 2011-07-27 DBIx::Class::SQLMaker(3)
All times are GMT -4. The time now is 09:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy