From andy at pasty.org.uk Sun Mar 20 02:25:42 2005 From: andy at pasty.org.uk (andy@pasty.org.uk) Date: Sun Mar 20 02:25:58 2005 Subject: [Bath-pm] Oracle SQL in Perl with unexpected results Message-ID: <3836.82.32.42.43.1111314342.squirrel@webmail.pasty.org.uk> Hi, * Perl 5.6.1 * Oracle 8i If I create an empty table (in SQL*Plus): create table animals ( a_dob date, a_name varchar2(10), a_cost number(9,2) ) and execute the following three SQL statements which creates an sqlldr control file: select 'LOAD DATA'|| chr (10) || 'INFILE ''' || lower (table_name) || '.dat''' || chr (10) || 'INTO TABLE '|| table_name || chr (10)|| 'FIELDS TERMINATED BY '','''||chr (10)|| 'TRAILING NULLCOLS' || chr (10) || '(' from user_tables where table_name = upper ('&tname'); select decode (rownum, 1, ' ', ' , ') || rpad (column_name, 33, ' ') || decode (data_type, 'VARCHAR2', 'CHAR NULLIF ('||column_name||'=BLANKS)', 'FLOAT', 'DECIMAL EXTERNAL NULLIF('||column_name||'=BLANKS)', 'NUMBER', decode (data_precision, 0, 'INTEGER EXTERNAL NULLIF ('||column_name|| '=BLANKS)', decode (data_scale, 0, 'INTEGER EXTERNAL NULLIF ('|| column_name||'=BLANKS)', 'DECIMAL EXTERNAL NULLIF ('|| column_name||'=BLANKS)')), 'DATE', 'DATE "&dformat" NULLIF ('||column_name||'=BLANKS)', null)from user_tab_columns where table_name = upper ('&tname') order by column_id; select ')' from dual; spool off (from http://www.oracleutilities.com/OSUtil/sqlldr.html) A control file, as expected, is returned. If I take those same chunks of SQL, replace the &'s, and prepare/execute them with DBI: my $SQL2 = <<__SQL2__; select 'LOAD DATA' || chr(10) || 'INFILE ''$datafile''' || chr(10) || 'INTO TABLE '|| table_name || chr(10) || 'FIELDS TERMINATED BY '','''||chr(10) || 'TRAILING NULLCOLS' || chr(10) || '(' from user_tables where table_name = upper ('$table') __SQL2__ my $SQL3 = <<__SQL3__; select decode (rownum, 1, ' ', ' , ') || rpad (column_name, 33, ' ') || decode (data_type, 'VARCHAR2', 'CHAR NULLIF ('||column_name||'=BLANKS)', 'FLOAT', 'DECIMAL EXTERNAL NULLIF('||column_name||'=BLANKS)', 'NUMBER', decode (data_precision, 0, 'INTEGER EXTERNAL NULLIF ('||column_name|| '=BLANKS)', decode (data_scale, 0, 'INTEGER EXTERNAL NULLIF ('|| column_name||'=BLANKS)', 'DECIMAL EXTERNAL NULLIF ('|| column_name||'=BLANKS)')), 'DATE', 'DATE "DD/MM/YYYY" NULLIF ('||column_name||'=BLANKS)', null)from user_tab_columns where table_name = upper ('$table') order by column_id __SQL3__ my $SQL4 = <<__SQL4__; select ')' from dual __SQL4__ I only get the first column. LOAD DATA INFILE 'animals.dat' INTO TABLE ANIMALS FIELDS TERMINATED BY ',' TRAILING NULLCOLS ( A_DOB DATE "DD/MM/YYYY" NULLIF (A_DOB=BLANKS)) What doesn't Perl like about the middle chunk of SQL? Regards, Andy From andy at pasty.org.uk Mon Mar 21 06:39:51 2005 From: andy at pasty.org.uk (andy@pasty.org.uk) Date: Mon Mar 21 06:40:01 2005 Subject: [Bath-pm] Oracle SQL in Perl with unexpected results In-Reply-To: <3836.82.32.42.43.1111314342.squirrel@webmail.pasty.org.uk> References: <3836.82.32.42.43.1111314342.squirrel@webmail.pasty.org.uk> Message-ID: <51685.62.173.88.110.1111415991.squirrel@webmail.pasty.org.uk> > What doesn't Perl like about the middle chunk of SQL? skoolboy error, I didn't while() the middle sth - hence only returning the first column. From stigliz at gmail.com Thu Mar 24 15:03:46 2005 From: stigliz at gmail.com (Amedeo Guffanti) Date: Thu Mar 24 15:03:55 2005 Subject: [Bath-pm] Reseach on Open Source Developers Message-ID: Hi, I'm Amedeo Guffanti, a 22 years old Italian student at Bocconi university in Milan, I' m doing a research to write a work about Open Source Movement, in particular, about the developers. I try to collect the opinions of developers like you. My little poll is at this page : http://www.alberocavo.com/OSSprojects.asp It takes less then 4 minutes. I hope the Open Source Communities will give me a help for my research. I apologize for taking your time and for my English that I hope it's understandable ^^ Sincerly, Amedeo Guffanti